mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
More simplifications in PathItem._getWinding()
This commit is contained in:
parent
a2941472b5
commit
de6650a6ca
1 changed files with 23 additions and 24 deletions
|
@ -388,31 +388,30 @@ statics: {
|
||||||
windLeft = _getWinding(new Point(x, yTop), curves);
|
windLeft = _getWinding(new Point(x, yTop), curves);
|
||||||
if (yBottom < Infinity)
|
if (yBottom < Infinity)
|
||||||
windRight = _getWinding(new Point(x, yBottom), curves);
|
windRight = _getWinding(new Point(x, yBottom), curves);
|
||||||
return Math.max(windLeft, windRight);
|
} else {
|
||||||
}
|
// Find the winding number for right side of the curve, inclusive of
|
||||||
// Find the winding number for right hand side of the curve,
|
// the curve itself, while tracing along its +-x direction.
|
||||||
// inclusive of the curve itself, while tracing along its ±x direction.
|
for (var i = 0, l = curves.length; i < l; i++) {
|
||||||
for (var i = 0, l = curves.length; i < l; i++) {
|
var v = curves[i];
|
||||||
var v = curves[i];
|
if (Curve.solveCubic(v, 1, y, roots, 0, 1 - tolerance) === 1) {
|
||||||
if (Curve.solveCubic(v, 1, y, roots, 0, 1 - tolerance) === 1) {
|
var t = roots[0],
|
||||||
var t = roots[0],
|
x0 = Curve.evaluate(v, t, 0).x,
|
||||||
x0 = Curve.evaluate(v, t, 0).x,
|
slope = Curve.evaluate(v, t, 1).y;
|
||||||
slope = Curve.evaluate(v, t, 1).y,
|
// Take care of cases where the curve and the preceeding
|
||||||
stationary = abs(slope) < tolerance && !Curve.isLinear(v)
|
// curve merely touches the ray towards +-x direction, but
|
||||||
// Take care of cases where the curve and the
|
// proceeds to the same side of the ray. This essentially is
|
||||||
// preceeding curve merely touches the ray towards
|
// not a crossing.
|
||||||
// +-x direction, but proceeds to the same side of
|
// NOTE: The previous curve is stored at v[9], see
|
||||||
// the ray. This essentially is not a crossing.
|
// Path#_getMonoCurves() for details.
|
||||||
// NOTE: The previous curve is stored at v[9],
|
if (abs(slope) < tolerance && !Curve.isLinear(v)
|
||||||
// see Path#_getMonoCurves() for details.
|
|
||||||
|| t < tolerance
|
|| t < tolerance
|
||||||
&& slope * Curve.evaluate(v[9], t, 1).y < 0;
|
&& slope * Curve.evaluate(v[9], t, 1).y < 0) {
|
||||||
if (!stationary) {
|
// TODO: Handle stationary points here!
|
||||||
var winding = v[8];
|
} else if (x0 <= xBefore) {
|
||||||
if (x0 <= xBefore)
|
windLeft += v[8];
|
||||||
windLeft += winding;
|
} else if (x0 >= xAfter) {
|
||||||
if (x0 >= xAfter)
|
windRight += v[8];
|
||||||
windRight += winding;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue