From a1c62cfa30b88dcf2897320707a4f41cf13fe38c Mon Sep 17 00:00:00 2001 From: Skef Iterum Date: Sun, 23 Oct 2022 23:23:11 -0700 Subject: [PATCH 1/2] Correct for (rare) bad tracking of previousIntersectionPoint --- Lib/booleanOperations/flatten.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Lib/booleanOperations/flatten.py b/Lib/booleanOperations/flatten.py index 8f1d7e1..67d200b 100644 --- a/Lib/booleanOperations/flatten.py +++ b/Lib/booleanOperations/flatten.py @@ -255,6 +255,29 @@ def tValueForPoint(self, point): else: raise NotImplementedError + def tValueToPoint(self, t): + if self.segmentType == "curve": + on1 = self.previousOnCurve + off1 = self.points[0].coordinates + off2 = self.points[1].coordinates + on2 = self.points[2].coordinates + return _getCubicPoint(t, on1, off1, off2, on2) + elif self.segmentType == "line": + return _getLinePoint(t, self.previousOnCurve, self.points[0].coordinates) + elif self.segmentType == "qcurve": + raise NotImplementedError + else: + raise NotImplementedError + + def hasPoint(self, p): + if p is None: + return False + for t in self.tValueForPoint(p): + pp = self.tValueToPoint(t) + if _distance(p, pp) < _approximateSegmentLength/100: + return True + return False + class InputPoint: @@ -803,6 +826,13 @@ def reCurveSubSegments(self, inputContours): continue tValues = None lastPointWithAttributes = None + # Occasionally our logic about the previous intersection + # point can drift out of sync with the current segment. + # So check here if it is on the current segment and if + # not set it to None + if not inputSegment.hasPoint(previousIntersectionPoint): + previousIntersectionPoint = None + if flatSegment[0] == inputSegment.flat[0] and flatSegment[-1] != inputSegment.flat[-1]: # needed the first part of the segment # if previousIntersectionPoint is None: From 88e2afbf97836b9fe55cc588f874de133da028a6 Mon Sep 17 00:00:00 2001 From: Skef Iterum Date: Sun, 23 Oct 2022 23:57:11 -0700 Subject: [PATCH 2/2] Add missing function --- Lib/booleanOperations/flatten.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/booleanOperations/flatten.py b/Lib/booleanOperations/flatten.py index 67d200b..83e6009 100644 --- a/Lib/booleanOperations/flatten.py +++ b/Lib/booleanOperations/flatten.py @@ -1154,6 +1154,12 @@ def _mid(pt1, pt2): (x0, y0), (x1, y1) = pt1, pt2 return 0.5 * (x0 + x1), 0.5 * (y0 + y1) +def _getLinePoint(t, pt0, pt1): + if t == 0: + return pt0 + if t == 1: + return pt1 + return pt0[0] + (pt1[0]-pt0[0]) * t, pt0[1] + (pt1[1]-pt0[1]) * t def _getCubicPoint(t, pt0, pt1, pt2, pt3): if t == 0: