Revert "Never starting in intersections allows for further code simplifications."

This reverts commit 892154e8f8.
This commit is contained in:
Jürg Lehni 2015-10-09 10:18:45 +02:00
parent 892154e8f8
commit c45ae4b51a

View file

@ -566,6 +566,7 @@ PathItem.inject(new function() {
var paths = [], var paths = [],
start, start,
otherStart,
operator = operators[operation], operator = operators[operation],
// Adjust winding contributions for specific operations on overlaps: // Adjust winding contributions for specific operations on overlaps:
overlapWinding = { overlapWinding = {
@ -585,6 +586,10 @@ PathItem.inject(new function() {
return operator(winding); return operator(winding);
} }
function isStart(seg) {
return seg === start || seg === otherStart;
}
/** /**
* Checks if the curve from seg1 to seg2 is part of an overlap. * Checks if the curve from seg1 to seg2 is part of an overlap.
*/ */
@ -616,7 +621,7 @@ PathItem.inject(new function() {
+ nextSeg._index + nextSeg._index
+ ', seg vis:' + !!seg._visited + ', seg vis:' + !!seg._visited
+ ', next vis:' + !!nextSeg._visited + ', next vis:' + !!nextSeg._visited
+ ', next start:' + (nextSeg === start) + ', next start:' + isStart(nextSeg)
+ ', seg wi:' + seg._winding + ', seg wi:' + seg._winding
+ ', next wi:' + nextSeg._winding + ', next wi:' + nextSeg._winding
+ ', seg op:' + isValid(seg, true) + ', seg op:' + isValid(seg, true)
@ -643,7 +648,7 @@ PathItem.inject(new function() {
// result, the non-strict mode is used, in which invalid current // result, the non-strict mode is used, in which invalid current
// segments are tolerated, and overlaps for the next segment are // segments are tolerated, and overlaps for the next segment are
// allowed as long as they are valid when not adjusted. // allowed as long as they are valid when not adjusted.
if (nextSeg === start if (isStart(nextSeg)
|| !seg._visited && !nextSeg._visited || !seg._visited && !nextSeg._visited
// Self-intersections (!operator) don't need isValid() calls // Self-intersections (!operator) don't need isValid() calls
&& (!operator && (!operator
@ -670,13 +675,14 @@ PathItem.inject(new function() {
for (var i = 0, l = segments.length; i < l; i++) { for (var i = 0, l = segments.length; i < l; i++) {
var seg = segments[i], var seg = segments[i],
path = null; path = null,
finished = false;
// Do not start a chain with segments that have intersections, // Do not start a chain with segments that have intersections,
// segments that are already visited, or that are invalid. // segments that are already visited, or that are invalid.
if (seg._intersection || !isValid(seg)) if (seg._intersection || !isValid(seg))
continue; continue;
start = null; start = otherStart = null;
while (seg !== start) { while (!finished) {
var inter = seg._intersection; var inter = seg._intersection;
// Once we started a chain, see if there are multiple // Once we started a chain, see if there are multiple
// intersections, and if so, pick the best one: // intersections, and if so, pick the best one:
@ -735,8 +741,9 @@ PathItem.inject(new function() {
drawSegment(seg, null, 'stay', i, 'blue'); drawSegment(seg, null, 'stay', i, 'blue');
} }
if (seg._visited) { if (seg._visited) {
if (seg === start) { if (isStart(seg)) {
drawSegment(seg, null, 'done', i, 'red'); drawSegment(seg, null, 'done', i, 'red');
finished = true;
} else { } else {
// We didn't manage to switch, so stop right here. // We didn't manage to switch, so stop right here.
console.error('Visited segment encountered, aborting #' console.error('Visited segment encountered, aborting #'
@ -750,21 +757,23 @@ PathItem.inject(new function() {
if (!path) { if (!path) {
path = new Path(Item.NO_INSERT); path = new Path(Item.NO_INSERT);
start = seg; start = seg;
otherStart = other;
} }
// Add the current segment to the path, and mark the added // Add the current segment to the path, and mark the added
// segment as visited. // segment as visited.
path.add(new Segment(seg._point, handleIn, seg._handleOut)); path.add(new Segment(seg._point, handleIn, seg._handleOut));
seg._visited = true; seg._visited = true;
seg = seg.getNext(); seg = seg.getNext();
if (seg === start) { if (isStart(seg)) {
drawSegment(seg, null, 'done', i, 'red'); drawSegment(seg, null, 'done', i, 'red');
finished = true;
} }
} }
if (!path) if (!path)
continue; continue;
// Finish with closing the paths if necessary, correctly linking up // Finish with closing the paths if necessary, correctly linking up
// curves etc. // curves etc.
if (seg === start) { if (finished) {
path.firstSegment.setHandleIn(seg._handleIn); path.firstSegment.setHandleIn(seg._handleIn);
path.setClosed(true); path.setClosed(true);
if (window.reportSegments) { if (window.reportSegments) {