Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify handling of invalid zero-area paths #52

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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