Switch to sampling only one location for winding contribution.

Closes #1073
This commit is contained in:
Jürg Lehni 2016-06-13 11:26:02 +02:00
parent 4c94553b81
commit 34c35e26bd

View file

@ -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,11 +446,8 @@ 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++) {
// Sample the points at 3 equal intervals along the total length:
var length = totalLength * (i + 1) / 4;
for (var j = 0, l = chain.length; j < l; j++) { for (var j = 0, l = chain.length; j < l; j++) {
var entry = chain[j], var entry = chain[j],
curveLength = entry.length; curveLength = entry.length;
@ -467,23 +464,20 @@ PathItem.inject(new function() {
// While subtracting, we need to omit this curve if it is // While subtracting, we need to omit this curve if it is
// contributing to the second operand and is outside the // contributing to the second operand and is outside the
// first operand. // first operand.
if (!(operator.subtract && path2 winding = !(operator.subtract && path2 && (
&& (path === path1 path === path1 && path2._getWinding(pt, operator, hor) ||
&& path2._getWinding(pt, operator, hor) path === path2 && !path1._getWinding(pt, operator, hor)))
|| path === path2 ? getWinding(pt, monoCurves, operator, hor)
&& !path1._getWinding(pt, operator, hor)))) { : 0;
windingSum += getWinding(pt, monoCurves, operator, hor);
}
break; break;
} }
length -= curveLength; length -= curveLength;
} }
} // Now assign the winding to the entire curve chain.
// Assign the average winding to the entire curve chain. for (var j = chain.length - 1; j >= 0; j--) {
var winding = Math.round(windingSum / 3);
for (var j = chain.length - 1; j >= 0; j--)
chain[j].segment._winding = winding; chain[j].segment._winding = winding;
} }
}
/** /**
* Private method to trace closed paths from a list of segments, according * Private method to trace closed paths from a list of segments, according