Boolean: handle linear segments correctly.

Earlier implementation was unfinished and did not reset some handles to
linear, this caused the winding to be miscalculated.
This commit is contained in:
hkrish 2014-05-05 18:46:39 +02:00
parent 10c5b389c7
commit 1c9d1de380

View file

@ -164,17 +164,14 @@ PathItem.inject(new function() {
*/ */
function splitPath(intersections) { function splitPath(intersections) {
var TOLERANCE = /*#=*/ Numerical.TOLERANCE, var TOLERANCE = /*#=*/ Numerical.TOLERANCE,
linearSegments; linearHandles;
function resetLinear() { function resetLinear() {
// Reset linear segments if they were part of a linear curve // Reset linear segments if they were part of a linear curve
// and if we are done with the entire curve. // and if we are done with the entire curve.
for (var i = 0, l = linearSegments.length; i < l; i++) { for (var i = 0, l = linearHandles.length; i < l; i++) {
var segment = linearSegments[i]; var handle = linearHandles[i];
// FIXME: Don't reset the appropriate handle if the intersection handle.set(0, 0);
// was on t == 0 && t == 1.
segment._handleOut.set(0, 0);
segment._handleIn.set(0, 0);
} }
} }
@ -188,10 +185,14 @@ PathItem.inject(new function() {
// Scale parameter after previous split. // Scale parameter after previous split.
t /= prevLoc._parameter; t /= prevLoc._parameter;
} else { } else {
if (linearSegments) if (linearHandles)
resetLinear(); resetLinear();
curve = loc._curve; curve = loc._curve;
linearSegments = curve.isLinear() && []; linearHandles = curve.isLinear() && [];
if (linearHandles) {
linearHandles.push(curve._segment1._handleOut);
linearHandles.push(curve._segment2._handleIn);
}
} }
var newCurve, var newCurve,
segment; segment;
@ -199,6 +200,10 @@ PathItem.inject(new function() {
if (newCurve = curve.divide(t, true, true)) { if (newCurve = curve.divide(t, true, true)) {
segment = newCurve._segment1; segment = newCurve._segment1;
curve = newCurve.getPrevious(); curve = newCurve.getPrevious();
if (linearHandles) {
linearHandles.push(segment._handleOut);
linearHandles.push(segment._handleIn);
}
} else { } else {
segment = t < TOLERANCE segment = t < TOLERANCE
? curve._segment1 ? curve._segment1
@ -211,11 +216,9 @@ PathItem.inject(new function() {
// Link the new segment with the intersection on the other curve // Link the new segment with the intersection on the other curve
segment._intersection = loc.getIntersection(); segment._intersection = loc.getIntersection();
loc._segment = segment; loc._segment = segment;
if (linearSegments)
linearSegments.push(segment);
prevLoc = loc; prevLoc = loc;
} }
if (linearSegments) if (linearHandles)
resetLinear(); resetLinear();
} }