summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2023-07-08 20:48:14 -0400
committerLex Neva <github.com@lexneva.name>2023-07-08 20:48:14 -0400
commit661ae39546497bd2e4eb48496903405cfe919a18 (patch)
treef03812935cb9a0cfdbc28d49d16ec30e058322c4
parent71e09496c27e1742ce4d7eaa3d4333f1a20f252e (diff)
produce only one satin from convert to satin
-rw-r--r--lib/elements/satin_column.py32
-rw-r--r--lib/extensions/convert_to_satin.py15
2 files changed, 42 insertions, 5 deletions
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py
index 86c6d05a..cc0cda9f 100644
--- a/lib/elements/satin_column.py
+++ b/lib/elements/satin_column.py
@@ -825,6 +825,38 @@ class SatinColumn(EmbroideryElement):
return SatinColumn(node)
+ def merge(self, satin):
+ """Merge this satin with another satin
+
+ This method expects that the provided satin continues on directly after
+ this one, as would be the case, for example, if the two satins were the
+ result of the split() method.
+
+ Returns a new SatinColumn instance that combines the rails and rungs of
+ this satin and the provided satin. A rung is added at the end of this
+ satin.
+ """
+ rails = [self.flatten_subpath(rail) for rail in self.rails]
+ other_rails = [satin.flatten_subpath(rail) for rail in satin.rails]
+
+ if len(rails) != 2 or len(other_rails) != 2:
+ # weird non-satin things, give up and don't merge
+ return self
+
+ rails[0].extend(other_rails[0])
+ rails[1].extend(other_rails[1])
+
+ rungs = [self.flatten_subpath(rung) for rung in self.rungs]
+ other_rungs = [satin.flatten_subpath(rung) for rung in satin.rungs]
+
+ # add a rung at the end of my satin
+ rungs.append([rails[0][-1], rails[1][-1]])
+
+ # add on the other satin's rungs
+ rungs.extend(other_rungs)
+
+ return self._csp_to_satin(point_lists_to_csp(rails + rungs))
+
@property
@cache
def center_line(self):
diff --git a/lib/extensions/convert_to_satin.py b/lib/extensions/convert_to_satin.py
index 7a36ce21..093b301c 100644
--- a/lib/extensions/convert_to_satin.py
+++ b/lib/extensions/convert_to_satin.py
@@ -13,7 +13,7 @@ from numpy import diff, setdiff1d, sign
from shapely import geometry as shgeo
from .base import InkstitchExtension
-from ..elements import Stroke
+from ..elements import SatinColumn, Stroke
from ..i18n import _
from ..svg import PIXELS_PER_MM, get_correction_transform
from ..svg.tags import INKSTITCH_ATTRIBS
@@ -57,16 +57,21 @@ class ConvertToSatin(InkstitchExtension):
# ignore paths with just one point -- they're not visible to the user anyway
continue
- for satin in self.convert_path_to_satins(path, element.stroke_width, style_args, correction_transform, path_style):
- parent.insert(index, satin)
- index += 1
+ satins = list(self.convert_path_to_satins(path, element.stroke_width, style_args, correction_transform, path_style))
+
+ if satins:
+ joined_satin = satins[0]
+ for satin in satins[1:]:
+ joined_satin = joined_satin.merge(satin)
+
+ parent.insert(index, joined_satin.node)
parent.remove(element.node)
def convert_path_to_satins(self, path, stroke_width, style_args, correction_transform, path_style, depth=0):
try:
rails, rungs = self.path_to_satin(path, stroke_width, style_args)
- yield self.satin_to_svg_node(rails, rungs, correction_transform, path_style)
+ yield SatinColumn(self.satin_to_svg_node(rails, rungs, correction_transform, path_style))
except SelfIntersectionError:
# The path intersects itself. Split it in two and try doing the halves
# individually.