diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2022-06-22 15:22:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-22 15:22:34 +0200 |
| commit | b6bde000fe675ed725d7d5dbd7db3f44fb33af0e (patch) | |
| tree | 2c856ac51c563b6c918ab3041ac29c5106e7a06d /lib/stitch_plan | |
| parent | 75fc4ce8695f6fb6c7cc108fcf458ad36bbd00c1 (diff) | |
Option to drop short stitches (#1693)
Diffstat (limited to 'lib/stitch_plan')
| -rw-r--r-- | lib/stitch_plan/color_block.py | 8 | ||||
| -rw-r--r-- | lib/stitch_plan/stitch_plan.py | 8 |
2 files changed, 9 insertions, 7 deletions
diff --git a/lib/stitch_plan/color_block.py b/lib/stitch_plan/color_block.py index cd7b9c6d..2f387460 100644 --- a/lib/stitch_plan/color_block.py +++ b/lib/stitch_plan/color_block.py @@ -98,19 +98,21 @@ class ColorBlock(object): return False - def filter_duplicate_stitches(self): + def filter_duplicate_stitches(self, min_stitch_len=0.1): if not self.stitches: return - stitches = [self.stitches[0]] + if min_stitch_len is None: + min_stitch_len = 0.1 + stitches = [self.stitches[0]] for stitch in self.stitches[1:]: if stitches[-1].jump or stitch.stop or stitch.trim or stitch.color_change: # Don't consider jumps, stops, color changes, or trims as candidates for filtering pass else: length = (stitch - stitches[-1]).length() - if length <= 0.1 * PIXELS_PER_MM: + if length <= min_stitch_len * PIXELS_PER_MM: # duplicate stitch, skip this one continue diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py index 4593781a..04d587c2 100644 --- a/lib/stitch_plan/stitch_plan.py +++ b/lib/stitch_plan/stitch_plan.py @@ -13,7 +13,7 @@ from .color_block import ColorBlock from .ties import add_ties -def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, disable_ties=False): # noqa: C901 +def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, min_stitch_len=0.1, disable_ties=False): # noqa: C901 """Convert a collection of StitchGroups to a StitchPlan. @@ -71,7 +71,7 @@ def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, disable_ties= # last block ended in a stop, so now we have an empty block del stitch_plan.color_blocks[-1] - stitch_plan.filter_duplicate_stitches() + stitch_plan.filter_duplicate_stitches(min_stitch_len) if not disable_ties: stitch_plan.add_ties() @@ -101,9 +101,9 @@ class StitchPlan(object): def add_color_block(self, color_block): self.color_blocks.append(color_block) - def filter_duplicate_stitches(self): + def filter_duplicate_stitches(self, min_stitch_len): for color_block in self: - color_block.filter_duplicate_stitches() + color_block.filter_duplicate_stitches(min_stitch_len) def add_ties(self): # see ties.py |
