From ec63d0c312056545cce7450bfb9e91a7033dac58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Granskogen=20Bj=C3=B8rnstad?= Date: Fri, 10 Nov 2017 13:44:24 +0100 Subject: [PATCH] Arc: Handle round-off issue with acos() math.acos raises outside of valid range [-1, 1]. Handle round-off errors gracefully by using `round()` here too. --- svgpathtools/path.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/svgpathtools/path.py b/svgpathtools/path.py index 41989de..51378fd 100644 --- a/svgpathtools/path.py +++ b/svgpathtools/path.py @@ -1300,10 +1300,13 @@ class Arc(object): # delta is the angular distance of the arc (w.r.t the circle) # theta is the angle between the positive x'-axis and the start point # on the circle + u1_real_rounded = u1.real + if u1.real > 1 or u1.real < -1: + u1_real_rounded = round(u1.real) if u1.imag > 0: - self.theta = degrees(acos(u1.real)) + self.theta = degrees(acos(u1_real_rounded)) elif u1.imag < 0: - self.theta = -degrees(acos(u1.real)) + self.theta = -degrees(acos(u1_real_rounded)) else: if u1.real > 0: # start is on pos u_x axis self.theta = 0