From c6c10ad642b92c5dd2687d4b6b48b1b4b36c8de7 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 22 Aug 2025 08:47:24 -0400 Subject: 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 --- lib/elements/utils/stroke_to_satin.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'lib/elements/utils/stroke_to_satin.py') 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) -- cgit v1.2.3