Add normalize_safe to avoid a division by zero

This commit is contained in:
Alberto Torres 2024-08-17 02:48:51 +02:00
parent 6a63d64453
commit 2ddb51917c

View file

@ -791,6 +791,12 @@ proc lengthSq*[T](a: GVec4[T]): T =
proc normalize*[T](a: GVec234[T]): type(a) =
a / a.length
proc normalize_safe*[T](a: GVec234[T]): type(a) =
let l = a.length
if l != 0:
return a / l
# else, implicit result is vec(0)
proc mix*[T: SomeFloat](a, b: GVec234[T], v: T): type(a) =
a * (1.0 - v) + b * v