Add Unit for vector2
Former-commit-id: 4a143363f24e08d0be12a5ef6bfb46c71b11be4a
This commit is contained in:
@@ -105,6 +105,12 @@ T NzVector2<T>::GetSquaredLength() const
|
||||
return x*x + y*y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T>& NzVector2<T>::MakeUnit()
|
||||
{
|
||||
return Set(F(1.0), F(1.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T>& NzVector2<T>::MakeUnitX()
|
||||
{
|
||||
@@ -129,7 +135,7 @@ NzVector2<T>& NzVector2<T>::Maximize(const NzVector2& vec)
|
||||
if (vec.x > x)
|
||||
x = vec.x;
|
||||
|
||||
if (vec.y > y)
|
||||
if (vec.y > y)
|
||||
y = vec.y;
|
||||
|
||||
return *this;
|
||||
@@ -141,7 +147,7 @@ NzVector2<T>& NzVector2<T>::Minimize(const NzVector2& vec)
|
||||
if (vec.x < x)
|
||||
x = vec.x;
|
||||
|
||||
if (vec.y < y)
|
||||
if (vec.y < y)
|
||||
y = vec.y;
|
||||
|
||||
return *this;
|
||||
@@ -229,7 +235,7 @@ NzVector2<T>& NzVector2<T>::Set(const NzVector4<T>& vec)
|
||||
template<typename T>
|
||||
T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
|
||||
{
|
||||
return operator-(vec).GetSquaredLength();
|
||||
return (*this - vec).GetSquaredLength();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -398,7 +404,7 @@ template<typename T>
|
||||
bool NzVector2<T>::operator==(const NzVector2& vec) const
|
||||
{
|
||||
return NzNumberEquals(x, vec.x) &&
|
||||
NzNumberEquals(y, vec.y);
|
||||
NzNumberEquals(y, vec.y);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -443,6 +449,15 @@ NzVector2<T> NzVector2<T>::Lerp(const NzVector2& from, const NzVector2& to, T in
|
||||
return NzLerp(from, to, interpolation);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T> NzVector2<T>::Unit()
|
||||
{
|
||||
NzVector2 vector;
|
||||
vector.MakeUnit();
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T> NzVector2<T>::UnitX()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user