Skip to content

Commit b79e2cf

Browse files
author
Cosimo Lupo
committed
[flatten] record position of contour's starting point and restore if possible
1 parent 9523a83 commit b79e2cf

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Lib/booleanOperations/flatten.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class ContourPointDataPen:
306306

307307
def __init__(self):
308308
self._points = None
309+
self._foundStartingPoint = False
309310

310311
def getData(self):
311312
"""
@@ -343,6 +344,8 @@ def endPath(self):
343344

344345
def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs):
345346
assert segmentType != "move"
347+
if not self._foundStartingPoint and segmentType is not None:
348+
kwargs['startingPoint'] = self._foundStartingPoint = True
346349
data = InputPoint(
347350
coordinates=pt,
348351
segmentType=segmentType,
@@ -970,11 +973,16 @@ def drawPoints(self, pointPen):
970973
points.extend(segment.points)
971974

972975
hasOnCurve = False
973-
for point in points:
976+
foundOriginalStartingPoint = False
977+
for index, point in enumerate(points):
974978
if point.segmentType is not None:
975979
hasOnCurve = True
976-
break
977-
if hasOnCurve:
980+
if point.kwargs is not None and point.kwargs.get("startingPoint"):
981+
foundOriginalStartingPoint = True
982+
break
983+
if foundOriginalStartingPoint:
984+
points = points[index:] + points[:index]
985+
elif hasOnCurve:
978986
while points[0].segmentType is None:
979987
p = points.pop(0)
980988
points.append(p)

0 commit comments

Comments
 (0)