Fix polyline tool calculation when dealing with 180 degrees angles.

This commit is contained in:
Bruno Perdigão
2025-05-15 17:40:29 -03:00
parent 92f2559ce0
commit b9a435e1c3
+16
View File
@@ -102,6 +102,10 @@ class Cad:
d1 = v1 - v2
d2 = v3 - v2
# Rounding avoids problems when dealing with 180 degrees
d1 = Vector((round(c, 6) for c in d1))
d2 = Vector((round(c, 6) for c in d2))
d1.normalize()
d2.normalize()
@@ -123,12 +127,24 @@ class Cad:
if new_angle is not None:
rot_mat = Matrix.Rotation(new_angle, 3, axis)
rot_vector = (d1 @ rot_mat) if parameter else (rot_mat @ d1)
# 180 degrees special cases
if abs(round(a, 4)) == round(math.pi, 4) and (
rot_vector.x == 0.0 and rot_vector.y == 0.0 or
rot_vector.x == 0.0 and rot_vector.z == 0.0 or
rot_vector.y == 0.0 and rot_vector.z == 0.0
):
rot_vector *= -1
return rot_vector
else:
sign = -1 if parameter else 1
if degrees:
a = math.degrees(a)
# 180 degrees special cases
if abs(round(a, 2)) == abs(180.00):
return -180.0
return a * sign
else:
return a