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
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:
parent
6a63d64453
commit
2ddb51917c
|
@ -791,6 +791,12 @@ proc lengthSq*[T](a: GVec4[T]): T =
|
||||||
proc normalize*[T](a: GVec234[T]): type(a) =
|
proc normalize*[T](a: GVec234[T]): type(a) =
|
||||||
a / a.length
|
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) =
|
proc mix*[T: SomeFloat](a, b: GVec234[T], v: T): type(a) =
|
||||||
a * (1.0 - v) + b * v
|
a * (1.0 - v) + b * v
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue