From 661ae39546497bd2e4eb48496903405cfe919a18 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 8 Jul 2023 20:48:14 -0400 Subject: produce only one satin from convert to satin --- lib/elements/satin_column.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/elements/satin_column.py') 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): -- cgit v1.2.3 From b01870890b07c8e9ac4c843fac9461c7086f31f7 Mon Sep 17 00:00:00 2001 From: Kaalleen Date: Sun, 9 Jul 2023 10:05:24 +0200 Subject: avoid duplicated nodes transform issue --- lib/elements/satin_column.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/elements/satin_column.py') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index cc0cda9f..8975a4ba 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -698,7 +698,7 @@ class SatinColumn(EmbroideryElement): new SatinColumn's node will not be in the SVG document. """ - return self._csp_to_satin(self.csp) + return self._csp_to_satin(self.csp, True) def split(self, split_point): """Split a satin into two satins at the specified point @@ -814,13 +814,12 @@ class SatinColumn(EmbroideryElement): def _path_list_to_satins(self, path_list): return self._csp_to_satin(line_strings_to_csp(path_list)) - def _csp_to_satin(self, csp): + def _csp_to_satin(self, csp, remove_transform=False): node = deepcopy(self.node) d = paths.CubicSuperPath(csp).to_path() node.set("d", d) - # we've already applied the transform, so get rid of it - if node.get("transform"): + if remove_transform and node.get("transform"): del node.attrib["transform"] return SatinColumn(node) @@ -843,14 +842,16 @@ class SatinColumn(EmbroideryElement): # weird non-satin things, give up and don't merge return self - rails[0].extend(other_rails[0]) - rails[1].extend(other_rails[1]) + # 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.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 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) -- cgit v1.2.3 From de863d72eff6a6bd7326edc6b7293560e0fd5d35 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 15 Jul 2023 11:25:38 -0400 Subject: more transform fixes --- lib/elements/satin_column.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/elements/satin_column.py') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 8975a4ba..4ea26575 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -698,7 +698,7 @@ class SatinColumn(EmbroideryElement): new SatinColumn's node will not be in the SVG document. """ - return self._csp_to_satin(self.csp, True) + return self._csp_to_satin(self.csp) def split(self, split_point): """Split a satin into two satins at the specified point @@ -713,6 +713,9 @@ class SatinColumn(EmbroideryElement): Returns two new SatinColumn instances: the part before and the part after the split point. All parameters are copied over to the new SatinColumn instances. + + The returned SatinColumns will not be in the SVG document and will have + their transforms applied. """ cut_points = self._find_cut_points(split_point) @@ -814,12 +817,13 @@ class SatinColumn(EmbroideryElement): def _path_list_to_satins(self, path_list): return self._csp_to_satin(line_strings_to_csp(path_list)) - def _csp_to_satin(self, csp, remove_transform=False): + def _csp_to_satin(self, csp): node = deepcopy(self.node) d = paths.CubicSuperPath(csp).to_path() node.set("d", d) - if remove_transform and node.get("transform"): + # we've already applied the transform, so get rid of it + if node.get("transform"): del node.attrib["transform"] return SatinColumn(node) @@ -834,6 +838,9 @@ class SatinColumn(EmbroideryElement): 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.flatten_subpath(rail) for rail in self.rails] other_rails = [satin.flatten_subpath(rail) for rail in satin.rails] -- cgit v1.2.3