Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/seadVector2: Implement dot, cross, squaredLength #140

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading