diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2023-07-30 10:49:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-30 10:49:25 -0400 |
| commit | 9c090170941e00a6c6265e3a6999ca240fb73052 (patch) | |
| tree | 748e9bdda3acbf145c8ddb2ba7595be1975f6e56 /lib/elements/satin_column.py | |
| parent | 96df68c46f495de0f63d36b5130e7dfdc773198a (diff) | |
| parent | 74e93834c094351a398dd46d01c40d197f8fe9af (diff) | |
Merge pull request #2418 from inkstitch/lexelby/convert-to-satin-join
produce only one satin from convert to satin
Diffstat (limited to 'lib/elements/satin_column.py')
| -rw-r--r-- | lib/elements/satin_column.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 86c6d05a..4ea26575 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -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) @@ -825,6 +828,43 @@ 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.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 + + # 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 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) + + return self._csp_to_satin(point_lists_to_csp(rails + rungs)) + @property @cache def center_line(self): |
