When aborting fat-line clipping, attempt an approximation with line intersections.

This commit is contained in:
Jürg Lehni 2017-02-22 13:58:27 +01:00
parent ba2b18c7dc
commit e3828d810b
2 changed files with 10 additions and 8 deletions

View file

@ -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,

View file

@ -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 }
]);
});