From 8e70f3d2feaab8a14f775a5ef84002bdab9688f0 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Tue, 26 Mar 2024 07:10:40 +0100 Subject: Add object based min stitch length (#2792) * add object based min stitch length (overwrites global) * add object based minimum jump stitch (overwrites global) * rename patches to stitch_groups --- lib/stitch_plan/stitch.py | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'lib/stitch_plan/stitch.py') diff --git a/lib/stitch_plan/stitch.py b/lib/stitch_plan/stitch.py index 8ad699c7..ffa944ae 100644 --- a/lib/stitch_plan/stitch.py +++ b/lib/stitch_plan/stitch.py @@ -11,7 +11,17 @@ from ..utils.geometry import Point class Stitch(Point): """A stitch is a Point with extra information telling how to sew it.""" - def __init__(self, x, y=None, color=None, jump=False, stop=False, trim=False, color_change=False, tags=None): + def __init__( + self, + x, y=None, + color=None, + jump=False, + stop=False, + trim=False, + color_change=False, + min_stitch_length=None, + tags=None + ): # DANGER: if you add new attributes, you MUST also set their default # values in __new__() below. Otherwise, cached stitch plans can be # loaded and create objects without those properties defined, because @@ -37,6 +47,7 @@ class Stitch(Point): self._set('trim', trim, base_stitch) self._set('stop', stop, base_stitch) self._set('color_change', color_change, base_stitch) + self._set('min_stitch_length', min_stitch_length, base_stitch) self.tags = set() self.add_tags(tags or []) @@ -52,13 +63,16 @@ class Stitch(Point): return instance def __repr__(self): - return "Stitch(%s, %s, %s, %s, %s, %s, %s)" % (self.x, - self.y, - self.color, - "JUMP" if self.jump else " ", - "TRIM" if self.trim else " ", - "STOP" if self.stop else " ", - "COLOR CHANGE" if self.color_change else " ") + return "Stitch(%s, %s, %s, %s, %s, %s, %s, %s)" % ( + self.x, + self.y, + self.color, + self.min_stitch_length, + "JUMP" if self.jump else " ", + "TRIM" if self.trim else " ", + "STOP" if self.stop else " ", + "COLOR CHANGE" if self.color_change else " " + ) def _set(self, attribute, value, base_stitch): # Set an attribute. If the caller passed a Stitch object, use its value, unless @@ -95,7 +109,17 @@ class Stitch(Point): return tag in self.tags def copy(self): - return Stitch(self.x, self.y, self.color, self.jump, self.stop, self.trim, self.color_change, self.tags) + return Stitch( + self.x, + self.y, + self.color, + self.jump, + self.stop, + self.trim, + self.color_change, + self.min_stitch_length, + self.tags + ) def offset(self, offset: Point): out = self.copy() -- cgit v1.2.3