From e884fb78db288c91e8183ef8e242840ba5d68db2 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Jun 2022 09:26:37 -0400 Subject: add running stitch tolerance param (#1701) --- lib/elements/fill_stitch.py | 18 ++++++++++++++++++ lib/elements/stroke.py | 21 +++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'lib/elements') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 245c67e0..dbd94fb4 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -366,6 +366,19 @@ class FillStitch(EmbroideryElement): def running_stitch_length(self): return max(self.get_float_param("running_stitch_length_mm", 1.5), 0.01) + @property + @param('running_stitch_tolerance_mm', + _('Running stitch tolerance'), + tooltip=_('All stitches must be within this distance of the path. ' + + 'A lower tolerance means stitches will be closer together. ' + + 'A higher tolerance means sharp corners may be rounded.'), + unit='mm', + type='float', + default=0.2, + sort_index=6) + def running_stitch_tolerance(self): + return max(self.get_float_param("running_stitch_tolerance_mm", 0.2), 0.01) + @property @param('fill_underlay', _('Underlay'), type='toggle', group=_('Fill Underlay'), default=True) def fill_underlay(self): @@ -560,6 +573,7 @@ class FillStitch(EmbroideryElement): self.fill_underlay_row_spacing, self.fill_underlay_max_stitch_length, self.running_stitch_length, + self.running_stitch_tolerance, self.staggers, self.fill_underlay_skip_last, starting_point, @@ -580,6 +594,7 @@ class FillStitch(EmbroideryElement): self.end_row_spacing, self.max_stitch_length, self.running_stitch_length, + self.running_stitch_tolerance, self.staggers, self.skip_last, starting_point, @@ -601,6 +616,7 @@ class FillStitch(EmbroideryElement): tree, self.row_spacing, self.max_stitch_length, + self.running_stitch_tolerance, starting_point, self.avoid_self_crossing ) @@ -608,12 +624,14 @@ class FillStitch(EmbroideryElement): stitches = contour_fill.single_spiral( tree, self.max_stitch_length, + self.running_stitch_tolerance, starting_point ) elif self.contour_strategy == 2: stitches = contour_fill.double_spiral( tree, self.max_stitch_length, + self.running_stitch_tolerance, starting_point ) diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py index 6edd2c9e..bf5e1d35 100644 --- a/lib/elements/stroke.py +++ b/lib/elements/stroke.py @@ -111,6 +111,19 @@ class Stroke(EmbroideryElement): def running_stitch_length(self): return max(self.get_float_param("running_stitch_length_mm", 1.5), 0.01) + @property + @param('running_stitch_tolerance_mm', + _('Running stitch tolerance'), + tooltip=_('All stitches must be within this distance from the path. ' + + 'A lower tolerance means stitches will be closer together. ' + + 'A higher tolerance means sharp corners may be rounded.'), + unit='mm', + type='float', + default=0.2, + sort_index=4) + def running_stitch_tolerance(self): + return max(self.get_float_param("running_stitch_tolerance_mm", 0.2), 0.01) + @property @param('zigzag_spacing_mm', _('Zig-zag spacing (peak-to-peak)'), @@ -360,7 +373,7 @@ class Stroke(EmbroideryElement): # `self.zigzag_spacing` is the length for a zig and a zag # together (a V shape). Start with running stitch at half # that length: - patch = self.running_stitch(path, zigzag_spacing / 2.0) + patch = self.running_stitch(path, zigzag_spacing / 2.0, self.running_stitch_tolerance) # Now move the points left and right. Consider each pair # of points in turn, and move perpendicular to them, @@ -385,7 +398,7 @@ class Stroke(EmbroideryElement): return patch - def running_stitch(self, path, stitch_length): + def running_stitch(self, path, stitch_length, tolerance): repeated_path = [] # go back and forth along the path as specified by self.repeats @@ -398,7 +411,7 @@ class Stroke(EmbroideryElement): repeated_path.extend(this_path) - stitches = running_stitch(repeated_path, stitch_length) + stitches = running_stitch(repeated_path, stitch_length, tolerance) return StitchGroup(self.color, stitches) @@ -429,7 +442,7 @@ class Stroke(EmbroideryElement): patch = StitchGroup(color=self.color, stitches=path, stitch_as_is=True) # running stitch elif self.is_running_stitch(): - patch = self.running_stitch(path, self.running_stitch_length) + patch = self.running_stitch(path, self.running_stitch_length, self.running_stitch_tolerance) if self.bean_stitch_repeats > 0: patch.stitches = self.do_bean_repeats(patch.stitches) # simple satin -- cgit v1.2.3