summaryrefslogtreecommitdiff
path: root/lib/stitch_plan
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stitch_plan')
-rw-r--r--lib/stitch_plan/color_block.py8
-rw-r--r--lib/stitch_plan/stitch_plan.py8
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