From a101183fba1266c5f4fb72abdc683e9e5235542b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 15 Jan 2017 11:47:23 +0100 Subject: [PATCH] Remove EPSILON constants that are only used in one place in the code. CLIPPING_EPSILON and WINDING_EPSILON are too specific to be in Numerical. --- src/path/Curve.js | 12 +++++++----- src/path/PathItem.Boolean.js | 16 +++++++++------- src/util/Numerical.js | 9 --------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index 4acc60fd..1b604aa0 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -1740,8 +1740,11 @@ new function() { // Scope for intersection using bezier fat-line clipping // See also: #565 #899 #1074 if (++recursion >= 48 || ++calls > 4096) return calls; - // Let P be the first curve and Q be the second - var q0x = v2[0], q0y = v2[1], q3x = v2[6], q3y = v2[7], + // Use an epsilon smaller than CURVETIME_EPSILON to compare curve-time + // parameters in fat-line clipping code. + var epsilon = 1e-9, + // Let P be the first curve and Q be the second + q0x = v2[0], q0y = v2[1], q3x = v2[6], q3y = v2[7], getSignedDistance = Line.getSignedDistance, // Calculate the fat-line L for Q is the baseline l and two // offsets which completely encloses the curve P. @@ -1776,8 +1779,7 @@ new function() { // Scope for intersection using bezier fat-line clipping // original parameter range for v2. var tMinNew = tMin + (tMax - tMin) * tMinClip, tMaxNew = tMin + (tMax - tMin) * tMaxClip; - if (Math.max(uMax - uMin, tMaxNew - tMinNew) - < /*#=*/Numerical.CLIPPING_EPSILON) { + if (Math.max(uMax - uMin, tMaxNew - tMinNew) < epsilon) { // We have isolated the intersection with sufficient precision var t = (tMinNew + tMaxNew) / 2, u = (uMin + uMax) / 2; @@ -1813,7 +1815,7 @@ new function() { // Scope for intersection using bezier fat-line clipping u, uMax, tMinNew, tMaxNew, !flip, recursion, calls); } } else { // Iterate - if (uMax - uMin >= /*#=*/Numerical.CLIPPING_EPSILON) { + if (uMax - uMin >= epsilon) { calls = addCurveIntersections( v2, v1, c2, c1, locations, param, uMin, uMax, tMinNew, tMaxNew, !flip, recursion, calls); diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index 515746b6..3b9ce1d1 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -401,16 +401,18 @@ PathItem.inject(new function() { * @private */ function getWinding(point, curves, dir, closed, dontFlip) { - var epsilon = /*#=*/Numerical.WINDING_EPSILON, - // Determine the index of the abscissa and ordinate values in the - // curve values arrays, based on the direction: - ia = dir ? 1 : 0, // the abscissa index + // Determine the index of the abscissa and ordinate values in the curve + // values arrays, based on the direction: + var ia = dir ? 1 : 0, // the abscissa index io = dir ? 0 : 1, // the ordinate index pv = [point.x, point.y], pa = pv[ia], // the point's abscissa po = pv[io], // the point's ordinate - paL = pa - epsilon, - paR = pa + epsilon, + // Use separate epsilons for winding contribution code. + windingEpsilon = 1e-8, + qualityEpsilon = 1e-6, + paL = pa - windingEpsilon, + paR = pa + windingEpsilon, windingL = 0, windingR = 0, onPath = false, @@ -497,7 +499,7 @@ PathItem.inject(new function() { // curves, the quality becomes less than 0.5 // TODO: Set quality depending on distance if (po !== o0) { - if (a > pa - 100 * epsilon && a < pa + 100 * epsilon) { + if (a > pa - qualityEpsilon && a < pa + qualityEpsilon) { //quality *= Math.min(1, (100 * epsilon * Math.abs(a - pa) + 0.5)); quality /= 2; } diff --git a/src/util/Numerical.js b/src/util/Numerical.js index d0e8b8f7..72cccb75 100644 --- a/src/util/Numerical.js +++ b/src/util/Numerical.js @@ -148,20 +148,11 @@ var Numerical = new function() { * distances between points and lines. */ GEOMETRIC_EPSILON: 1e-7, - /** - * The epsilon to be used when performing winding contribution checks. - */ - WINDING_EPSILON: 1e-8, /** * The epsilon to be used when performing "trigonometric" checks, such * as examining cross products to check for collinearity. */ TRIGONOMETRIC_EPSILON: 1e-8, - /** - * The epsilon to be used when comparing curve-time parameters in the - * fat-line clipping code. - */ - CLIPPING_EPSILON: 1e-9, /** * Kappa is the value which which to scale the curve handles when * drawing a circle with bezier curves.