Make findBestIntersection() more strict and improve comments.

This commit is contained in:
Jürg Lehni 2016-06-13 12:08:44 +02:00
parent 94853669f6
commit af5a5b5f2d

View file

@ -523,21 +523,18 @@ PathItem.inject(new function() {
nextSeg = seg.getNext(), nextSeg = seg.getNext(),
nextInter = nextSeg._intersection; nextInter = nextSeg._intersection;
// See if this segment and the next are both not visited yet, or // See if this segment and the next are both not visited yet, or
// are bringing us back to the beginning, and are both part of // are bringing us back to the beginning, and are both valid,
// the boolean result. // meaning they are part of the boolean result.
// Handling overlaps correctly here is tricky, requiring two // Handling overlaps correctly requires two passes, first with
// passes, first with strict = true, then false: // strict set to true, then false:
// In strict mode, the current and the next segment are both // In strict mode, the next segment is not allowed to be an
// checked for validity, and only the current one is allowed to // overlap. In non-strict mode, the next segment may be invalid
// be an overlap. // if it offers a switch to a valid segment.
// If this pass does not yield a result, the non-strict mode is
// used, in which invalid current segments are tolerated, and
// overlaps for the next segment are allowed.
if (seg !== exclude && (isStart(seg) || isStart(nextSeg) if (seg !== exclude && (isStart(seg) || 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
|| (!strict || isValid(seg)) || isValid(seg)
// Do not consider nextSeg in strict mode if it is part // Do not consider nextSeg in strict mode if it is part
// of an overlap, in order to give non-overlapping // of an overlap, in order to give non-overlapping
// options that might follow the priority over overlaps. // options that might follow the priority over overlaps.