diff --git a/include/math/seadVector.h b/include/math/seadVector.h index f9a66c20..054a8c8d 100644 --- a/include/math/seadVector.h +++ b/include/math/seadVector.h @@ -59,7 +59,11 @@ struct Vector2 : public Policies::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; diff --git a/include/math/seadVector.hpp b/include/math/seadVector.hpp index 6d4abc28..15d4dc39 100644 --- a/include/math/seadVector.hpp +++ b/include/math/seadVector.hpp @@ -63,12 +63,30 @@ inline void Vector2::set(T x_, T y_) Vector2CalcCommon::set(*this, x_, y_); } +template +inline T Vector2::dot(const Vector2& t) const +{ + return Vector2CalcCommon::dot(*this, t); +} + +template +inline T Vector2::cross(const Vector2& t) const +{ + return Vector2CalcCommon::cross(*this, t); +} + template inline T Vector2::length() const { return Vector2CalcCommon::length(*this); } +template +inline T Vector2::squaredLength() const +{ + return Vector2CalcCommon::squaredLength(*this); +} + template inline Vector3::Vector3(T x_, T y_, T z_) { diff --git a/include/math/seadVectorCalcCommon.h b/include/math/seadVectorCalcCommon.h index a024de19..61f8f571 100644 --- a/include/math/seadVectorCalcCommon.h +++ b/include/math/seadVectorCalcCommon.h @@ -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); }; diff --git a/include/math/seadVectorCalcCommon.hpp b/include/math/seadVectorCalcCommon.hpp index f680f8a0..da863f65 100644 --- a/include/math/seadVectorCalcCommon.hpp +++ b/include/math/seadVectorCalcCommon.hpp @@ -39,6 +39,18 @@ inline void Vector2CalcCommon::set(Base& v, T x, T y) v.y = y; } +template +inline T Vector2CalcCommon::dot(const Base& a, const Base& b) +{ + return a.x * b.x + a.y * b.y; +} + +template +inline T Vector2CalcCommon::cross(const Base& a, const Base& b) +{ + return a.x * b.y - a.y * b.x; +} + template inline T Vector2CalcCommon::squaredLength(const Base& v) {