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
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);

View file

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

View file

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