fix crash with tiny satin (#3934)

* avoid crash on tiny satin

* cleanup small satins too

* fix #3933

---------

Co-authored-by: Kaalleen <reni@allenka.de>
pull/3940/head dev-build-claudine-rename_fill_composed_glyph_to_organize_glyphs
Lex Neva 2025-08-24 09:14:09 -04:00 zatwierdzone przez GitHub
rodzic c6c10ad642
commit dbef888e4d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 23 dodań i 2 usunięć

Wyświetl plik

@ -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):

Wyświetl plik

@ -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)))

Wyświetl plik

@ -12,6 +12,9 @@
<param name="rm_stroke" type="boolean" gui-text="Remove Small strokes"
gui-description="Removes small strokes shorter than defined by threshold.">true</param>
<param name="stroke_threshold" type="int" gui-text="Stroke threshold (px)" min="2" max="800">5</param>
<param name="rm_satin" type="boolean" gui-text="Remove Small satins"
gui-description="Removes small satin columns shorter than defined by threshold.">true</param>
<param name="satin_threshold" type="int" gui-text="Satin threshold (px)" min="2" max="800">5</param>
<param name="rm_groups" type="boolean" gui-text="Remove empty layers and groups">true</param>
<spacer />
<separator />