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.py19
-rw-r--r--lib/stitch_plan/stitch.py10
-rw-r--r--lib/stitch_plan/stitch_plan.py7
3 files changed, 36 insertions, 0 deletions
diff --git a/lib/stitch_plan/color_block.py b/lib/stitch_plan/color_block.py
index 9d474f80..a888dc80 100644
--- a/lib/stitch_plan/color_block.py
+++ b/lib/stitch_plan/color_block.py
@@ -3,6 +3,8 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+from typing import List
+
from .stitch import Stitch
from ..threads import ThreadColor
from ..utils.geometry import Point
@@ -155,3 +157,20 @@ class ColorBlock(object):
maxy = max(stitch.y for stitch in self)
return minx, miny, maxx, maxy
+
+ def make_offsets(self, offsets: List[Point]):
+ first_final_stitch = len(self.stitches)
+ while (first_final_stitch > 0 and self.stitches[first_final_stitch-1].is_terminator):
+ first_final_stitch -= 1
+ if first_final_stitch == 0:
+ return self
+ final_stitches = self.stitches[first_final_stitch:]
+ block_stitches = self.stitches[:first_final_stitch]
+
+ out = ColorBlock(self.color)
+ for i, offset in enumerate(offsets):
+ out.add_stitches([s.offset(offset) for s in block_stitches])
+ if i != len(offsets) - 1:
+ out.add_stitch(trim=True)
+ out.add_stitches(final_stitches)
+ return out
diff --git a/lib/stitch_plan/stitch.py b/lib/stitch_plan/stitch.py
index 90af58c0..8ad699c7 100644
--- a/lib/stitch_plan/stitch.py
+++ b/lib/stitch_plan/stitch.py
@@ -68,6 +68,10 @@ class Stitch(Point):
if value or base_stitch is None:
setattr(self, attribute, value)
+ @property
+ def is_terminator(self) -> bool:
+ return self.trim or self.stop or self.color_change
+
def add_tags(self, tags):
for tag in tags:
self.add_tag(tag)
@@ -93,6 +97,12 @@ class Stitch(Point):
def copy(self):
return Stitch(self.x, self.y, self.color, self.jump, self.stop, self.trim, self.color_change, self.tags)
+ def offset(self, offset: Point):
+ out = self.copy()
+ out.x += offset.x
+ out.y += offset.y
+ return out
+
def __json__(self):
attributes = dict(vars(self))
attributes['tags'] = list(attributes['tags'])
diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py
index 25571578..b9ce902a 100644
--- a/lib/stitch_plan/stitch_plan.py
+++ b/lib/stitch_plan/stitch_plan.py
@@ -4,6 +4,7 @@
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
from sys import exit
+from typing import List
from inkex import errormsg
@@ -11,6 +12,7 @@ from ..i18n import _
from ..svg import PIXELS_PER_MM
from .color_block import ColorBlock
from ..utils.threading import check_stop_flag
+from ..utils.geometry import Point
def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, min_stitch_len=0.1, disable_ties=False): # noqa: C901
@@ -207,3 +209,8 @@ class StitchPlan(object):
return self.color_blocks[-1]
else:
return None
+
+ def make_offsets(self, offsets: List[Point]):
+ out = StitchPlan()
+ out.color_blocks = [block.make_offsets(offsets) for block in self]
+ return out