more optimizations in computeBoolean().

I think this is done now!
This commit is contained in:
Jürg Lehni 2013-05-04 03:00:31 -07:00
parent 9aafb46e6c
commit 7fdaa3e699

View file

@ -57,7 +57,7 @@ PathItem.inject(new function() {
segment = curve && curve.getSegment1() || loc.getSegment(); segment = curve && curve.getSegment1() || loc.getSegment();
if (others) if (others)
others.push(other); others.push(other);
segment._ixPair = other; segment._intersection = other;
} }
return others; return others;
} }
@ -153,7 +153,7 @@ PathItem.inject(new function() {
|| !testOnCurve(_path2, midPoint)); || !testOnCurve(_path2, midPoint));
} }
if (operator(id === path1Id, insidePath1, insidePath2)) { if (operator(id === path1Id, insidePath1, insidePath2)) {
segment._INVALID = true; segment._invalid = true;
// markPoint(midPoint, '+'); // markPoint(midPoint, '+');
} else { } else {
nodes.push(segment); nodes.push(segment);
@ -162,39 +162,38 @@ PathItem.inject(new function() {
} }
// 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 = nodes.length; i < l; i++) {
var node = nodes[i]; var segment = nodes[i];
if (node._visited) if (segment._visited)
continue; continue;
var path = node.path, var path = new Path(),
nuPath = new Path(), loc = segment._intersection,
end = node._ixPair && node._ixPair.getSegment(true); last = loc && loc.getSegment(true);
if (node.getPrevious()._INVALID) { if (segment.getPrevious()._invalid)
node.setHandleIn(node._ixPair segment.setHandleIn(last ? last._handleIn : Point.create(0, 0));
? node._ixPair.getSegment(true)._handleIn
: Point.create(0, 0));
}
do { do {
node._visited = true; segment._visited = true;
// node._ixPair is this node's intersection CurveLocation object if (segment._intersection) {
if (node._ixPair) { var next = segment._invalid
var nextNode = node._INVALID ? segment._intersection.getSegment(true)
? node._ixPair.getSegment(true) : segment;
: node; path.add(new Segment(segment._point, segment._handleIn,
nuPath.add(new Segment(node._point, node._handleIn, next._handleOut));
nextNode._handleOut)); next._visited = true;
nextNode._visited = true; segment = next;
node = nextNode;
} else { } else {
nuPath.add(node); // Remove temporary digraph data structures from segment
delete segment._invalid;
delete segment._intersection;
path.add(segment);
} }
node = node.getNext(); segment = segment.getNext();
} while (node && !node._visited && node !== end); } while (segment && !segment._visited && segment !== last);
// Avoid stray segments and incomplete paths // Avoid stray segments and incomplete paths
if (nuPath._segments.length > 2) { if (path._segments.length > 2) {
nuPath.setClosed(true); path.setClosed(true);
result.addChild(nuPath, true); result.addChild(path, true);
} else { } else {
nuPath.remove(); path.remove();
} }
} }
// Delete the proxies // Delete the proxies