From 4965eec9649d24de5607b58e671b10ac329d12d2 Mon Sep 17 00:00:00 2001 From: MonsterDruide1 <5958456@gmail.com> Date: Tue, 18 Jun 2024 23:38:44 +0200 Subject: [PATCH] math/seadVector2: Implement dot, cross, squaredLength --- include/math/seadVector.h | 4 ++++ include/math/seadVector.hpp | 18 ++++++++++++++++++ include/math/seadVectorCalcCommon.h | 2 ++ include/math/seadVectorCalcCommon.hpp | 12 ++++++++++++ 4 files changed, 36 insertions(+) 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 713695fb..26b7d2bc 100644 --- a/include/math/seadVector.hpp +++ b/include/math/seadVector.hpp @@ -62,12 +62,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 3f25afcc..752ed244 100644 --- a/include/math/seadVectorCalcCommon.hpp +++ b/include/math/seadVectorCalcCommon.hpp @@ -40,6 +40,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) {