summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2023-07-08 21:08:12 -0400
committerLex Neva <github.com@lexneva.name>2023-07-08 21:08:12 -0400
commitf1b63d8efefbcf8923d997cc0da18e4329fbe77e (patch)
treeaaf6cb2696deefed0ed09e74e5b7a63a34a9a3b0
parent6134570ebc60af7727e77282753c160117d5983b (diff)
handle looped paths better
-rw-r--r--lib/extensions/convert_to_satin.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/extensions/convert_to_satin.py b/lib/extensions/convert_to_satin.py
index 7f68734c..03a4d6e4 100644
--- a/lib/extensions/convert_to_satin.py
+++ b/lib/extensions/convert_to_satin.py
@@ -51,7 +51,7 @@ class ConvertToSatin(InkstitchExtension):
path_style = self.path_style(element)
for path in element.paths:
- path = self.remove_duplicate_points(path)
+ path = self.remove_duplicate_points(self.fix_loop(path))
if len(path) < 2:
# ignore paths with just one point -- they're not visible to the user anyway
@@ -102,6 +102,17 @@ class ConvertToSatin(InkstitchExtension):
return halves
+ def fix_loop(self, path):
+ if path[0] == path[-1] and len(path) > 1:
+ first = Point.from_tuple(path[0])
+ second = Point.from_tuple(path[1])
+ midpoint = (first + second) / 2
+ midpoint = midpoint.as_tuple()
+
+ return [midpoint] + path[1:] + [path[0], midpoint]
+ else:
+ return path
+
def remove_duplicate_points(self, path):
path = [[round(coord, 4) for coord in point] for point in path]
return [point for point, repeats in groupby(path)]