Skip to content

Commit

Permalink
make normalize safe
Browse files Browse the repository at this point in the history
normalizing a zero vector returns the zero vector, not a nan
  • Loading branch information
micycle8778 committed Sep 22, 2023
1 parent 7282ae1 commit 1e3668d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/vmath.nim
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@ proc lengthSq*[T](a: GVec4[T]): T =
a.x*a.x + a.y*a.y + a.z*a.z + a.w*a.w

proc normalize*[T](a: GVec234[T]): type(a) =
a / a.length
if (a.length == 0): a
else: a / a.length

proc mix*[T: SomeFloat](a, b: GVec234[T], v: T): type(a) =
a * (1.0 - v) + b * v
Expand Down

0 comments on commit 1e3668d

Please sign in to comment.