mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -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,
|
||||
windLeft = 0,
|
||||
windRight = 0,
|
||||
isOnCurve = false,
|
||||
length = curves.length,
|
||||
roots = [],
|
||||
abs = Math.abs;
|
||||
|
@ -349,17 +350,15 @@ PathItem.inject(new function() {
|
|||
var xBefore = px - epsilon,
|
||||
xAfter = px + epsilon,
|
||||
prevWinding,
|
||||
prevXEnd,
|
||||
isOnCurve;
|
||||
prevXEnd;
|
||||
for (var i = 0; i < length; i++) {
|
||||
var curve = curves[i],
|
||||
winding = curve.winding,
|
||||
values = curve.values,
|
||||
yStart = values[1],
|
||||
yEnd = values[7];
|
||||
// The first curve of a loop holds the last curve with
|
||||
// non-zero winding.
|
||||
// Retrieve and use it here (See _getMonoCurve()).
|
||||
// The first curve of a loop holds the last curve with non-zero
|
||||
// winding. Retrieve and use it here (See _getMonoCurve()).
|
||||
if (curve.last) {
|
||||
// Get the end x coordinate and winding of the last
|
||||
// non-horizontal curve, which will be the previous
|
||||
|
@ -374,19 +373,19 @@ PathItem.inject(new function() {
|
|||
// Horizontal curves with winding == 0 will be completely
|
||||
// ignored.
|
||||
if (winding && (py >= yStart && py <= yEnd
|
||||
|| py >= yEnd && py <= yStart)) {
|
||||
|| py >= yEnd && py <= yStart)) {
|
||||
// Calculate the x value for the ray's intersection.
|
||||
var x = py === yStart ? values[0]
|
||||
: py === yEnd ? values[6]
|
||||
: Curve.solveCubic(values, 1, py, roots, 0, 1) === 1
|
||||
? Curve.getPoint(values, roots[0]).x
|
||||
: null;
|
||||
? Curve.getPoint(values, roots[0]).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 inbetween.
|
||||
// horizontal curve in between.
|
||||
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
|
||||
if ((x >= xBefore && x <= xAfter) || isOnHorizontal)
|
||||
isOnCurve = true;
|
||||
|
@ -396,7 +395,7 @@ PathItem.inject(new function() {
|
|||
// - or the crossing is at the start of the curve and
|
||||
// the winding did not change between curves
|
||||
if (py != yEnd
|
||||
&& (py != yStart || winding === prevWinding)) {
|
||||
&& (py != yStart || winding === prevWinding)) {
|
||||
if (x < xBefore) {
|
||||
windLeft += winding;
|
||||
} else if (x > xAfter) {
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue