Skip to content

Commit 7482ba0

Browse files
author
Cosimo Lupo
committed
[flatten] if > 1 starting points, use closest to origin
When merging two or more contours, there could be more than one possible original starting points to be restored. Here we choose the one that is closest to the origin.
1 parent b79e2cf commit 7482ba0

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Lib/booleanOperations/flatten.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -973,15 +973,17 @@ def drawPoints(self, pointPen):
973973
points.extend(segment.points)
974974

975975
hasOnCurve = False
976-
foundOriginalStartingPoint = False
976+
originalStartingPoints = []
977977
for index, point in enumerate(points):
978978
if point.segmentType is not None:
979979
hasOnCurve = True
980980
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]
981+
distanceFromOrigin = math.hypot(*point)
982+
originalStartingPoints.append((distanceFromOrigin, index))
983+
if originalStartingPoints:
984+
# use the original starting point that is closest to the origin
985+
startingPointIndex = sorted(originalStartingPoints)[0][1]
986+
points = points[startingPointIndex:] + points[:startingPointIndex]
985987
elif hasOnCurve:
986988
while points[0].segmentType is None:
987989
p = points.pop(0)

0 commit comments

Comments
 (0)