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>
|
||||
NzVector2<T>& NzVector2<T>::Normalize(T* length)
|
||||
{
|
||||
T norm = std::sqrt(GetSquaredLength());
|
||||
T invNorm = F(1.0) / norm;
|
||||
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
T norm = GetLength();
|
||||
if (norm > F(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / norm;
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
}
|
||||
|
||||
if (length)
|
||||
*length = norm;
|
||||
|
|
|
|||
|
|
@ -231,11 +231,13 @@ template<typename T>
|
|||
NzVector3<T>& NzVector3<T>::Normalize(T* length)
|
||||
{
|
||||
T norm = GetLength();
|
||||
T invNorm = F(1.0) / norm;
|
||||
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
z *= invNorm;
|
||||
if (norm > F(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / norm;
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
z *= invNorm;
|
||||
}
|
||||
|
||||
if (length)
|
||||
*length = norm;
|
||||
|
|
|
|||
Loading…
Reference in New Issue