Skip to content

Commit

Permalink
Merge pull request #52 from typemytype/simplify-skip-no-area
Browse files Browse the repository at this point in the history
simplify handling of invalid zero-area paths
  • Loading branch information
typemytype authored Dec 10, 2018
2 parents d13c612 + ed866a5 commit b7d9fc9
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions Lib/booleanOperations/booleanOperationManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,25 @@
}


def _addContour(clipperPath, contour, fillType, contourCount):
if pyclipper.Area(contour) == 0:
# skip paths with no area,
# BUT self intersecting paths could have no area...
dummy = pyclipper.Pyclipper()
try:
dummy.AddPath(contour, fillType)
shouldBeAValidPath = True
except pyclipper.ClipperException:
shouldBeAValidPath = False
if not shouldBeAValidPath:
return

try:
clipperPath.AddPath(contour, fillType)
except pyclipper.ClipperException:
raise InvalidSubjectContourError("contour %d is invalid for clipping" % contourCount)


def clipExecute(subjectContours, clipContours, operation, subjectFillType="nonZero",
clipFillType="nonZero"):
pc = pyclipper.Pyclipper()

for i, subjectContour in enumerate(subjectContours):
_addContour(clipperPath=pc, contour=subjectContour, fillType=pyclipper.PT_SUBJECT, contourCount=i)
try:
pc.AddPath(subjectContour, pyclipper.PT_SUBJECT)
except pyclipper.ClipperException:
# skip invalid paths with no area
if pyclipper.Area(subjectContour) != 0:
raise InvalidSubjectContourError("contour %d is invalid for clipping" % i)

for j, clipContour in enumerate(clipContours):
_addContour(clipperPath=pc, contour=clipContour, fillType=pyclipper.PT_CLIP, contourCount=i)
try:
pc.AddPath(clipContour, pyclipper.PT_CLIP)
except pyclipper.ClipperException:
# skip invalid paths with no area
if pyclipper.Area(clipContour) == 0:
raise InvalidClippingContourError("contour %d is invalid for clipping" % j)

bounds = pc.GetBounds()
if (bounds.bottom, bounds.left, bounds.top, bounds.right) == (0, 0, 0, 0):
Expand Down

0 comments on commit b7d9fc9

Please sign in to comment.