mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
One last optimization in computeBoolean().
This commit is contained in:
parent
3ee10c1765
commit
b5abfcb515
1 changed files with 12 additions and 22 deletions
|
@ -104,8 +104,6 @@ PathItem.inject(new function() {
|
||||||
_path2 = reorientPath(path2.clone()),
|
_path2 = reorientPath(path2.clone()),
|
||||||
path1Clockwise = _path1.isClockwise(),
|
path1Clockwise = _path1.isClockwise(),
|
||||||
path2Clockwise = _path2.isClockwise(),
|
path2Clockwise = _path2.isClockwise(),
|
||||||
path1Id = _path1.id,
|
|
||||||
path2Id = _path2.id,
|
|
||||||
// Calculate all the intersections
|
// Calculate all the intersections
|
||||||
intersections = _cache && _cache.intersections
|
intersections = _cache && _cache.intersections
|
||||||
|| _path1.getIntersections(_path2);
|
|| _path1.getIntersections(_path2);
|
||||||
|
@ -124,45 +122,37 @@ PathItem.inject(new function() {
|
||||||
_path2.reverse();
|
_path2.reverse();
|
||||||
path2Clockwise = !path2Clockwise;
|
path2Clockwise = !path2Clockwise;
|
||||||
}
|
}
|
||||||
|
|
||||||
var paths = []
|
var paths = []
|
||||||
.concat(_path1._children || [_path1])
|
.concat(_path1._children || [_path1])
|
||||||
.concat(_path2._children || [_path2]),
|
.concat(_path2._children || [_path2]),
|
||||||
nodes = [],
|
segments = [],
|
||||||
result = new CompoundPath();
|
result = new CompoundPath();
|
||||||
// Step 1: Discard invalid links according to the boolean operator
|
// Step 1: Discard invalid links according to the boolean operator
|
||||||
for (var i = 0, l = paths.length; i < l; i++) {
|
for (var i = 0, l = paths.length; i < l; i++) {
|
||||||
var path = paths[i],
|
var path = paths[i],
|
||||||
parent = path._parent,
|
parent = path._parent,
|
||||||
id = parent instanceof CompoundPath ? parent._id : path._id,
|
|
||||||
clockwise = path.isClockwise(),
|
clockwise = path.isClockwise(),
|
||||||
segments = path._segments,
|
segs = path._segments;
|
||||||
insidePath1 = false,
|
path = parent instanceof CompoundPath ? parent : path;
|
||||||
insidePath2 = false;
|
for (var j = segs.length - 1; j >= 0; j--) {
|
||||||
for (var j = segments.length - 1; j >= 0; j--) {
|
var segment = segs[j],
|
||||||
var segment = segments[j],
|
midPoint = segment.getCurve().getPoint(0.5),
|
||||||
midPoint = segment.getCurve().getPoint(0.5);
|
insidePath1 = path !== _path1 && _path1.contains(midPoint)
|
||||||
if (id !== path1Id) {
|
|
||||||
insidePath1 = _path1.contains(midPoint)
|
|
||||||
&& (clockwise === path1Clockwise || subtract
|
&& (clockwise === path1Clockwise || subtract
|
||||||
|| !testOnCurve(_path1, midPoint));
|
|| !testOnCurve(_path1, midPoint));
|
||||||
}
|
insidePath2 = path !== _path2 && _path2.contains(midPoint)
|
||||||
if (id !== path2Id) {
|
|
||||||
insidePath2 = _path2.contains(midPoint)
|
|
||||||
&& (clockwise === path2Clockwise
|
&& (clockwise === path2Clockwise
|
||||||
|| !testOnCurve(_path2, midPoint));
|
|| !testOnCurve(_path2, midPoint));
|
||||||
}
|
if (operator(path === _path1, insidePath1, insidePath2)) {
|
||||||
if (operator(id === path1Id, insidePath1, insidePath2)) {
|
|
||||||
segment._invalid = true;
|
segment._invalid = true;
|
||||||
// markPoint(midPoint, '+');
|
|
||||||
} else {
|
} else {
|
||||||
nodes.push(segment);
|
segments.push(segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Step 2: Retrieve the resulting paths from the graph
|
// Step 2: Retrieve the resulting paths from the graph
|
||||||
for (var i = 0, l = nodes.length; i < l; i++) {
|
for (var i = 0, l = segments.length; i < l; i++) {
|
||||||
var segment = nodes[i];
|
var segment = segments[i];
|
||||||
if (segment._visited)
|
if (segment._visited)
|
||||||
continue;
|
continue;
|
||||||
var path = new Path(),
|
var path = new Path(),
|
||||||
|
|
Loading…
Reference in a new issue