Fix calls counting in addCurveIntersections() when dealing with straight curves.

See https://github.com/paperjs/paper.js/issues/1239#issuecomment-284340550
This commit is contained in:
Jürg Lehni 2017-03-06 10:13:14 +01:00
parent b85fc988de
commit b680ec05b9

View file

@ -1759,18 +1759,19 @@ new function() { // Scope for bezier intersection using fat-line clipping
// as well as the total amount of calls, to avoid massive call-trees as // as well as the total amount of calls, to avoid massive call-trees as
// suggested by @iconexperience in #904#issuecomment-225283430. // suggested by @iconexperience in #904#issuecomment-225283430.
// See also: #565 #899 #1074 // See also: #565 #899 #1074
var abort = ++recursion >= 48 || ++calls > 256, var abort = ++recursion >= 48 || ++calls > 4096,
// Consider both curves as straight if we need to abort and see if // If we need to abort, consider both curves as straight and see if
// their lines intersect. // their lines intersect.
straight1 = abort || Curve.isStraight(v1), straight1 = abort || Curve.isStraight(v1),
straight2 = abort || Curve.isStraight(v2); straight2 = abort || Curve.isStraight(v2);
if (straight1 || straight2) { if (straight1 || straight2) {
return (straight1 && straight2 (straight1 && straight2
? addLineIntersection ? addLineIntersection
: addCurveLineIntersections)( : addCurveLineIntersections)(
flip ? v2 : v1, flip ? v1 : v2, flip ? v2 : v1, flip ? v1 : v2,
flip ? c2 : c1, flip ? c1 : c2, flip ? c2 : c1, flip ? c1 : c2,
locations, include, recursion); locations, include, recursion);
return calls;
} }
// Use an epsilon smaller than CURVETIME_EPSILON to compare curve-time // Use an epsilon smaller than CURVETIME_EPSILON to compare curve-time
// parameters in fat-line clipping code. // parameters in fat-line clipping code.