Do not start with segments with multiple intersections.

Simplifies the required checks at the end, and generally reduces number edge cases.
This commit is contained in:
Jürg Lehni 2015-10-08 23:38:41 +02:00
parent c9eba83cc7
commit 5129fb0050

View file

@ -673,22 +673,13 @@ PathItem.inject(new function() {
return null; return null;
} }
function findStartSegment(inter, next) {
while (inter) {
var seg = inter._segment;
if (isStart(seg))
return seg;
inter = inter[next ? '_next' : '_prev'];
}
}
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; finished = false;
// Do not start a chain with already visited segments, and segments // Do not start a chain with segments that have multiple
// that are not going to be part of the resulting operation. // intersections or invalid segments.
if (!isValid(seg)) if (seg._intersection && seg._intersection._next || !isValid(seg))
continue; continue;
start = otherStart = null; start = otherStart = null;
while (!finished) { while (!finished) {
@ -753,17 +744,7 @@ PathItem.inject(new function() {
if (isStart(seg)) { if (isStart(seg)) {
drawSegment(seg, null, 'done', i, 'red'); drawSegment(seg, null, 'done', i, 'red');
finished = true; finished = true;
} else if (inter) { } else {
var found = findStartSegment(inter, true)
|| findStartSegment(inter, false);
if (found) {
seg = found;
drawSegment(seg, null, 'done multiple', i, 'red');
finished = true;
break;
}
}
if (!finished) {
// 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 #'
+ pathCount + '.' + pathCount + '.'