Optimize Item#intersects() by only checking to see if there are at least one intersection.

This commit is contained in:
Jürg Lehni 2015-08-25 11:45:28 +02:00
parent 7ca8ce3cbb
commit fd1f2e56f8
3 changed files with 22 additions and 15 deletions

View file

@ -77,7 +77,8 @@ PathItem.inject(new function() {
_path2.reverse();
// Split curves at intersections on both paths. Note that for self
// intersection, _path2 will be null and getIntersections() handles it.
splitPath(_path1.getIntersections(_path2, null, true));
splitPath(Curve.filterIntersections(
_path1._getIntersections(_path2, null, []), true));
var chain = [],
segments = [],
@ -538,7 +539,7 @@ PathItem.inject(new function() {
// the correct contour to traverse next.
w3 = t1.cross(t3),
w4 = t1.cross(t4);
if (Math.abs(w3 * w4) > Numerical.EPSILON) {
if (Math.abs(w3 * w4) > /*#=*/Numerical.EPSILON) {
// Do not attempt to switch contours if we aren't
// sure that there is a possible candidate.
var curve = w3 < w4 ? c3 : c4,
@ -603,7 +604,8 @@ PathItem.inject(new function() {
? startInterSeg : seg)._handleIn);
} else {
path.lastSegment._handleOut.set(0, 0);
console.error('Boolean operation results in open path!');
console.error('Boolean operation results in open path, length =',
path._segments.length);
}
path.setClosed(true);
// Add the path to the result, while avoiding stray segments and