
Hello everyone. I am using Path Math to detect collision between paths, on one side I have Dynamic Lighting walls, and the other is a dynamic path between two tokens. Basically I'm trying to determine line of sight. I have all paths 'popped' into Path Math objects, and that seems to work fine, but when I ask Path Math to check for intersections, I get no positives. I even tried placing a wall right smack between the two tokens. I'm guessing I am doin something wrong? I would be thankful for any help. Here is the relevant code: var pid=chartokens[0].get('pageid');
var segments1=[];
var segments2=[];
var paths1=[];
var paths2=[];
var paths=findObjs({"_type":"path","_pageid":pid,"layer":"walls"});
for (var p in paths) {
paths1[paths1.length]=new PathMath.Path(paths[p]);
}
for (var token in tokens) {
if (chartokens[0].get("left")!=tokens[token].get("left") && chartokens[0].get("top")!=tokens[token].get("top")) {
var left = Math.min(chartokens[0].get("left"),tokens[token].get("left"));
var right = Math.max(chartokens[0].get("left"),tokens[token].get("left"));
var top = Math.min(chartokens[0].get("top"),tokens[token].get("top"));
var bottom = Math.max(chartokens[0].get("top"),tokens[token].get("top"));
var width = right-left;
var height = bottom-top;
var cx = left + width/2;
var cy = top + height/2;
_path=[["M",chartokens[0].get("left"),chartokens[0].get("top")],["L",tokens[token].get("left"),tokens[token].get("top")]];
var pathObj={
_path: JSON.stringify(_path),
left: cx,
top: cy,
width: width,
height: height,
stroke: '#ff0000',
_pageid: chartokens[0].get('pageid'),
layer: 'walls'
}
var newPath = createObj('path', pathObj);
paths2[paths2.length]=new PathMath.Path(newPath);
newPath.remove();
}
}
for (var _i in paths1) {
for (var _n in paths2) {
log(paths1[_i].intersects(paths2[_n]))
}
}