summaryrefslogtreecommitdiff
path: root/lib/extensions/convert_to_satin.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2020-03-18 22:54:25 -0400
committerLex Neva <github.com@lexneva.name>2020-03-18 22:54:25 -0400
commitbabd4884ddc7a3f0d6a47f52e5e3c27ddfda10be (patch)
tree1bc6a9de7f1f1009aea5d698131f943f7a8c002e /lib/extensions/convert_to_satin.py
parentd52373a32a503aba5ec62d6313a4335c5321f989 (diff)
avoid math domain error
Diffstat (limited to 'lib/extensions/convert_to_satin.py')
-rw-r--r--lib/extensions/convert_to_satin.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/extensions/convert_to_satin.py b/lib/extensions/convert_to_satin.py
index c666b625..cf292281 100644
--- a/lib/extensions/convert_to_satin.py
+++ b/lib/extensions/convert_to_satin.py
@@ -164,6 +164,13 @@ class ConvertToSatin(InkstitchExtension):
# The dot product of two vectors is |v1| * |v2| * cos(angle).
# These are unit vectors, so their magnitudes are 1.
cos_angle_between = prev_direction * direction
+
+ # Clamp to the valid range for a cosine. The above _should_
+ # already be in this range, but floating point inaccuracy can
+ # push it outside the range causing math.acos to throw
+ # ValueError ("math domain error").
+ cos_angle_between = max(-1.0, min(1.0, cos_angle_between))
+
angle = abs(math.degrees(math.acos(cos_angle_between)))
# Use the square of the angle, measured in degrees.