mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Revert "Change the way we determine the winding in getWinding()."
This commit is contained in:
parent
0152439627
commit
f7b1aca3e4
1 changed files with 21 additions and 25 deletions
|
@ -314,7 +314,6 @@ PathItem.inject(new function() {
|
||||||
py = point.y,
|
py = point.y,
|
||||||
windLeft = 0,
|
windLeft = 0,
|
||||||
windRight = 0,
|
windRight = 0,
|
||||||
isOnCurve = false,
|
|
||||||
length = curves.length,
|
length = curves.length,
|
||||||
roots = [],
|
roots = [],
|
||||||
abs = Math.abs;
|
abs = Math.abs;
|
||||||
|
@ -357,12 +356,13 @@ PathItem.inject(new function() {
|
||||||
values = curve.values,
|
values = curve.values,
|
||||||
yStart = values[1],
|
yStart = values[1],
|
||||||
yEnd = values[7];
|
yEnd = values[7];
|
||||||
// The first curve of a loop holds the last curve with non-zero
|
// The first curve of a loop holds the last curve with
|
||||||
// winding. Retrieve and use it here (See _getMonoCurve()).
|
// non-zero winding.
|
||||||
|
// Retrieve and use it here (See _getMonoCurve()).
|
||||||
if (curve.last) {
|
if (curve.last) {
|
||||||
// Get the end x coordinate and winding of the last
|
// Get the values of to the end x coordinate and winding of
|
||||||
// non-horizontal curve, which will be the previous
|
// the last non-horizontal curve, which will be the previous
|
||||||
// non-horizontal curve for first curve in the loop.
|
// non-horizontal curve for the first curve of the loop.
|
||||||
prevWinding = curve.last.winding;
|
prevWinding = curve.last.winding;
|
||||||
prevXEnd = curve.last.values[6];
|
prevXEnd = curve.last.values[6];
|
||||||
}
|
}
|
||||||
|
@ -381,25 +381,25 @@ PathItem.inject(new function() {
|
||||||
? Curve.getPoint(values, roots[0]).x
|
? Curve.getPoint(values, roots[0]).x
|
||||||
: null;
|
: null;
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
// If the point is between the curve's start point and
|
|
||||||
// the previous curve's end point, it must be on a
|
|
||||||
// horizontal curve in between.
|
|
||||||
var isOnHorizontal =
|
|
||||||
py === yStart && (px - x) * (px - prevXEnd) < 0;
|
|
||||||
// Test if the point is on a y-monotonic curve
|
|
||||||
if ((x >= xBefore && x <= xAfter) || isOnHorizontal)
|
|
||||||
isOnCurve = true;
|
|
||||||
// Count the intersection of the ray with the
|
// Count the intersection of the ray with the
|
||||||
// y-monotonic curve if:
|
// monotonic curve if:
|
||||||
// - the crossing is not the start or end of the curve
|
// - the crossing is not at the start of the curve
|
||||||
// - or the crossing is at the start of the curve and
|
// - or the windings are opposite (intersect at a
|
||||||
// the winding did not change between curves
|
// vertical extremum)
|
||||||
if (py != yEnd
|
// - or the start of the current curve and the end
|
||||||
&& (py != yStart || winding === prevWinding)) {
|
// of the prev curve are on opposite sides of px
|
||||||
|
var isWindingChange = winding === -prevWinding;
|
||||||
|
if (py !== yStart || isWindingChange
|
||||||
|
|| (x - px) * (prevXEnd - px) < 0) {
|
||||||
if (x < xBefore) {
|
if (x < xBefore) {
|
||||||
windLeft += winding;
|
windLeft += winding;
|
||||||
} else if (x > xAfter) {
|
} else if (x > xAfter) {
|
||||||
windRight += winding;
|
windRight += winding;
|
||||||
|
} else if (py === yStart && isWindingChange) {
|
||||||
|
// The point is a vertical extremum of the
|
||||||
|
// path.
|
||||||
|
++windLeft;
|
||||||
|
++windRight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -410,11 +410,7 @@ PathItem.inject(new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the point is on a monotonic curve, ensure that the winding is odd
|
return Math.max(abs(windLeft), abs(windRight));
|
||||||
// by applying bit-wise or `| 1` to the bigger absolute winding number:
|
|
||||||
// If winding is an even number and the point is on a curve, this will
|
|
||||||
// add up to the next uneven number, otherwise it remains the same.
|
|
||||||
return Math.max(abs(windLeft), abs(windRight)) | (isOnCurve ? 1 : 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function propagateWinding(segment, path1, path2, monoCurves, operator) {
|
function propagateWinding(segment, path1, path2, monoCurves, operator) {
|
||||||
|
|
Loading…
Reference in a new issue