|
30 | 30 | } |
31 | 31 |
|
32 | 32 |
|
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 | | - |
52 | 33 | def clipExecute(subjectContours, clipContours, operation, subjectFillType="nonZero", |
53 | 34 | clipFillType="nonZero"): |
54 | 35 | pc = pyclipper.Pyclipper() |
55 | 36 |
|
56 | 37 | 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) |
58 | 44 |
|
59 | 45 | 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) |
61 | 52 |
|
62 | 53 | bounds = pc.GetBounds() |
63 | 54 | if (bounds.bottom, bounds.left, bounds.top, bounds.right) == (0, 0, 0, 0): |
|
0 commit comments