diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/extensions/stitch_plan_preview.py | 2 | ||||
| -rw-r--r-- | lib/stitches/auto_fill.py | 14 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/extensions/stitch_plan_preview.py b/lib/extensions/stitch_plan_preview.py index ddb0e3d1..8d08f6d6 100644 --- a/lib/extensions/stitch_plan_preview.py +++ b/lib/extensions/stitch_plan_preview.py @@ -139,7 +139,7 @@ class StitchPlanPreview(InkstitchExtension): out = findall(r"(?m)^-?\d+\.?\d*$", out) # Parse the returned coordinates out into viewport units - x, y, width, height = map(lambda x: svg.viewport_to_unit(f'{x}px', svg.unit), out) + x, y, width, height = map(lambda x: svg.viewport_to_unit(f'{x}px'), out) # Embed the rasterized stitch plan into the SVG, and replace the original stitch plan with open(temp_png_path, "rb") as f: 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): |
