Skip to content

Commit b7d9fc9

Browse files
authored
Merge pull request #52 from typemytype/simplify-skip-no-area
simplify handling of invalid zero-area paths
2 parents d13c612 + ed866a5 commit b7d9fc9

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

Lib/booleanOperations/booleanOperationManager.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,25 @@
3030
}
3131

3232

33-
def _addContour(clipperPath, contour, fillType, contourCount):
34-
if pyclipper.Area(contour) == 0:
35-
# skip paths with no area,
36-
# BUT self intersecting paths could have no area...
37-
dummy = pyclipper.Pyclipper()
38-
try:
39-
dummy.AddPath(contour, fillType)
40-
shouldBeAValidPath = True
41-
except pyclipper.ClipperException:
42-
shouldBeAValidPath = False
43-
if not shouldBeAValidPath:
44-
return
45-
46-
try:
47-
clipperPath.AddPath(contour, fillType)
48-
except pyclipper.ClipperException:
49-
raise InvalidSubjectContourError("contour %d is invalid for clipping" % contourCount)
50-
51-
5233
def clipExecute(subjectContours, clipContours, operation, subjectFillType="nonZero",
5334
clipFillType="nonZero"):
5435
pc = pyclipper.Pyclipper()
5536

5637
for i, subjectContour in enumerate(subjectContours):
57-
_addContour(clipperPath=pc, contour=subjectContour, fillType=pyclipper.PT_SUBJECT, contourCount=i)
38+
try:
39+
pc.AddPath(subjectContour, pyclipper.PT_SUBJECT)
40+
except pyclipper.ClipperException:
41+
# skip invalid paths with no area
42+
if pyclipper.Area(subjectContour) != 0:
43+
raise InvalidSubjectContourError("contour %d is invalid for clipping" % i)
5844

5945
for j, clipContour in enumerate(clipContours):
60-
_addContour(clipperPath=pc, contour=clipContour, fillType=pyclipper.PT_CLIP, contourCount=i)
46+
try:
47+
pc.AddPath(clipContour, pyclipper.PT_CLIP)
48+
except pyclipper.ClipperException:
49+
# skip invalid paths with no area
50+
if pyclipper.Area(clipContour) == 0:
51+
raise InvalidClippingContourError("contour %d is invalid for clipping" % j)
6152

6253
bounds = pc.GetBounds()
6354
if (bounds.bottom, bounds.left, bounds.top, bounds.right) == (0, 0, 0, 0):

0 commit comments

Comments
 (0)