mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Merge pull request #938 from iconexperience/getWinding-simplification
Simplify getWindings() by using only the 'last' property to understand when a new loop starts.
This commit is contained in:
commit
53269ab169
1 changed files with 55 additions and 61 deletions
|
@ -348,27 +348,24 @@ PathItem.inject(new function() {
|
|||
} else {
|
||||
var xBefore = px - epsilon,
|
||||
xAfter = px + epsilon,
|
||||
start,
|
||||
end = 0;
|
||||
while (end < length) {
|
||||
start = end;
|
||||
// The first curve of a loop holds information about its length
|
||||
// and the last curve with non-zero winding.
|
||||
// Retrieve and use it here (See _getMonoCurve()).
|
||||
var curve = curves[start],
|
||||
last = curve.last,
|
||||
// Get the values of to the end x coordinate and winding of
|
||||
// the last non-horizontal curve, which will be the previous
|
||||
// non-horizontal curve for the first curve of the loop.
|
||||
prevWinding = last.winding,
|
||||
prevXEnd = last.values[6];
|
||||
end = start + curve.length;
|
||||
for (var i = start; i < end; i++) {
|
||||
prevWinding,
|
||||
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()).
|
||||
if (curve.last) {
|
||||
// Get the values of to the end x coordinate and winding of
|
||||
// the last non-horizontal curve, which will be the previous
|
||||
// non-horizontal curve for the first curve of the loop.
|
||||
prevWinding = curve.last.winding;
|
||||
prevXEnd = curve.last.values[6];
|
||||
}
|
||||
// Since the curves are monotone in y direction, we can just
|
||||
// compare the endpoints of the curve to determine if the
|
||||
// ray from query point along +-x direction will intersect
|
||||
|
@ -413,7 +410,6 @@ PathItem.inject(new function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Math.max(abs(windLeft), abs(windRight));
|
||||
}
|
||||
|
||||
|
@ -976,11 +972,9 @@ Path.inject(/** @lends Path# */{
|
|||
handleCurve([p1x, p1y, p1x, p1y, p2x, p2y, p2x, p2y]);
|
||||
}
|
||||
if (monoCurves.length > 0) {
|
||||
// Add information about the loop length and the last curve with
|
||||
// non-zero winding, as required in getWinding().
|
||||
var first = monoCurves[0];
|
||||
first.length = monoCurves.length;
|
||||
first.last = last;
|
||||
// Add information about the last curve with non-zero winding,
|
||||
// as required in getWinding().
|
||||
monoCurves[0].last = last;
|
||||
}
|
||||
}
|
||||
return monoCurves;
|
||||
|
|
Loading…
Reference in a new issue