summaryrefslogtreecommitdiff
path: root/lib/stitches
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2024-07-09 18:18:49 +0200
committerGitHub <noreply@github.com>2024-07-09 18:18:49 +0200
commit4644c119495e175e909096d4e947dbb9e5f8234a (patch)
tree114855a36b3653e0c182aa12766fa928d442da6c /lib/stitches
parentf55571eac13a32ec6d27a4d4c0929d47449da2d4 (diff)
Pull comp: remove holes again (#3067)
* pull comp: remove holes again * rescue some more broken shapes
Diffstat (limited to 'lib/stitches')
-rw-r--r--lib/stitches/auto_fill.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py
index 84832fc8..963d686d 100644
--- a/lib/stitches/auto_fill.py
+++ b/lib/stitches/auto_fill.py
@@ -140,7 +140,19 @@ def adjust_shape_for_pull_compensation(shape, angle, row_spacing, pull_compensat
buffered_lines = [line.buffer(buffer_amount) for line in lines]
polygon = unary_union(buffered_lines)
- return make_valid(polygon)
+ exterior = smooth_path(polygon.exterior.coords, 0.2)
+ min_hole_area = row_spacing ** 2
+ interiors = [smooth_path(interior.coords) for interior in polygon.interiors if shgeo.Polygon(interior).area > min_hole_area]
+
+ shape = make_valid(shgeo.Polygon(exterior, interiors))
+ if shape.geom_type == 'MultiPolygon':
+ # the shape is somehow messed up
+ # rescue it by just using the first geometry
+ shape = list(shape.geoms)
+ shape.sort(key=lambda polygon: polygon.area, reverse=True)
+ shape = shape[0]
+
+ return shape
def apply_pull_compensation(segments, pull_compensation_px, pull_compensation_percent):