mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Reduce epsilon in fat-line clipping to 1e-12 and adjust unit tests.
These results make much more sense and the algorithm finds less false positives while still behaving reliably in all edge cases.
This commit is contained in:
parent
2343ed5ca9
commit
357ff0dd43
3 changed files with 5 additions and 9 deletions
|
@ -1766,7 +1766,7 @@ new function() { // Scope for bezier intersection using fat-line clipping
|
||||||
return calls;
|
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.
|
||||||
var fatLineEpsilon = 1e-9,
|
var epsilon = /*#=*/Numerical.EPSILON,
|
||||||
// Let P be the first curve and Q be the second
|
// Let P be the first curve and Q be the second
|
||||||
q0x = v2[0], q0y = v2[1], q3x = v2[6], q3y = v2[7],
|
q0x = v2[0], q0y = v2[1], q3x = v2[6], q3y = v2[7],
|
||||||
getSignedDistance = Line.getSignedDistance,
|
getSignedDistance = Line.getSignedDistance,
|
||||||
|
@ -1803,7 +1803,7 @@ new function() { // Scope for bezier intersection using fat-line clipping
|
||||||
// original parameter range for v2.
|
// original parameter range for v2.
|
||||||
var tMinNew = tMin + (tMax - tMin) * tMinClip,
|
var tMinNew = tMin + (tMax - tMin) * tMinClip,
|
||||||
tMaxNew = tMin + (tMax - tMin) * tMaxClip;
|
tMaxNew = tMin + (tMax - tMin) * tMaxClip;
|
||||||
if (Math.max(uMax - uMin, tMaxNew - tMinNew) < fatLineEpsilon) {
|
if (Math.max(uMax - uMin, tMaxNew - tMinNew) < epsilon) {
|
||||||
// We have isolated the intersection with sufficient precision
|
// We have isolated the intersection with sufficient precision
|
||||||
var t = (tMinNew + tMaxNew) / 2,
|
var t = (tMinNew + tMaxNew) / 2,
|
||||||
u = (uMin + uMax) / 2;
|
u = (uMin + uMax) / 2;
|
||||||
|
@ -1839,7 +1839,7 @@ new function() { // Scope for bezier intersection using fat-line clipping
|
||||||
u, uMax, tMinNew, tMaxNew, !flip, recursion, calls);
|
u, uMax, tMinNew, tMaxNew, !flip, recursion, calls);
|
||||||
}
|
}
|
||||||
} else { // Iterate
|
} else { // Iterate
|
||||||
if (uMax - uMin >= fatLineEpsilon) {
|
if (uMax - uMin >= epsilon) {
|
||||||
calls = addCurveIntersections(
|
calls = addCurveIntersections(
|
||||||
v2, v1, c2, c1, locations, include,
|
v2, v1, c2, c1, locations, include,
|
||||||
uMin, uMax, tMinNew, tMaxNew, !flip, recursion, calls);
|
uMin, uMax, tMinNew, tMaxNew, !flip, recursion, calls);
|
||||||
|
|
|
@ -869,7 +869,7 @@ test('#1239', function() {
|
||||||
var p2 = new Path([[960, 352, -0.05999999999994543, 111.67999999999995, 0, 0], [1024, 352, 0, 0, -0.05999999999994543, 127.07], [890.69, 696.28, 85.5, -93.98000000000002, 0, 0], [843.44, 653.28, 0, 0, 75.14999999999998, -82.61000000000001], true]);
|
var p2 = new Path([[960, 352, -0.05999999999994543, 111.67999999999995, 0, 0], [1024, 352, 0, 0, -0.05999999999994543, 127.07], [890.69, 696.28, 85.5, -93.98000000000002, 0, 0], [843.44, 653.28, 0, 0, 75.14999999999998, -82.61000000000001], true]);
|
||||||
project.activeLayer.scale(0.25);
|
project.activeLayer.scale(0.25);
|
||||||
compareBoolean(function() { return p1.unite(p2); },
|
compareBoolean(function() { return p1.unite(p2); },
|
||||||
'M923.0175,265.805c21.3525,23.505 33.2725,54.305 33.2725,86.065c0,0.01833 0,0.03667 -0.00001,0.055h0.00001c-0.00005,0.10258 -0.00022,0.20515 -0.00052,0.3077c-0.06338,22.18242 -5.9393,43.88534 -16.78017,62.94682c-4.63138,8.14369 -10.16899,15.8051 -16.54682,22.81548l-11.8125,-10.75c8.97181,-9.86302 16.01692,-21.11585 20.93099,-33.22212c5.34364,-13.16533 8.16725,-27.34044 8.20856,-41.83592c0.0003,-0.10564 0.00044,-0.21129 0.00044,-0.31697c0,-27.9075 -10.32,-54.655 -29.0875,-75.315z');
|
'M923.0175,265.805c21.3525,23.505 33.2725,54.305 33.2725,86.065c0,0.01833 0,0.03667 -0.00001,0.055h0.00001c-0.00005,0.10258 -0.00022,0.20515 -0.00052,0.3077c-0.09045,31.65922 -12.02084,62.34173 -33.32698,85.7623l-11.8125,-10.75c18.8,-20.6675 29.14,-47.4375 29.14,-75.375c0,-27.9075 -10.32,-54.655 -29.0875,-75.315z');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Selected edge-cases from @hari\'s boolean-test suite', function() {
|
test('Selected edge-cases from @hari\'s boolean-test suite', function() {
|
||||||
|
|
|
@ -154,7 +154,6 @@ test('#1073', function() {
|
||||||
testIntersections(path1.getIntersections(path2), [
|
testIntersections(path1.getIntersections(path2), [
|
||||||
{ point: { x: 426.61172, y: 448 }, index: 0, time: 0.27769, crossing: true },
|
{ 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: 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 }
|
{ point: { x: 336.40125, y: 463.59875 }, index: 2, time: 0.00608, crossing: true }
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -230,11 +229,8 @@ test('#1239', function() {
|
||||||
testIntersections(p1.getIntersections(p2), [
|
testIntersections(p1.getIntersections(p2), [
|
||||||
{ point: { x: 956.28999, y: 351.925 }, index: 1, time: 0.000577, crossing: true},
|
{ point: { x: 956.28999, y: 351.925 }, index: 1, time: 0.000577, crossing: true},
|
||||||
{ point: { x: 956.28948, y: 352.2327 }, index: 1, time: 0.003804, crossing: true},
|
{ point: { x: 956.28948, y: 352.2327 }, index: 1, time: 0.003804, crossing: true},
|
||||||
{ point: { x: 939.50932, y: 415.17952 }, index: 1, time: 0.701801, crossing: true},
|
|
||||||
{ point: { x: 922.9625, y: 437.995 }, index: 2, time: 0, crossing: false},
|
{ point: { x: 922.9625, y: 437.995 }, index: 2, time: 0, crossing: false},
|
||||||
{ point: { x: 911.15, y: 427.245 }, index: 3, time: 0, crossing: false},
|
{ point: { x: 911.15, y: 427.245 }, index: 3, time: 0, crossing: false}
|
||||||
{ point: { x: 932.08099, y: 394.02288 }, index: 3, time: 0.477224, crossing: true},
|
|
||||||
{ point: { x: 940.28956, y: 352.18697 }, index: 3, time: 0.996218, crossing: true}
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue