From dbef888e4d07fbd8dd840d160266768e41c894a2 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 24 Aug 2025 09:14:09 -0400 Subject: [PATCH] fix crash with tiny satin (#3934) * avoid crash on tiny satin * cleanup small satins too * fix #3933 --------- Co-authored-by: Kaalleen --- lib/elements/satin_column.py | 8 ++++++++ lib/extensions/cleanup.py | 14 ++++++++++++-- templates/cleanup.xml | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 62252ddb4..4951f8bf0 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -611,6 +611,10 @@ class SatinColumn(EmbroideryElement): self.pull_compensation_percent/100, True, ) + if len(pairs) == 1: + # we need at least two points for line string creation + # if there is only one, we simply duplicate it to prevent an error + pairs.append(pairs[0]) rail1 = [point[0] for point in pairs] rail2 = [point[1] for point in pairs] return shgeo.MultiLineString((rail1, rail2)) @@ -1110,6 +1114,10 @@ class SatinColumn(EmbroideryElement): points = [points[0] for points in pairs] stitches = running_stitch.even_running_stitch(points, self.running_stitch_length, self.running_stitch_tolerance) + + if len(stitches) == 1: + stitches.append(stitches[0]) + return stitches def _stitch_distance(self, pos0, pos1, previous_pos0, previous_pos1): diff --git a/lib/extensions/cleanup.py b/lib/extensions/cleanup.py index d59174f20..593c7f28e 100644 --- a/lib/extensions/cleanup.py +++ b/lib/extensions/cleanup.py @@ -5,7 +5,7 @@ from inkex import NSS, Boolean, errormsg -from ..elements import FillStitch, Stroke +from ..elements import FillStitch, SatinColumn, Stroke from ..i18n import _ from ..svg.tags import SVG_GROUP_TAG from .base import InkstitchExtension @@ -17,16 +17,20 @@ class Cleanup(InkstitchExtension): self.arg_parser.add_argument("--notebook") self.arg_parser.add_argument("-f", "--rm_fill", dest="rm_fill", type=Boolean, default=True) self.arg_parser.add_argument("-s", "--rm_stroke", dest="rm_stroke", type=Boolean, default=True) + self.arg_parser.add_argument("-n", "--rm_satin", dest="rm_satin", type=Boolean, default=True) self.arg_parser.add_argument("-a", "--fill_threshold", dest="fill_threshold", type=int, default=20) self.arg_parser.add_argument("-l", "--stroke_threshold", dest="stroke_threshold", type=int, default=5) + self.arg_parser.add_argument("-t", "--satin_threshold", dest="satin_threshold", type=int, default=5) self.arg_parser.add_argument("-g", "--rm_groups", dest="rm_groups", type=Boolean, default=True) self.arg_parser.add_argument("-d", "--dry_run", dest="dry_run", type=Boolean, default=False) def effect(self): self.rm_fill = self.options.rm_fill self.rm_stroke = self.options.rm_stroke + self.rm_satin = self.options.rm_satin self.fill_threshold = self.options.fill_threshold self.stroke_threshold = self.options.stroke_threshold + self.satin_threshold = self.options.satin_threshold self.rm_groups = self.options.rm_groups self.dry_run = self.options.dry_run @@ -45,6 +49,9 @@ class Cleanup(InkstitchExtension): if self.rm_stroke and (isinstance(element, Stroke) and element.shape.length < self.stroke_threshold and element.node.getparent() is not None): self.elements_to_remove.add(element.node) + if self.rm_satin and (isinstance(element, SatinColumn) and + element.shape.length < self.satin_threshold and element.node.getparent() is not None): + self.elements_to_remove.add(element.node) self.groups_to_remove = set() if self.rm_groups: @@ -60,7 +67,10 @@ class Cleanup(InkstitchExtension): def _dry_run(self): errormsg(_("%s elements to remove:" % len(self.elements_to_remove))) for element in self.elements_to_remove: - errormsg(f" - {element.label}: {element.get_id()}") + if element.label: + errormsg(f" - {element.label} (id: {element.get_id()})") + else: + errormsg(f" - {element.get_id()}") errormsg("\n") errormsg(_("%s groups/layers to remove:" % len(self.groups_to_remove))) diff --git a/templates/cleanup.xml b/templates/cleanup.xml index 51bd94e34..97c7a755e 100644 --- a/templates/cleanup.xml +++ b/templates/cleanup.xml @@ -12,6 +12,9 @@ true 5 + true + 5 true