diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-04-27 21:20:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-27 21:20:55 +0200 |
| commit | 41975b1f6a6e88a8737d8989b2ac12b71f750b59 (patch) | |
| tree | d97a2c9112703909e77597f3be31b5644304676e | |
| parent | 3b47c180fd334a64805a49fe7580709d04f6242c (diff) | |
fix zerodivision error in zigzag to satin (#3696)
| -rw-r--r-- | lib/extensions/zigzag_line_to_satin.py | 27 | ||||
| -rw-r--r-- | lib/lettering/font.py | 5 |
2 files changed, 15 insertions, 17 deletions
diff --git a/lib/extensions/zigzag_line_to_satin.py b/lib/extensions/zigzag_line_to_satin.py index f867a42b..ed6b8013 100644 --- a/lib/extensions/zigzag_line_to_satin.py +++ b/lib/extensions/zigzag_line_to_satin.py @@ -150,24 +150,14 @@ class ZigzagLineToSatin(InkstitchExtension): # get start handle positions start = inkex.DirectedLineSegment(prev_prev, point) - if prev in sharp_edges: - start = prev - elif not start.length == 0: - start = start.parallel(*prev).point_at_length(start.length - length) - else: - start = start.start + handle_position_start = self._get_handle_position(prev, start, sharp_edges, length) # get end handle positions end = inkex.DirectedLineSegment(next, prev) - if point in sharp_edges: - end = point - elif not end.length == 0: - end = end.parallel(*point).point_at_length(end.length - length) - else: - end = end.start + handle_position_end = self._get_handle_position(point, end, sharp_edges, length) # generate curves - path_commands.append(inkex.paths.Curve(*start, *end, *point)) + path_commands.append(inkex.paths.Curve(*handle_position_start, *handle_position_end, *point)) # recalculate rungs for zigzag pattern if self.options.pattern == 'zigzag' and i <= len(r) and (not self.options.reduce_rungs or j == 0): @@ -178,7 +168,7 @@ class ZigzagLineToSatin(InkstitchExtension): line = inkex.DirectedLineSegment(rung[0], rung[1]) point0 = line.point_at_length(-50) point1 = line.point_at_length(line.length + 50) - new_point = inkex.bezier.linebezierintersect((point0, point1), [prev, start, end, point]) + new_point = inkex.bezier.linebezierintersect((point0, point1), [prev, handle_position_start, handle_position_end, point]) if new_point: new_rungs.append((rung[k[j]], new_point[0])) else: @@ -187,6 +177,15 @@ class ZigzagLineToSatin(InkstitchExtension): rungs = self._update_rungs(new_rungs, rungs, r, has_equal_rail_point_count) return str(inkex.Path(path_commands)), rungs + def _get_handle_position(self, point, segment, sharp_edges, length): + if point in sharp_edges: + handle_position = point + elif segment.length > 0.0001: + handle_position = segment.parallel(*point).point_at_length(segment.length - length) + else: + handle_position = segment.start + return handle_position + def _update_rungs(self, new_rungs, rungs, r, has_equal_rail_point_count): if self.options.pattern == 'zigzag': rungs = new_rungs diff --git a/lib/lettering/font.py b/lib/lettering/font.py index 50fb804f..f7744eff 100644 --- a/lib/lettering/font.py +++ b/lib/lettering/font.py @@ -16,13 +16,12 @@ from ..elements import SatinColumn, Stroke, nodes_to_elements from ..exceptions import InkstitchException from ..extensions.lettering_custom_font_dir import get_custom_font_dir from ..i18n import _, get_languages -from ..marker import (MARKER, ensure_marker_symbols, has_marker, - is_grouped_with_marker) +from ..marker import ensure_marker_symbols, has_marker, is_grouped_with_marker from ..stitches.auto_satin import auto_satin from ..svg.clip import get_clips from ..svg.tags import (CONNECTION_END, CONNECTION_START, EMBROIDERABLE_TAGS, INKSCAPE_LABEL, INKSTITCH_ATTRIBS, SVG_GROUP_TAG, - SVG_PATH_TAG, SVG_USE_TAG, XLINK_HREF) + SVG_PATH_TAG) from ..utils import Point from .font_variant import FontVariant |
