mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Remove the need to store winding samples in array and sort.
Calculating the average winding value instead yields the same results.
This commit is contained in:
parent
26f209c835
commit
51ec3325e3
1 changed files with 7 additions and 8 deletions
|
@ -62,7 +62,6 @@ PathItem.inject(new function() {
|
||||||
splitPath(_path1.getIntersections(_path2, null, true));
|
splitPath(_path1.getIntersections(_path2, null, true));
|
||||||
|
|
||||||
var chain = [],
|
var chain = [],
|
||||||
windings = [],
|
|
||||||
segments = [],
|
segments = [],
|
||||||
// Aggregate of all curves in both operands, monotonic in y
|
// Aggregate of all curves in both operands, monotonic in y
|
||||||
monoCurves = [],
|
monoCurves = [],
|
||||||
|
@ -98,15 +97,16 @@ PathItem.inject(new function() {
|
||||||
// intersection or end of a curve chain.
|
// intersection or end of a curve chain.
|
||||||
chain.length = 0;
|
chain.length = 0;
|
||||||
var startSeg = segment,
|
var startSeg = segment,
|
||||||
totalLength = 0;
|
totalLength = 0,
|
||||||
|
windingSum = 0;
|
||||||
do {
|
do {
|
||||||
var length = segment.getCurve().getLength();
|
var length = segment.getCurve().getLength();
|
||||||
chain.push({ segment: segment, length: length });
|
chain.push({ segment: segment, length: length });
|
||||||
totalLength += length;
|
totalLength += length;
|
||||||
segment = segment.getNext();
|
segment = segment.getNext();
|
||||||
} while (segment && !segment._intersection && segment !== startSeg);
|
} while (segment && !segment._intersection && segment !== startSeg);
|
||||||
// Select the median winding of three evenly distributed points
|
// Calculate the average winding among three evenly distributed
|
||||||
// along this curve chain, as a representative winding number.
|
// points along this curve chain as a representative winding number.
|
||||||
// This selection gives a better chance of returning a correct
|
// This selection gives a better chance of returning a correct
|
||||||
// winding than equally dividing the curve chain, with the same
|
// winding than equally dividing the curve chain, with the same
|
||||||
// (amortised) time.
|
// (amortised) time.
|
||||||
|
@ -131,7 +131,7 @@ PathItem.inject(new function() {
|
||||||
// While subtracting, we need to omit this curve if this
|
// While subtracting, we need to omit this curve if this
|
||||||
// curve is contributing to the second operand and is
|
// curve is contributing to the second operand and is
|
||||||
// outside the first operand.
|
// outside the first operand.
|
||||||
windings[j] = subtract && _path2
|
windingSum += subtract && _path2
|
||||||
&& (path === _path1 && _path2._getWinding(pt, hor)
|
&& (path === _path1 && _path2._getWinding(pt, hor)
|
||||||
|| path === _path2 && !_path1._getWinding(pt, hor))
|
|| path === _path2 && !_path1._getWinding(pt, hor))
|
||||||
? 0
|
? 0
|
||||||
|
@ -141,9 +141,8 @@ PathItem.inject(new function() {
|
||||||
length -= curveLength;
|
length -= curveLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
windings.sort();
|
// Assign the average winding to the entire curve chain.
|
||||||
// Assign the median winding to the entire curve chain.
|
var winding = Math.round(windingSum / 3);
|
||||||
var winding = windings[1];
|
|
||||||
for (var j = chain.length - 1; j >= 0; j--)
|
for (var j = chain.length - 1; j >= 0; j--)
|
||||||
chain[j].segment._winding = winding;
|
chain[j].segment._winding = winding;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue