Skip to content

Commit 71124f2

Browse files
committed
Correct mistaken impressions about merging
1 parent 2ca61b6 commit 71124f2

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

Lib/booleanOperations/flatten.py

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -692,50 +692,36 @@ def reCurveSubSegments(self, inputContours):
692692
fp = segmentedFlatPoints[0][0]
693693
lp = segmentedFlatPoints[-1][-1]
694694
mergeFirstSegments = False
695-
duplicatePoint = 0
696695
if fp in flatInputPoints and lp in flatInputPoints:
697696
# fp and lp are "known" points with associated input
698-
# segments. If they're on the same segment, merge
699-
# them.
700-
# Otherwise, if the opposite segment is curved we
701-
# need to duplicate the point so that we have
702-
# the full curve when processing that segment.
703-
# However, there is an exception case: If the
704-
# inputSegment type is "curved" but it was encoded
705-
# for pyClipper as a line anyway, do nothing.
697+
# segments and fp is an isolated point in
698+
# segmentedFlatPoints[0]. If both points are
699+
# associated with the same input segment or if one
700+
# is the previous on-curve point for the other
701+
# segment (and the two are oriented correctly)
702+
# we want to merge the first and last segments.
706703
firstInputSegment = flatInputPointsSegmentDict[fp]
707704
lastInputSegment = flatInputPointsSegmentDict[lp]
708705
reversedFirstInputSegment = reversedFlatInputPointsSegmentDict[fp]
709706
reversedLastInputSegment = reversedFlatInputPointsSegmentDict[lp]
710-
# Note: len(segmentedFlatPoints[0]) == 0 in this code,
711-
# so firstCurved is at least very unlikely. I don't
712-
# think I've hit the firstCurved conditions below in
713-
# my generated test data.
714707
firstCurved = firstInputSegment.segmentType == reversedFirstInputSegment.segmentType == "curve"
715708
lastCurved = lastInputSegment.segmentType == reversedLastInputSegment.segmentType == "curve"
716709
if firstCurved or lastCurved:
717-
if firstInputSegment == lastInputSegment or reversedFirstInputSegment == reversedLastInputSegment:
710+
if (firstInputSegment == lastInputSegment or
711+
reversedFirstInputSegment == reversedLastInputSegment):
712+
mergeFirstSegments = True
713+
elif (fp == lastInputSegment.scaledPreviousOnCurve and
714+
lastCurved and lp == lastInputSegment.flat[0]):
715+
mergeFirstSegments = True
716+
elif (lp == firstInputSegment.scaledPreviousOnCurve and
717+
firstCurved and fp == firstInputSegment.flat[0]):
718+
mergeFirstSegments = True
719+
elif (fp == reversedLastInputSegment.scaledPreviousOnCurve and
720+
lastCurved and lp == reversedLastInputSegment.flat[0]):
721+
mergeFirstSegments = True
722+
elif (lp == reversedFirstInputSegment.scaledPreviousOnCurve and
723+
firstCurved and fp == reversedFirstInputSegment.flat[0]):
718724
mergeFirstSegments = True
719-
elif fp == lastInputSegment.scaledPreviousOnCurve and lastCurved:
720-
if lp == lastInputSegment.flat[-1]:
721-
pass
722-
else:
723-
duplicatePoint = 1
724-
elif lp == firstInputSegment.scaledPreviousOnCurve and firstCurved:
725-
if fp == firstInputSegment.flat[-1]:
726-
pass
727-
else:
728-
duplicatePoint = -1
729-
elif fp == reversedLastInputSegment.scaledPreviousOnCurve and lastCurved:
730-
if lp == reversedLastInputSegment.flat[-1]:
731-
pass
732-
else:
733-
duplicatePoint = 1
734-
elif lp == reversedFirstInputSegment.scaledPreviousOnCurve and firstCurved:
735-
if fp == reversedFirstInputSegment.flat[-1]:
736-
pass
737-
else:
738-
duplicatePoint = -1
739725
elif not hasOncurvePoints and _distance(fp, lp):
740726
# Merge last segment with first segment if the distance between the last point and the first
741727
# point is less than the step distance between the last two points. _approximateSegmentLength
@@ -753,10 +739,6 @@ def reCurveSubSegments(self, inputContours):
753739
segmentedFlatPoints[0] = segmentedFlatPoints[-1] + segmentedFlatPoints[0]
754740
segmentedFlatPoints.pop(-1)
755741
mergeFirstSegments = False
756-
elif duplicatePoint == 1:
757-
segmentedFlatPoints[-1].append(segmentedFlatPoints[0][0])
758-
elif duplicatePoint == -1:
759-
segmentedFlatPoints[0].insert(0, segmentedFlatPoints[-1][-1])
760742
convertedSegments = []
761743
previousIntersectionPoint = None
762744
if segmentedFlatPoints[-1][-1] in intersectionPoints:

0 commit comments

Comments
 (0)