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;
}
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++) {
var seg = segments[i],
path = null,
finished = false;
// Do not start a chain with already visited segments, and segments
// that are not going to be part of the resulting operation.
if (!isValid(seg))
// Do not start a chain with segments that have multiple
// intersections or invalid segments.
if (seg._intersection && seg._intersection._next || !isValid(seg))
continue;
start = otherStart = null;
while (!finished) {
@ -753,17 +744,7 @@ PathItem.inject(new function() {
if (isStart(seg)) {
drawSegment(seg, null, 'done', i, 'red');
finished = true;
} else if (inter) {
var found = findStartSegment(inter, true)
|| findStartSegment(inter, false);
if (found) {
seg = found;
drawSegment(seg, null, 'done multiple', i, 'red');
finished = true;
break;
}
}
if (!finished) {
} else {
// We didn't manage to switch, so stop right here.
console.error('Visited segment encountered, aborting #'
+ pathCount + '.'