Skip to content

Commit

Permalink
repair/project: make make_intersection more robust…
Browse files Browse the repository at this point in the history
round via Shapely 2.x set_precision
  • Loading branch information
bertsky committed Feb 24, 2024
1 parent 03540b5 commit f8a13a4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ocrd_segment/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def join_polygons(polygons, scale=20):
polygons.append(bridgep)
jointp = unary_union(polygons)
assert jointp.geom_type == 'Polygon', jointp.wkt
# follow-up calculations will necessarily be integer;
# so anticipate rounding here and then ensure validity
jointp = set_precision(jointp, 1.0)
return jointp

Expand Down Expand Up @@ -233,11 +235,9 @@ def make_intersection(poly1, poly2):
if interp.geom_type == 'MultiPolygon':
# homogeneous result: construct convex hull to connect
interp = join_polygons(interp.geoms)
if interp.minimum_clearance < 1.0:
# follow-up calculations will necessarily be integer;
# so anticipate rounding here and then ensure validity
interp = Polygon(np.round(interp.exterior.coords))
interp = make_valid(interp)
# follow-up calculations will necessarily be integer;
# so anticipate rounding here and then ensure validity
interp = set_precision(interp, 1.0)
return interp

def make_valid(polygon):
Expand Down

0 comments on commit f8a13a4

Please sign in to comment.