Skip to content

Commit fdf4039

Browse files
committed
ignore zero area contours only when pyclipper cannot add them
this solves zero area self intersection paths, but still ignores reall zero area paths like lines #50 #48
1 parent f5fb0d4 commit fdf4039

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

Lib/booleanOperations/booleanOperationManager.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,34 @@
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, pyclipper.PT_SUBJECT)
48+
except pyclipper.ClipperException:
49+
raise InvalidSubjectContourError("contour %d is invalid for clipping" % contourCount)
50+
51+
3352
def clipExecute(subjectContours, clipContours, operation, subjectFillType="nonZero",
3453
clipFillType="nonZero"):
3554
pc = pyclipper.Pyclipper()
3655

3756
for i, subjectContour in enumerate(subjectContours):
38-
try:
39-
pc.AddPath(subjectContour, pyclipper.PT_SUBJECT)
40-
except pyclipper.ClipperException:
41-
raise InvalidSubjectContourError("contour %d is invalid for clipping" % i)
57+
_addContour(pc, subjectContour, pyclipper.PT_SUBJECT, i)
58+
4259
for j, clipContour in enumerate(clipContours):
43-
try:
44-
pc.AddPath(clipContour, pyclipper.PT_CLIP)
45-
except pyclipper.ClipperException:
46-
raise InvalidClippingContourError("contour %d is invalid for clipping" % j)
60+
_addContour(pc, subjectContour, pyclipper.PT_CLIP, i)
4761

4862
try:
4963
solution = pc.Execute(_operationMap[operation],

0 commit comments

Comments
 (0)