Add normalize_safe to avoid a division by zero
Some checks failed
Github Actions / build (1.4.0, ubuntu-latest) (push) Has been cancelled
Github Actions / build (1.4.0, windows-latest) (push) Has been cancelled
Github Actions / build (1.4.x, ubuntu-latest) (push) Has been cancelled
Github Actions / build (1.4.x, windows-latest) (push) Has been cancelled
Github Actions / build (stable, ubuntu-latest) (push) Has been cancelled
Github Actions / build (stable, windows-latest) (push) Has been cancelled

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