summaryrefslogtreecommitdiff
path: root/lib/stitches/running_stitch.py
diff options
context:
space:
mode:
authorGeorge Steel <george.steel@gmail.com>2023-01-22 17:21:54 -0500
committerGeorge Steel <george.steel@gmail.com>2023-01-22 17:21:54 -0500
commiteb3d6bbcc13d749745271eb0b2a8b6cba938ac19 (patch)
tree33ca2668104cb8d700eed3dd70bb1aba112248a9 /lib/stitches/running_stitch.py
parent5a1ea7d4c7cf2c831b668a4c444c9d3ebe8b89a9 (diff)
fix backtracking case
Diffstat (limited to 'lib/stitches/running_stitch.py')
-rw-r--r--lib/stitches/running_stitch.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/stitches/running_stitch.py b/lib/stitches/running_stitch.py
index a2b8251a..49d29c72 100644
--- a/lib/stitches/running_stitch.py
+++ b/lib/stitches/running_stitch.py
@@ -118,6 +118,8 @@ class AngleInterval():
if self.all:
return None
segArc = AngleInterval.fromSegment(a - origin, b - origin)
+ if segArc is None:
+ return a # b is exactly behind origin from a
if segArc.containsAngle(self.a):
return cut_segment_with_angle(origin, self.a, a, b)
elif segArc.containsAngle(self.b):
@@ -209,15 +211,18 @@ def path_to_curves(points: typing.List[Point]):
# split a path at obvious corner points so that they get stitched exactly
curves = []
last = 0
+ last_seg = points[1] - points[0]
for i in range(1, len(points) - 1):
- a = points[i] - points[i-1]
+ a = last_seg
b = points[i + 1] - points[i]
aabb = (a * a) * (b * b)
- abab = (a * b) * (a * b)
- if aabb > 0.000001 and 2 * abab < aabb:
+ abab = (a * b) * abs(a * b)
+ if aabb > 0 and 2 * abab < aabb:
# inner angle of at most 135 deg
- curves.append(points[last: i+1])
+ curves.append(points[last: i + 1])
last = i
+ if b * b > 0:
+ last_seg = b
curves.append(points[last:])
return curves