mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Switch to sampling only one location for winding contribution.
Closes #1073
This commit is contained in:
parent
4c94553b81
commit
34c35e26bd
1 changed files with 29 additions and 35 deletions
|
@ -438,7 +438,7 @@ PathItem.inject(new function() {
|
||||||
var chain = [],
|
var chain = [],
|
||||||
start = segment,
|
start = segment,
|
||||||
totalLength = 0,
|
totalLength = 0,
|
||||||
windingSum = 0;
|
winding = 0;
|
||||||
do {
|
do {
|
||||||
var curve = segment.getCurve(),
|
var curve = segment.getCurve(),
|
||||||
length = curve.getLength();
|
length = curve.getLength();
|
||||||
|
@ -446,43 +446,37 @@ PathItem.inject(new function() {
|
||||||
totalLength += length;
|
totalLength += length;
|
||||||
segment = segment.getNext();
|
segment = segment.getNext();
|
||||||
} while (segment && !segment._intersection && segment !== start);
|
} while (segment && !segment._intersection && segment !== start);
|
||||||
// Calculate the average winding among three evenly distributed points
|
// Sample the point at a middle of the chain to get its winding:
|
||||||
// along this curve chain as a representative winding number.
|
var length = totalLength / 2;
|
||||||
for (var i = 0; i < 3; i++) {
|
for (var j = 0, l = chain.length; j < l; j++) {
|
||||||
// Sample the points at 3 equal intervals along the total length:
|
var entry = chain[j],
|
||||||
var length = totalLength * (i + 1) / 4;
|
curveLength = entry.length;
|
||||||
for (var j = 0, l = chain.length; j < l; j++) {
|
if (length <= curveLength) {
|
||||||
var entry = chain[j],
|
var curve = entry.curve,
|
||||||
curveLength = entry.length;
|
path = curve._path,
|
||||||
if (length <= curveLength) {
|
parent = path._parent,
|
||||||
var curve = entry.curve,
|
t = curve.getTimeAt(length),
|
||||||
path = curve._path,
|
pt = curve.getPointAtTime(t),
|
||||||
parent = path._parent,
|
hor = Math.abs(curve.getTangentAtTime(t).y)
|
||||||
t = curve.getTimeAt(length),
|
< /*#=*/Numerical.TRIGONOMETRIC_EPSILON;
|
||||||
pt = curve.getPointAtTime(t),
|
if (parent instanceof CompoundPath)
|
||||||
hor = Math.abs(curve.getTangentAtTime(t).y)
|
path = parent;
|
||||||
< /*#=*/Numerical.TRIGONOMETRIC_EPSILON;
|
// While subtracting, we need to omit this curve if it is
|
||||||
if (parent instanceof CompoundPath)
|
// contributing to the second operand and is outside the
|
||||||
path = parent;
|
// first operand.
|
||||||
// While subtracting, we need to omit this curve if it is
|
winding = !(operator.subtract && path2 && (
|
||||||
// contributing to the second operand and is outside the
|
path === path1 && path2._getWinding(pt, operator, hor) ||
|
||||||
// first operand.
|
path === path2 && !path1._getWinding(pt, operator, hor)))
|
||||||
if (!(operator.subtract && path2
|
? getWinding(pt, monoCurves, operator, hor)
|
||||||
&& (path === path1
|
: 0;
|
||||||
&& path2._getWinding(pt, operator, hor)
|
break;
|
||||||
|| path === path2
|
|
||||||
&& !path1._getWinding(pt, operator, hor)))) {
|
|
||||||
windingSum += getWinding(pt, monoCurves, operator, hor);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
length -= curveLength;
|
|
||||||
}
|
}
|
||||||
|
length -= curveLength;
|
||||||
}
|
}
|
||||||
// Assign the average winding to the entire curve chain.
|
// Now assign the winding to the entire curve chain.
|
||||||
var winding = Math.round(windingSum / 3);
|
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