Answered
Geometric test functions

Testing whether a selected path intersects() a selected path:
var intersects = function() {
if (app.selection.length == 1) {
return false;
}
app.executeMenuCommand("group");
app.executeMenuCommand("Live Pathfinder Intersect");
app.executeMenuCommand("expandStyle");
app.executeMenuCommand("ungroup");
var a = app.selection.length;
app.redraw();
app.undo();
return a == 1;
}
alert( intersects() );
Testing whether a selected path contains() a selected path:
var contains = function() {
app.executeMenuCommand("group");
app.executeMenuCommand("Live Pathfinder Subtract");
app.executeMenuCommand("expandStyle");
app.executeMenuCommand("ungroup");
var a = app.selection[0].typename;
var b = app.selection.length;
app.redraw();
app.undo();
return a == "CompoundPathItem" || b == 2;
// if a front path totally eclipsing a back path shouldn't count as contains()
// then remove the b == 2 part of the expression
}
alert( contains() );
Whether a path contains() a point can be tested by first converting the point to a path with the same coordinates:
var convertPointToPath = function (x, y) {
var path1 = app.activeDocument.pathItems.add();
path1.setEntirePath([ [x, y], [x, y] ]);
return path1;
}
// e.g.
var w = app.activeDocument.width;
var h = - app.activeDocument.height;
var tempPoint = convertPointToPath(w/2, h/2);
- Feedback is appreciated.
- Is there any way to do away with redraw()? Presently, without redraw(), undo() undos the script and a step before.
Thanks in advance.
