diff options
| author | Lex Neva <github.com@lexneva.name> | 2023-07-08 21:02:11 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2023-07-08 21:02:11 -0400 |
| commit | 6134570ebc60af7727e77282753c160117d5983b (patch) | |
| tree | fbb22133fc7a573764ec17a7b7f9c57fd70bac07 /lib | |
| parent | 661ae39546497bd2e4eb48496903405cfe919a18 (diff) | |
split mid-segment to handle corners better
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/extensions/convert_to_satin.py | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/extensions/convert_to_satin.py b/lib/extensions/convert_to_satin.py index 093b301c..7f68734c 100644 --- a/lib/extensions/convert_to_satin.py +++ b/lib/extensions/convert_to_satin.py @@ -81,27 +81,26 @@ class ConvertToSatin(InkstitchExtension): # getting nowhere. Just give up on this section of the path. return - half = int(len(path) / 2.0) - halves = [path[:half + 1], path[half:]] + halves = self.split_path(path) for path in halves: for satin in self.convert_path_to_satins(path, stroke_width, style_args, correction_transform, path_style, depth=depth + 1): yield satin - def fix_loop(self, path): - if path[0] == path[-1]: - # Looping paths seem to confuse shapely's parallel_offset(). It loses track - # of where the start and endpoint is, even if the user explicitly breaks the - # path. I suspect this is because parallel_offset() uses buffer() under the - # hood. - # - # To work around this we'll introduce a tiny gap by nudging the starting point - # toward the next point slightly. - start = Point(*path[0]) - next = Point(*path[1]) - direction = (next - start).unit() - start += 0.01 * direction - path[0] = start.as_tuple() + def split_path(self, path): + half = len(path) // 2 + halves = [path[:half], path[half:]] + + start = Point.from_tuple(halves[0][-1]) + end = Point.from_tuple(halves[1][0]) + + midpoint = (start + end) / 2 + midpoint = midpoint.as_tuple() + + halves[0].append(midpoint) + halves[1] = [midpoint] + halves[1] + + return halves def remove_duplicate_points(self, path): path = [[round(coord, 4) for coord in point] for point in path] |
