Skip to content

Commit a1c62cf

Browse files
committed
Correct for (rare) bad tracking of previousIntersectionPoint
1 parent 25f7091 commit a1c62cf

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Lib/booleanOperations/flatten.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,29 @@ def tValueForPoint(self, point):
255255
else:
256256
raise NotImplementedError
257257

258+
def tValueToPoint(self, t):
259+
if self.segmentType == "curve":
260+
on1 = self.previousOnCurve
261+
off1 = self.points[0].coordinates
262+
off2 = self.points[1].coordinates
263+
on2 = self.points[2].coordinates
264+
return _getCubicPoint(t, on1, off1, off2, on2)
265+
elif self.segmentType == "line":
266+
return _getLinePoint(t, self.previousOnCurve, self.points[0].coordinates)
267+
elif self.segmentType == "qcurve":
268+
raise NotImplementedError
269+
else:
270+
raise NotImplementedError
271+
272+
def hasPoint(self, p):
273+
if p is None:
274+
return False
275+
for t in self.tValueForPoint(p):
276+
pp = self.tValueToPoint(t)
277+
if _distance(p, pp) < _approximateSegmentLength/100:
278+
return True
279+
return False
280+
258281

259282
class InputPoint:
260283

@@ -803,6 +826,13 @@ def reCurveSubSegments(self, inputContours):
803826
continue
804827
tValues = None
805828
lastPointWithAttributes = None
829+
# Occasionally our logic about the previous intersection
830+
# point can drift out of sync with the current segment.
831+
# So check here if it is on the current segment and if
832+
# not set it to None
833+
if not inputSegment.hasPoint(previousIntersectionPoint):
834+
previousIntersectionPoint = None
835+
806836
if flatSegment[0] == inputSegment.flat[0] and flatSegment[-1] != inputSegment.flat[-1]:
807837
# needed the first part of the segment
808838
# if previousIntersectionPoint is None:

0 commit comments

Comments
 (0)