Fixed Vector[2|3]::Normalize returning NaN for zero vectors
Former-commit-id: e849a14189ff178134358d4ceed87955bc9f8eae
This commit is contained in:
parent
b413727a21
commit
4acd61cf30
|
|
@ -150,11 +150,13 @@ NzVector2<T>& NzVector2<T>::Minimize(const NzVector2& vec)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
NzVector2<T>& NzVector2<T>::Normalize(T* length)
|
NzVector2<T>& NzVector2<T>::Normalize(T* length)
|
||||||
{
|
{
|
||||||
T norm = std::sqrt(GetSquaredLength());
|
T norm = GetLength();
|
||||||
T invNorm = F(1.0) / norm;
|
if (norm > F(0.0))
|
||||||
|
{
|
||||||
x *= invNorm;
|
T invNorm = F(1.0) / norm;
|
||||||
y *= invNorm;
|
x *= invNorm;
|
||||||
|
y *= invNorm;
|
||||||
|
}
|
||||||
|
|
||||||
if (length)
|
if (length)
|
||||||
*length = norm;
|
*length = norm;
|
||||||
|
|
|
||||||
|
|
@ -231,11 +231,13 @@ template<typename T>
|
||||||
NzVector3<T>& NzVector3<T>::Normalize(T* length)
|
NzVector3<T>& NzVector3<T>::Normalize(T* length)
|
||||||
{
|
{
|
||||||
T norm = GetLength();
|
T norm = GetLength();
|
||||||
T invNorm = F(1.0) / norm;
|
if (norm > F(0.0))
|
||||||
|
{
|
||||||
x *= invNorm;
|
T invNorm = F(1.0) / norm;
|
||||||
y *= invNorm;
|
x *= invNorm;
|
||||||
z *= invNorm;
|
y *= invNorm;
|
||||||
|
z *= invNorm;
|
||||||
|
}
|
||||||
|
|
||||||
if (length)
|
if (length)
|
||||||
*length = norm;
|
*length = norm;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue