mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Clean-up changes from #939
This commit is contained in:
parent
aed9d05bfc
commit
41aca10112
1 changed files with 14 additions and 12 deletions
|
@ -314,6 +314,7 @@ 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;
|
||||||
|
@ -349,17 +350,15 @@ PathItem.inject(new function() {
|
||||||
var xBefore = px - epsilon,
|
var xBefore = px - epsilon,
|
||||||
xAfter = px + epsilon,
|
xAfter = px + epsilon,
|
||||||
prevWinding,
|
prevWinding,
|
||||||
prevXEnd,
|
prevXEnd;
|
||||||
isOnCurve;
|
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
var curve = curves[i],
|
var curve = curves[i],
|
||||||
winding = curve.winding,
|
winding = curve.winding,
|
||||||
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
|
// The first curve of a loop holds the last curve with non-zero
|
||||||
// non-zero winding.
|
// winding. Retrieve and use it here (See _getMonoCurve()).
|
||||||
// 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 end x coordinate and winding of the last
|
||||||
// non-horizontal curve, which will be the previous
|
// non-horizontal curve, which will be the previous
|
||||||
|
@ -386,7 +385,7 @@ PathItem.inject(new function() {
|
||||||
// the previous curve's end point, it must be on a
|
// the previous curve's end point, it must be on a
|
||||||
// horizontal curve in between.
|
// horizontal curve in between.
|
||||||
var isOnHorizontal =
|
var isOnHorizontal =
|
||||||
(py === yStart && (px - x) * (px - prevXEnd) < 0);
|
py === yStart && (px - x) * (px - prevXEnd) < 0;
|
||||||
// Test if the point is on a y-monotonic curve
|
// Test if the point is on a y-monotonic curve
|
||||||
if ((x >= xBefore && x <= xAfter) || isOnHorizontal)
|
if ((x >= xBefore && x <= xAfter) || isOnHorizontal)
|
||||||
isOnCurve = true;
|
isOnCurve = true;
|
||||||
|
@ -411,7 +410,10 @@ PathItem.inject(new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the point was on a monocurve, ensure that the winding is odd.
|
// If the point is on a monotonic curve, ensure that the winding is odd
|
||||||
|
// 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 );
|
return Math.max(abs(windLeft), abs(windRight)) | (isOnCurve ? 1 : 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue