Skip to content

Commit 1a33f94

Browse files
author
Robert Sachunsky
committed
segment/polygon_for_parent: skip segment if polygon cannot be made valid
1 parent 426a33d commit 1a33f94

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ocrd_cis/ocropy/segment.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,17 @@ def polygon_for_parent(polygon, parent):
731731
# (this can happen when shapes valid in floating point are rounded)
732732
childp = make_valid(childp)
733733
parentp = make_valid(parentp)
734+
if not childp.is_valid:
735+
return None
736+
if not parentp.is_valid:
737+
return None
734738
# check if clipping is necessary
735739
if childp.within(parentp):
736740
return childp.exterior.coords[:-1]
737741
# clip to parent
738742
interp = make_intersection(childp, parentp)
743+
if not interp:
744+
return None
739745
return interp.exterior.coords[:-1] # keep open
740746

741747
def make_intersection(poly1, poly2):

0 commit comments

Comments
 (0)