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.
This commit is contained in:
Jürg Lehni 2017-01-15 11:47:23 +01:00
parent cf2ebbaaf8
commit a101183fba
3 changed files with 16 additions and 21 deletions

View file

@ -1740,8 +1740,11 @@ new function() { // Scope for intersection using bezier fat-line clipping
// See also: #565 #899 #1074 // See also: #565 #899 #1074
if (++recursion >= 48 || ++calls > 4096) if (++recursion >= 48 || ++calls > 4096)
return calls; return calls;
// Let P be the first curve and Q be the second // Use an epsilon smaller than CURVETIME_EPSILON to compare curve-time
var q0x = v2[0], q0y = v2[1], q3x = v2[6], q3y = v2[7], // 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, getSignedDistance = Line.getSignedDistance,
// Calculate the fat-line L for Q is the baseline l and two // Calculate the fat-line L for Q is the baseline l and two
// offsets which completely encloses the curve P. // 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. // 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) if (Math.max(uMax - uMin, tMaxNew - tMinNew) < epsilon) {
< /*#=*/Numerical.CLIPPING_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;
@ -1813,7 +1815,7 @@ new function() { // Scope for intersection using bezier fat-line clipping
u, uMax, tMinNew, tMaxNew, !flip, recursion, calls); u, uMax, tMinNew, tMaxNew, !flip, recursion, calls);
} }
} else { // Iterate } else { // Iterate
if (uMax - uMin >= /*#=*/Numerical.CLIPPING_EPSILON) { if (uMax - uMin >= epsilon) {
calls = addCurveIntersections( calls = addCurveIntersections(
v2, v1, c2, c1, locations, param, v2, v1, c2, c1, locations, param,
uMin, uMax, tMinNew, tMaxNew, !flip, recursion, calls); uMin, uMax, tMinNew, tMaxNew, !flip, recursion, calls);

View file

@ -401,16 +401,18 @@ PathItem.inject(new function() {
* @private * @private
*/ */
function getWinding(point, curves, dir, closed, dontFlip) { function getWinding(point, curves, dir, closed, dontFlip) {
var epsilon = /*#=*/Numerical.WINDING_EPSILON, // Determine the index of the abscissa and ordinate values in the curve
// Determine the index of the abscissa and ordinate values in the // values arrays, based on the direction:
// curve values arrays, based on the direction: var ia = dir ? 1 : 0, // the abscissa index
ia = dir ? 1 : 0, // the abscissa index
io = dir ? 0 : 1, // the ordinate index io = dir ? 0 : 1, // the ordinate index
pv = [point.x, point.y], pv = [point.x, point.y],
pa = pv[ia], // the point's abscissa pa = pv[ia], // the point's abscissa
po = pv[io], // the point's ordinate po = pv[io], // the point's ordinate
paL = pa - epsilon, // Use separate epsilons for winding contribution code.
paR = pa + epsilon, windingEpsilon = 1e-8,
qualityEpsilon = 1e-6,
paL = pa - windingEpsilon,
paR = pa + windingEpsilon,
windingL = 0, windingL = 0,
windingR = 0, windingR = 0,
onPath = false, onPath = false,
@ -497,7 +499,7 @@ PathItem.inject(new function() {
// curves, the quality becomes less than 0.5 // curves, the quality becomes less than 0.5
// TODO: Set quality depending on distance // TODO: Set quality depending on distance
if (po !== o0) { 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 *= Math.min(1, (100 * epsilon * Math.abs(a - pa) + 0.5));
quality /= 2; quality /= 2;
} }

View file

@ -148,20 +148,11 @@ var Numerical = new function() {
* distances between points and lines. * distances between points and lines.
*/ */
GEOMETRIC_EPSILON: 1e-7, 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 * The epsilon to be used when performing "trigonometric" checks, such
* as examining cross products to check for collinearity. * as examining cross products to check for collinearity.
*/ */
TRIGONOMETRIC_EPSILON: 1e-8, 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 * Kappa is the value which which to scale the curve handles when
* drawing a circle with bezier curves. * drawing a circle with bezier curves.