From 741293909666b1a11232f85e416444b359d231d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 4 Oct 2017 21:43:56 +0200 Subject: [PATCH] Boolean: Add better filtering for invalid segments Fixes #1385 --- src/path/PathItem.Boolean.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index fe36bc89..c78d6b9d 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -825,21 +825,25 @@ PathItem.inject(new function() { function collect(inter, end) { while (inter && inter !== end) { var other = inter._segment, - path = other._path, - next = other.getNext() || path && path.getFirstSegment(), - nextInter = next && next._intersection; - // See if this segment and the next are both not visited - // yet, or are bringing us back to the beginning, and are - // both valid, meaning they are part of the boolean result. - if (other !== segment && (isStart(other) || isStart(next) - || next && (isValid(other) && (isValid(next) - // If the next segment isn't valid, its intersection - // to which we may switch might be, so check that. - || nextInter && isValid(nextInter._segment))))) { - crossings.push(other); + path = other && other._path; + if (path) { + var next = other.getNext() || path.getFirstSegment(), + nextInter = next._intersection; + // See if this segment and the next are not visited yet, + // or are bringing us back to the start, and are both + // valid, meaning they're part of the boolean result. + if (other !== segment && (isStart(other) + || isStart(next) + || next && (isValid(other) && (isValid(next) + // If next segment isn't valid, its intersection + // 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; } } @@ -970,7 +974,8 @@ PathItem.inject(new function() { // the list of crossings when the branch is created above. do { seg = branch && branch.crossings.shift(); - if (!seg) { + if (!seg || !seg._path) { + seg = null; // If there are no segments left, try previous // branches until we find one that works. branch = branches.pop();