Restructure code from #883 a bit

- Use === instead of == for strict numeric comparisons
- Merge the two return statements to one
- Address some imprecisions in previously added comments
This commit is contained in:
Jürg Lehni 2016-01-02 23:39:13 +01:00
parent 46cf517976
commit 9404c5a0e3

View file

@ -1462,13 +1462,13 @@ new function() { // Scope for intersection using bezier fat-line clipping
bottom = hull[1], bottom = hull[1],
tMinClip, tMinClip,
tMaxClip; tMaxClip;
// Stop iteration if all points and control points are exactly collinear. // Stop iteration if all points and control points are collinear.
if (d1 == 0 && d2 == 0 && dp0 == 0 && dp1 == 0 && dp2 == 0 && dp3 == 0) if (d1 === 0 && d2 === 0
return; && dp0 === 0 && dp1 === 0 && dp2 === 0 && dp3 === 0
// Clip the convex-hull with dMin and dMax, taking into account that // Clip the convex-hull with dMin and dMax, taking into account that
// there will be no intersections if one of the tvalues are null. // there will be no intersections if one of the tvalues are null.
if ((tMinClip = clipConvexHull(top, bottom, dMin, dMax)) == null || || (tMinClip = clipConvexHull(top, bottom, dMin, dMax)) == null
(tMaxClip = clipConvexHull(top.reverse(), bottom.reverse(), || (tMaxClip = clipConvexHull(top.reverse(), bottom.reverse(),
dMin, dMax)) == null) dMin, dMax)) == null)
return; return;
// tMin and tMax are within the range (0, 1). We need to project it // tMin and tMax are within the range (0, 1). We need to project it
@ -1490,7 +1490,7 @@ new function() { // Scope for intersection using bezier fat-line clipping
reverse ? v2 : v1, reverse ? c2 : c1, reverse ? u : t, null, reverse ? v2 : v1, reverse ? c2 : c1, reverse ? u : t, null,
reverse ? v1 : v2, reverse ? c1 : c2, reverse ? t : u, null); reverse ? v1 : v2, reverse ? c1 : c2, reverse ? t : u, null);
} else { } else {
// Clip P with the fat-line for Q // Apply the result of the clipping to curve 1:
var v1Clip = Curve.getPart(v1, tMinClip, tMaxClip), var v1Clip = Curve.getPart(v1, tMinClip, tMaxClip),
tDiff = tMaxClip - tMinClip; tDiff = tMaxClip - tMinClip;
if (oldTDiff > 0.5 && tDiff > 0.5) { if (oldTDiff > 0.5 && tDiff > 0.5) {
@ -1518,9 +1518,9 @@ new function() { // Scope for intersection using bezier fat-line clipping
addCurveIntersections(v2, v1Clip, c2, c1, locations, param, addCurveIntersections(v2, v1Clip, c2, c1, locations, param,
uMin, uMax, tMinNew, tMaxNew, tDiff, !reverse, recursion); uMin, uMax, tMinNew, tMaxNew, tDiff, !reverse, recursion);
} else { } else {
// P has converged to a point. Since we cannot construct a fat- // Curve 1 has converged to a point. Since we cannot construct a
// line from a point, we dismiss this clipping so we can // fat-line from a point, we dismiss this clipping so we can
// continue with clipping Q. // continue clipping curve 2.
addCurveIntersections(v2, v1, c2, c1, locations, param, addCurveIntersections(v2, v1, c2, c1, locations, param,
uMin, uMax, tMin, tMax, tDiff, !reverse, recursion); uMin, uMax, tMin, tMax, tDiff, !reverse, recursion);
} }