mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Some code cleanup for winding-fix.
This commit is contained in:
parent
23045bb0f7
commit
55909b8bd5
1 changed files with 15 additions and 17 deletions
|
@ -380,23 +380,21 @@ PathItem.inject(new function() {
|
||||||
? Curve.getPoint(values, roots[0]).x
|
? Curve.getPoint(values, roots[0]).x
|
||||||
: null;
|
: null;
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
// determine if the point is on the horizontal
|
// Test if the point is on the current mono-curve.
|
||||||
// connection between the last non-horizontal curve's
|
|
||||||
// end point and the current curve's start point
|
|
||||||
var isOnHorizontal =
|
|
||||||
(py === yStart && (px - x) * (px - prevXEnd) < 0);
|
|
||||||
// Test if the point is on the current monocurve
|
|
||||||
if (x >= xBefore && x <= xAfter) {
|
if (x >= xBefore && x <= xAfter) {
|
||||||
isOnCurve = true;
|
isOnCurve = true;
|
||||||
// Count the intersection of the ray with the
|
} else if (
|
||||||
// monotonic curve if:
|
// Count the intersection of the ray with the
|
||||||
// - the crossing is not the start of the curve
|
// monotonic curve if the crossing is not the
|
||||||
// except if the winding changes.
|
// start of the curve, except if the winding
|
||||||
// - and the point is not on the curve or on the
|
// changes...
|
||||||
// horizontal connection between the previous
|
(py !== yStart || winding !== prevWinding)
|
||||||
// curve and the current curve
|
// ...and the point is not on the curve or on
|
||||||
} else if ((py != yStart || winding !== prevWinding)
|
// the horizontal connection between the last
|
||||||
&& !isOnHorizontal) {
|
// non-horizontal curve's end point and the
|
||||||
|
// current curve's start point.
|
||||||
|
&& !(py === yStart
|
||||||
|
&& (px - x) * (px - prevXEnd) < 0)) {
|
||||||
if (x < xBefore) {
|
if (x < xBefore) {
|
||||||
windLeft += winding;
|
windLeft += winding;
|
||||||
} else if (x > xAfter) {
|
} else if (x > xAfter) {
|
||||||
|
@ -415,8 +413,8 @@ PathItem.inject(new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the point was on a monocurve, we are on the path by definition.
|
// If the point was on a monotonic curve, we are on the path by
|
||||||
// In this case ensure that the winding is at least 1.
|
// definition. In this case ensure that the winding is at least 1.
|
||||||
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