From afc14b9634dd0beea435f02ec935120defff4173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rg=20Lehni?= Date: Sun, 4 Jan 2015 15:54:50 +0100 Subject: [PATCH] Reduce Numerical.TOLERANCE to 1e-6, and use the same value across the boolean code. Yields very good results now, across all tests. --- src/path/Curve.js | 3 +-- src/path/PathItem.Boolean.js | 9 +-------- src/util/Numerical.js | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index 7e28ddf3..09924a9c 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -1073,7 +1073,6 @@ new function() { // Scope for methods that require numerical integration // Let P be the first curve and Q be the second var q0x = v2[0], q0y = v2[1], q3x = v2[6], q3y = v2[7], tolerance = /*#=*/Numerical.TOLERANCE, - epsilon = 1e-10, // /*#=*/Numerical.EPSILON, // Calculate the fat-line L for Q is the baseline l and two // offsets which completely encloses the curve P. d1 = getSignedDistance(q0x, q0y, q3x, q3y, v2[2], v2[3]) || 0, @@ -1089,7 +1088,7 @@ new function() { // Scope for methods that require numerical integration dp2 = getSignedDistance(q0x, q0y, q3x, q3y, v1[4], v1[5]), dp3 = getSignedDistance(q0x, q0y, q3x, q3y, v1[6], v1[7]), tMinNew, tMaxNew, tDiff; - if (q0x === q3x && uMax - uMin <= epsilon && recursion > 3) { + if (q0x === q3x && uMax - uMin <= tolerance && recursion > 3) { // The fatline of Q has converged to a point, the clipping is not // reliable. Return the value we have even though we will miss the // precision. diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index 889c309e..1c5aa876 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -252,14 +252,7 @@ PathItem.inject(new function() { * with respect to a given set of monotone curves. */ function getWinding(point, curves, horizontal, testContains) { - // We need to use a smaller tolerance here than in the rest of the - // library when dealing with curve time parameters and coordinates, in - // order to get really precise values for winding tests. 1e-7 was - // determined through a lot of trial and error, and boolean-test suites. - // Further decreasing it produces new errors. - // The value of 1e-7 also solves issue #559: - // https://github.com/paperjs/paper.js/issues/559 - var tolerance = 1e-7, + var tolerance = /*#=*/Numerical.TOLERANCE, tMin = tolerance, tMax = 1 - tMin, x = point.x, diff --git a/src/util/Numerical.js b/src/util/Numerical.js index 01dd3ecf..cc043f01 100644 --- a/src/util/Numerical.js +++ b/src/util/Numerical.js @@ -63,7 +63,7 @@ var Numerical = new function() { cos = Math.cos, PI = Math.PI, isFinite = Number.isFinite, - TOLERANCE = 1e-5, + TOLERANCE = 1e-6, EPSILON = 1e-13, MACHINE_EPSILON = 1.12e-16;