Boolean: Add better filtering for invalid segments

Fixes #1385
This commit is contained in:
Jürg Lehni 2017-10-04 21:43:56 +02:00
parent 10f464edfc
commit 7412939096

View file

@ -825,21 +825,25 @@ PathItem.inject(new function() {
function collect(inter, end) { function collect(inter, end) {
while (inter && inter !== end) { while (inter && inter !== end) {
var other = inter._segment, var other = inter._segment,
path = other._path, path = other && other._path;
next = other.getNext() || path && path.getFirstSegment(), if (path) {
nextInter = next && next._intersection; var next = other.getNext() || path.getFirstSegment(),
// See if this segment and the next are both not visited nextInter = next._intersection;
// yet, or are bringing us back to the beginning, and are // See if this segment and the next are not visited yet,
// both valid, meaning they are part of the boolean result. // or are bringing us back to the start, and are both
if (other !== segment && (isStart(other) || isStart(next) // valid, meaning they're part of the boolean result.
|| next && (isValid(other) && (isValid(next) if (other !== segment && (isStart(other)
// If the next segment isn't valid, its intersection || isStart(next)
// to which we may switch might be, so check that. || next && (isValid(other) && (isValid(next)
|| nextInter && isValid(nextInter._segment))))) { // If next segment isn't valid, its intersection
crossings.push(other); // to which we may switch may be, so check that.
|| nextInter && isValid(nextInter._segment))))
) {
crossings.push(other);
}
if (collectStarts)
starts.push(other);
} }
if (collectStarts)
starts.push(other);
inter = inter._next; inter = inter._next;
} }
} }
@ -970,7 +974,8 @@ PathItem.inject(new function() {
// the list of crossings when the branch is created above. // the list of crossings when the branch is created above.
do { do {
seg = branch && branch.crossings.shift(); seg = branch && branch.crossings.shift();
if (!seg) { if (!seg || !seg._path) {
seg = null;
// If there are no segments left, try previous // If there are no segments left, try previous
// branches until we find one that works. // branches until we find one that works.
branch = branches.pop(); branch = branches.pop();