Skip to content

Commit

Permalink
math/seadVector2: Implement dot, cross, squaredLength
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsterDruide1 committed Jun 18, 2024
1 parent ae518fa commit 4965eec
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/math/seadVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ struct Vector2 : public Policies<T>::Vec2Base
void set(const Vector2& other);
void set(T x_, T y_);

T dot(const Vector2& other) const;
T cross(const Vector2& other) const;
T length() const;
T squaredLength() const;

bool isZero() const { return *this == zero; }

static const Vector2 zero;
Expand Down
18 changes: 18 additions & 0 deletions include/math/seadVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,30 @@ inline void Vector2<T>::set(T x_, T y_)
Vector2CalcCommon<T>::set(*this, x_, y_);
}

template <typename T>
inline T Vector2<T>::dot(const Vector2<T>& t) const
{
return Vector2CalcCommon<T>::dot(*this, t);
}

template <typename T>
inline T Vector2<T>::cross(const Vector2<T>& t) const
{
return Vector2CalcCommon<T>::cross(*this, t);
}

template <typename T>
inline T Vector2<T>::length() const
{
return Vector2CalcCommon<T>::length(*this);
}

template <typename T>
inline T Vector2<T>::squaredLength() const
{
return Vector2CalcCommon<T>::squaredLength(*this);
}

template <typename T>
inline Vector3<T>::Vector3(T x_, T y_, T z_)
{
Expand Down
2 changes: 2 additions & 0 deletions include/math/seadVectorCalcCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Vector2CalcCommon
static void set(Base& o, const Base& v);
static void set(Base& v, T x, T y);

static T dot(const Base& a, const Base& b);
static T cross(const Base& a, const Base& b);
static T squaredLength(const Base& v);
static T length(const Base& v);
};
Expand Down
12 changes: 12 additions & 0 deletions include/math/seadVectorCalcCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ inline void Vector2CalcCommon<T>::set(Base& v, T x, T y)
v.y = y;
}

template <typename T>
inline T Vector2CalcCommon<T>::dot(const Base& a, const Base& b)
{
return a.x * b.x + a.y * b.y;
}

template <typename T>
inline T Vector2CalcCommon<T>::cross(const Base& a, const Base& b)
{
return a.x * b.y - a.y * b.x;
}

template <typename T>
inline T Vector2CalcCommon<T>::squaredLength(const Base& v)
{
Expand Down

0 comments on commit 4965eec

Please sign in to comment.