Renamed Vector[i]::[Squared]Length[f] to Get[*]

Also added length pointer parameter to Vector[i]::GetNormal


Former-commit-id: 345ebd14bda9f5e0a3843e7603eb7a1a39667db1
This commit is contained in:
Lynix 2013-02-21 11:29:35 +01:00
parent 2828ced694
commit a9b538de20
7 changed files with 56 additions and 47 deletions

View File

@ -62,7 +62,7 @@ template<typename T>
T NzSphere<T>::Distance(T X, T Y, T Z) const
{
NzVector3<T> distance(X-x, Y-y, Z-z);
return distance.Length() - radius;
return distance.GetLength() - radius;
}
template<typename T>

View File

@ -28,10 +28,10 @@ class NzVector2
T DotProduct(const NzVector2& vec) const;
NzVector2 GetNormal() const;
T Length() const;
float Lengthf() const;
T GetLength() const;
float GetLengthf() const;
NzVector2 GetNormal(T* length = nullptr) const;
T GetSquaredLength() const;
NzVector2& MakeUnitX();
NzVector2& MakeUnitY();
@ -49,7 +49,6 @@ class NzVector2
template<typename U> NzVector2& Set(const NzVector2<U>& vec);
T SquaredDistance(const NzVector2& vec) const;
T SquaredLength() const;
NzString ToString() const;

View File

@ -73,24 +73,30 @@ T NzVector2<T>::DotProduct(const NzVector2& vec) const
}
template<typename T>
NzVector2<T> NzVector2<T>::GetNormal() const
T NzVector2<T>::GetLength() const
{
return std::sqrt(GetSquaredLength());
}
template<typename T>
float NzVector2<T>::GetLengthf() const
{
return std::sqrt(static_cast<float>(GetSquaredLength()));
}
template<typename T>
NzVector2<T> NzVector2<T>::GetNormal(T* length) const
{
NzVector2 vec(*this);
vec.Normalize();
vec.Normalize(length);
return vec;
}
template<typename T>
T NzVector2<T>::Length() const
T NzVector2<T>::GetSquaredLength() const
{
return std::sqrt(SquaredLength());
}
template<typename T>
float NzVector2<T>::Lengthf() const
{
return std::sqrt(static_cast<float>(SquaredLength()));
return x*x + y*y;
}
template<typename T>
@ -138,7 +144,7 @@ NzVector2<T>& NzVector2<T>::Minimize(const NzVector2& vec)
template<typename T>
NzVector2<T>& NzVector2<T>::Normalize(T* length)
{
T norm = std::sqrt(SquaredLength());
T norm = std::sqrt(GetSquaredLength());
T invNorm = F(1.0) / length;
x *= invNorm;
@ -197,13 +203,7 @@ NzVector2<T>& NzVector2<T>::Set(const NzVector2<U>& vec)
template<typename T>
T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
{
return operator-(vec).SquaredLength();
}
template<typename T>
T NzVector2<T>::SquaredLength() const
{
return x*x + y*y;
return operator-(vec).GetSquaredLength();
}
template<typename T>

View File

@ -31,10 +31,10 @@ template<typename T> class NzVector3
T DotProduct(const NzVector3& vec) const;
NzVector3 GetNormal() const;
T Length() const;
float Lengthf() const;
T GetLength() const;
float GetLengthf() const;
NzVector3 GetNormal(T* length = nullptr) const;
T GetSquaredLength() const;
NzVector3& MakeForward();
NzVector3& MakeLeft();
@ -57,7 +57,6 @@ template<typename T> class NzVector3
template<typename U> NzVector3& Set(const NzVector3<U>& vec);
T SquaredDistance(const NzVector3& vec) const;
T SquaredLength() const;
NzString ToString() const;

View File

@ -85,24 +85,30 @@ T NzVector3<T>::DotProduct(const NzVector3& vec) const
}
template<typename T>
NzVector3<T> NzVector3<T>::GetNormal() const
T NzVector3<T>::GetLength() const
{
return std::sqrt(GetSquaredLength());
}
template<typename T>
float NzVector3<T>::GetLengthf() const
{
return std::sqrt(static_cast<float>(GetSquaredLength()));
}
template<typename T>
NzVector3<T> NzVector3<T>::GetNormal(T* length) const
{
NzVector3 vec(*this);
vec.Normalize();
vec.Normalize(length);
return vec;
}
template<typename T>
T NzVector3<T>::Length() const
T NzVector3<T>::GetSquaredLength() const
{
return std::sqrt(SquaredLength());
}
template<typename T>
float NzVector3<T>::Lengthf() const
{
return std::sqrt(static_cast<float>(SquaredLength()));
return x*x + y*y + z*z;
}
template<typename T>
@ -180,7 +186,7 @@ NzVector3<T>& NzVector3<T>::Minimize(const NzVector3& vec)
template<typename T>
NzVector3<T>& NzVector3<T>::Normalize(T* length)
{
T norm = Length();
T norm = GetLength();
T invNorm = F(1.0) / norm;
x *= invNorm;
@ -253,13 +259,7 @@ NzVector3<T>& NzVector3<T>::Set(const NzVector3<U>& vec)
template<typename T>
T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
{
return operator-(vec).SquaredLength();
}
template<typename T>
T NzVector3<T>::SquaredLength() const
{
return x*x + y*y + z*z;
return operator-(vec).GetSquaredLength();
}
template<typename T>

View File

@ -26,6 +26,8 @@ template<typename T> class NzVector4
T DotProduct(const NzVector4& vec) const;
NzVector4 GetNormal(T* length = nullptr) const;
NzVector4& MakeUnitX();
NzVector4& MakeUnitY();
NzVector4& MakeUnitZ();

View File

@ -67,6 +67,15 @@ T NzVector4<T>::DotProduct(const NzVector4& vec) const
return x*vec.x + y*vec.y + z*vec.z + w*vec.w;
}
template<typename T>
NzVector4<T> NzVector4<T>::GetNormal(T* length) const
{
NzVector4<T> vec(*this);
vec.Normalize(length);
return vec;
}
template<typename T>
NzVector4<T>& NzVector4<T>::MakeUnitX()
{