summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2025-08-22 08:47:24 -0400
committerGitHub <noreply@github.com>2025-08-22 08:47:24 -0400
commitc6c10ad642b92c5dd2687d4b6b48b1b4b36c8de7 (patch)
treefebe691c3fafa050b102fc5897ff85fe494356b1
parente9bcdc910a2101c0da2fa379da36e1d1be2fe3f2 (diff)
a few fixes for converting stroke to satin internally (#3926)
* remove unused flatten_subpath() * there will always be two rails here * handle degenerate zero-length sections * remove unused SatinColumn.merge() * mark merge() as private and adjust docstring
-rw-r--r--lib/elements/element.py6
-rw-r--r--lib/elements/satin_column.py39
-rw-r--r--lib/elements/utils/stroke_to_satin.py23
3 files changed, 8 insertions, 60 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 1ca78b04..4aaf7580 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -520,12 +520,6 @@ class EmbroideryElement(object):
return [self.strip_control_points(subpath) for subpath in path]
- def flatten_subpath(self, subpath):
- path = [deepcopy(subpath)]
- bezier.cspsubdiv(path, 0.1)
-
- return self.strip_control_points(path[0])
-
@property
@cache
def lock_stitches(self):
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py
index 3f427724..62252ddb 100644
--- a/lib/elements/satin_column.py
+++ b/lib/elements/satin_column.py
@@ -1076,45 +1076,6 @@ 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.
-
- The returned SatinColumn will not be in the SVG document and will have
- its transforms applied.
- """
- rails = self.rails
- other_rails = satin.rails
-
- if len(rails) != 2 or len(other_rails) != 2:
- # weird non-satin things, give up and don't merge
- return self
-
- # remove first node of each other rail before merging (avoid duplicated nodes)
- rails[0].extend(other_rails[0][1:])
- rails[1].extend(other_rails[1][1:])
-
- rungs = self.rungs
- other_rungs = satin.rungs
-
- # add a rung in between the two satins and extend it just a litte to ensure it is crossing the rails
- new_rung = shgeo.LineString([other_rails[0][0], other_rails[1][0]])
- rungs.append(list(shaffinity.scale(new_rung, 1.2, 1.2).coords))
-
- # add on the other satin's rungs
- rungs.extend(other_rungs)
-
- rungs = self._get_filtered_rungs(rails, rungs)
-
- return self._coordinates_to_satin(line_strings_to_coordinate_lists(rails + rungs))
-
def _get_filtered_rungs(self, rails, rungs):
# returns a filtered list of rungs which do intersect the rails exactly twice
rails = shgeo.MultiLineString(rails)
diff --git a/lib/elements/utils/stroke_to_satin.py b/lib/elements/utils/stroke_to_satin.py
index 6e6367aa..e75ca5d3 100644
--- a/lib/elements/utils/stroke_to_satin.py
+++ b/lib/elements/utils/stroke_to_satin.py
@@ -33,7 +33,7 @@ def convert_path_to_satin(path, stroke_width, style_args, rungs_at_nodes=False):
if sections:
joined_satin = list(sections)[0]
for satin in sections[1:]:
- joined_satin = merge(joined_satin, satin)
+ joined_satin = _merge(joined_satin, satin)
return joined_satin
return None
@@ -279,25 +279,18 @@ def generate_rungs(path, stroke_width, left_rail, right_rail, rungs_at_nodes):
return rungs
-def merge(section, other_section):
- """Merge this satin with another satin
+def _merge(section, other_section):
+ """Merge two satin sections
- 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.
-
- The returned SatinColumn will not be in the SVG document and will have
- its transforms applied.
+ The two sections are expected to be contiguous; that is, the second one
+ starts where the first one ends.
"""
rails, rungs = section
other_rails, other_rungs = other_section
- if len(rails) != 2 or len(other_rails) != 2:
- # weird non-satin things, give up and don't merge
+ if len(other_rails[0]) < 2 or len(other_rails[1]) < 2:
+ # Somehow we got a degenerate rail with only one (or no?) point.
+ # Ignore this one since it has zero length anyway.
return section
# remove first node of each other rail before merging (avoid duplicated nodes)