Add Unit for vector2
Former-commit-id: 4a143363f24e08d0be12a5ef6bfb46c71b11be4a
This commit is contained in:
parent
376df6a3b7
commit
2d07922478
|
|
@ -27,12 +27,10 @@ class NzVector2
|
|||
~NzVector2() = default;
|
||||
|
||||
T AbsDotProduct(const NzVector2& vec) const;
|
||||
|
||||
T AngleBetween(const NzVector2& vec) const;
|
||||
|
||||
T Distance(const NzVector2& vec) const;
|
||||
float Distancef(const NzVector2& vec) const;
|
||||
|
||||
T DotProduct(const NzVector2& vec) const;
|
||||
|
||||
T GetLength() const;
|
||||
|
|
@ -40,6 +38,7 @@ class NzVector2
|
|||
NzVector2 GetNormal(T* length = nullptr) const;
|
||||
T GetSquaredLength() const;
|
||||
|
||||
NzVector2& MakeUnit();
|
||||
NzVector2& MakeUnitX();
|
||||
NzVector2& MakeUnitY();
|
||||
NzVector2& MakeZero();
|
||||
|
|
@ -89,6 +88,7 @@ class NzVector2
|
|||
bool operator>=(const NzVector2& vec) const;
|
||||
|
||||
static NzVector2 Lerp(const NzVector2& from, const NzVector2& to, T interpolation);
|
||||
static NzVector2 Unit();
|
||||
static NzVector2 UnitX();
|
||||
static NzVector2 UnitY();
|
||||
static NzVector2 Zero();
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue