Skip to content

Commit

Permalink
bug fix for some inputs into angle proc
Browse files Browse the repository at this point in the history
  • Loading branch information
lilkeet committed Jul 27, 2024
1 parent c2aa045 commit aee0c31
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vmath.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit aee0c31

Please sign in to comment.