diff --git a/src/path/Curve.js b/src/path/Curve.js index 01fff17c..ef2fa1af 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -1758,8 +1758,15 @@ new function() { // Scope for bezier intersection using fat-line clipping function addCurveIntersections(v1, v2, c1, c2, tMin, tMax, uMin, uMax, locations, include, recursion, calls, flip) { - var straight1 = Curve.isStraight(v1), - straight2 = Curve.isStraight(v2); + // Avoid deeper recursion, by counting the total amount of recursions, + // as well as the total amount of calls, to avoid massive call-trees as + // suggested by @iconexperience in #904#issuecomment-225283430. + // See also: #565 #899 #1074 + var abort = ++recursion >= 48 || ++calls > 256, + // Consider both curves as straight if we need to abort and see if + // their lines intersect. + straight1 = abort || Curve.isStraight(v1), + straight2 = abort || Curve.isStraight(v2); if (straight1 || straight2) { return (straight1 && straight2 ? addLineIntersection @@ -1768,12 +1775,6 @@ new function() { // Scope for bezier intersection using fat-line clipping flip ? c2 : c1, flip ? c1 : c2, locations, include, recursion); } - // Avoid deeper recursion, by counting the total amount of recursions, - // as well as the total amount of calls, to avoid massive call-trees as - // suggested by @iconexperience in #904#issuecomment-225283430. - // See also: #565 #899 #1074 - if (++recursion >= 48 || ++calls > 256) - return calls; // Use an epsilon smaller than CURVETIME_EPSILON to compare curve-time // parameters in fat-line clipping code. var epsilon = /*#=*/Numerical.EPSILON, diff --git a/test/tests/Path_Intersections.js b/test/tests/Path_Intersections.js index a819a8d6..4627c953 100644 --- a/test/tests/Path_Intersections.js +++ b/test/tests/Path_Intersections.js @@ -154,6 +154,7 @@ test('#1073', function() { testIntersections(path1.getIntersections(path2), [ { point: { x: 426.61172, y: 448 }, index: 0, time: 0.27769, crossing: true }, { point: { x: 376, y: 480 }, index: 1, time: 0, crossing: true }, + { point: { x: 343.68011, y: 469.7389 }, index: 1, time: 0.77843, crossing: true }, { point: { x: 336.40125, y: 463.59875 }, index: 2, time: 0.00608, crossing: true } ]); });