Winding: Don't mix up onPath and onCurve.

This commit is contained in:
Jürg Lehni 2016-07-23 18:50:58 +02:00
parent 31732917c0
commit e2e024f8a5

View file

@ -425,8 +425,7 @@ PathItem.inject(new function() {
: Curve.getPoint(v, t)[dir ? 'y' : 'x'], : Curve.getPoint(v, t)[dir ? 'y' : 'x'],
winding = o0 > o3 ? 1 : -1, winding = o0 > o3 ? 1 : -1,
windingPrev = vPrev[io] > vPrev[io + 6] ? 1 : -1, windingPrev = vPrev[io] > vPrev[io + 6] ? 1 : -1,
a3Prev = vPrev[ia + 6], a3Prev = vPrev[ia + 6];
onCurve = false;
if (po !== o0) { if (po !== o0) {
// Standard case, curve is not crossed at its starting point. // Standard case, curve is not crossed at its starting point.
if (a < paL) { if (a < paL) {
@ -434,7 +433,7 @@ PathItem.inject(new function() {
} else if (a > paR) { } else if (a > paR) {
pathWindingR += winding; pathWindingR += winding;
} else { } else {
onCurve = true; onPath = true;
pathWindingL += winding; pathWindingL += winding;
pathWindingR += winding; pathWindingR += winding;
} }
@ -450,7 +449,7 @@ PathItem.inject(new function() {
} else if (a3Prev < paL && a > paL || a3Prev > paR && a < paR) { } else if (a3Prev < paL && a > paL || a3Prev > paR && a < paR) {
// Point is on a horizontal curve between the previous non- // Point is on a horizontal curve between the previous non-
// horizontal and the current curve. // horizontal and the current curve.
onCurve = true; onPath = true;
if (a3Prev < paL) { if (a3Prev < paL) {
// left winding was added before, now add right winding. // left winding was added before, now add right winding.
pathWindingR += winding; pathWindingR += winding;
@ -460,13 +459,11 @@ PathItem.inject(new function() {
} }
} }
vPrev = v; vPrev = v;
if (onCurve)
onPath = true;
// If we're on the curve, look at the tangent to decide whether to // If we're on the curve, look at the tangent to decide whether to
// flip direction to determine a reliable winding number: // flip direction to better determine a reliable winding number:
// If the tangent is parallel to the direction, call getWinding() // If the tangent is parallel to the direction, call getWinding()
// again with flipped direction and return the result. // again with flipped direction and return that result instead.
return onCurve && !dontFlip return !dontFlip && a > paL && a < paR
&& Curve.getTangent(v, t)[dir ? 'x' : 'y'] === 0 && Curve.getTangent(v, t)[dir ? 'x' : 'y'] === 0
&& getWinding(point, curves, dir ? 0 : 1, true); && getWinding(point, curves, dir ? 0 : 1, true);
} }