From aee0c310fe69aea3078cac446b3193cb6506e692 Mon Sep 17 00:00:00 2001 From: lilkeet Date: Sat, 27 Jul 2024 02:02:49 -0500 Subject: [PATCH] bug fix for some inputs into angle proc --- src/vmath.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vmath.nim b/src/vmath.nim index ed3af08..371d1d2 100644 --- a/src/vmath.nim +++ b/src/vmath.nim @@ -1577,7 +1577,11 @@ proc angle*[T; S: GVec2[T]|GVec3[T]](a, b: S): T = ## Angle between 2 Vec2 or Vec3. var dot = dot(a, b) dot = dot / (a.length * b.length) - arccos(dot) + # The cases of angle((1, 1), (-1, -1)) and its 3d counterpart + # angle((1, 1, 1), (-1, -1, -1)) result in NaN due to a domain defect going + # into the arcos proc: abs(x) > 1.0. + # Therefore, we must `clamp` here. + arccos(dot.clamp(-1.0, 1.0)) type Quat* = GVec4[float32]