From c3f17c817d3b4daea13b880f4d4c6ea95208c4c4 Mon Sep 17 00:00:00 2001 From: scorpioblood <77296181+scorpioblood@users.noreply.github.com> Date: Wed, 5 Jun 2024 21:41:43 +0200 Subject: [PATCH] TIntVector2 setup. --- .../public/Math/Detail/IntVector2Decl.inl | 279 ++++++++++++ .../Runtime/Core/public/Math/IntVector2.hpp | 365 +++++++--------- .../Runtime/Core/public/Math/IntVector2.inl | 403 ++++++++++++++++++ .../Source/Runtime/Core/public/Math/MathFwd.h | 2 +- .../public/Math/SIMD/PhanesVectorMathSSE.hpp | 5 + 5 files changed, 843 insertions(+), 211 deletions(-) create mode 100644 Engine/Source/Runtime/Core/public/Math/Detail/IntVector2Decl.inl create mode 100644 Engine/Source/Runtime/Core/public/Math/IntVector2.inl diff --git a/Engine/Source/Runtime/Core/public/Math/Detail/IntVector2Decl.inl b/Engine/Source/Runtime/Core/public/Math/Detail/IntVector2Decl.inl new file mode 100644 index 0000000..35a45ef --- /dev/null +++ b/Engine/Source/Runtime/Core/public/Math/Detail/IntVector2Decl.inl @@ -0,0 +1,279 @@ +#pragma once + +#include "Core/public/Math/Boilerplate.h" + +namespace Phanes::Core::Math::Detail +{ + template + struct construct_ivec2 {}; + + template + struct compute_ivec2_add {}; + + template + struct compute_ivec2_sub {}; + + template + struct compute_ivec2_mul {}; + + template + struct compute_ivec2_div {}; + + template + struct compute_ivec2_mod {}; + + template + struct compute_ivec2_eq {}; + + template + struct compute_ivec2_ieq {}; + + template + struct compute_ivec2_inc {}; + + template + struct compute_ivec2_dec {}; + + template + struct compute_ivec2_and {}; + + template + struct compute_ivec2_or {}; + + template + struct compute_ivec2_xor {}; + + template + struct compute_ivec2_left_shift {}; + + template + struct compute_ivec2_right_shift {}; + + template + struct compute_ivec2_bnot {}; + + + template + struct construct_ivec2 + { + static constexpr void map(Phanes::Core::Math::TIntVector2& v1, const TIntVector2& v2) + { + v1.x = v2.x; + v1.y = v2.y; + } + + + static constexpr void map(Phanes::Core::Math::TIntVector2& v1, T s) + { + v1.x = s; + v1.y = s; + } + + static constexpr void map(Phanes::Core::Math::TIntVector2& v1, T x, T y) + { + v1.x = x; + v1.y = y; + } + + + static constexpr void map(Phanes::Core::Math::TIntVector2& v1, const T* comp) + { + v1.x = comp[0]; + v1.y = comp[1]; + } + }; + + + template + struct compute_ivec2_add + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x + v2.x; + r.y = v1.y + v2.y; + } + + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, T s) + { + r.x = v1.x + s; + r.y = v1.y + s; + } + }; + + + template + struct compute_ivec2_sub + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x - v2.x; + r.y = v1.y - v2.y; + } + + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, T s) + { + r.x = v1.x - s; + r.y = v1.y - s; + } + }; + + + template + struct compute_ivec2_mul + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x * v2.x; + r.y = v1.y * v2.y; + } + + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, T s) + { + r.x = v1.x * s; + r.y = v1.y * s; + } + }; + + + template + struct compute_ivec2_div + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x / v2.x; + r.y = v1.y / v2.y; + } + + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, T s) + { + s = (T)1.0 / s; + + r.x = v1.x * s; + r.y = v1.y * s; + } + }; + + template + struct compute_ivec2_mod + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x % v2.x; + r.y = v1.y % v2.y; + } + + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, T s) + { + r.x = v1.x % s; + r.y = v1.y % s; + } + }; + + template + struct compute_ivec2_eq + { + static constexpr bool map(const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC && + Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC); + } + }; + + template + struct compute_ivec2_ieq + { + static constexpr bool map(const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC || + Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC); + } + }; + + template + struct compute_ivec2_inc + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1) + { + r.x = v1.x + 1; + r.y = v1.y + 1; + } + }; + + template + struct compute_ivec2_dec + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1) + { + r.x = v1.x - 1; + r.y = v1.y - 1; + } + }; + + + template + struct compute_ivec2_and + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x & v2.x; + r.y = v1.y & v2.y; + } + + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, T s) + { + r.x = v1.x & s; + r.y = v1.y & s; + } + }; + + template + struct compute_ivec2_or + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x | v2.x; + r.y = v1.y | v2.y; + } + }; + + template + struct compute_ivec2_xor + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x ^ v2.x; + r.y = v1.y ^ v2.y; + } + }; + + template + struct compute_ivec2_left_shift + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x << v2.x; + r.y = v1.y << v2.y; + } + }; + + template + struct compute_ivec2_right_shift + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) + { + r.x = v1.x >> v2.x; + r.y = v1.y >> v2.y; + } + }; + + template + struct compute_ivec2_bnot + { + static constexpr void map(Phanes::Core::Math::TIntVector2& r, const Phanes::Core::Math::TIntVector2& v1) + { + r.x = ~v1.x; + r.y = ~v1.y; + } + }; +} + diff --git a/Engine/Source/Runtime/Core/public/Math/IntVector2.hpp b/Engine/Source/Runtime/Core/public/Math/IntVector2.hpp index 6867ea5..3b048d5 100644 --- a/Engine/Source/Runtime/Core/public/Math/IntVector2.hpp +++ b/Engine/Source/Runtime/Core/public/Math/IntVector2.hpp @@ -3,9 +3,10 @@ #include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathCommon.hpp" -#include "Core/public/Math/MathAbstractTypes.h" #include "Core/public/Math/MathFwd.h" +#include "Core/public/Math/SIMD/Storage.h" + #ifndef P_DEBUG #pragma warning(disable : 4244) #endif @@ -32,7 +33,7 @@ namespace Phanes::Core::Math { * A 2D Vector with components x and y with integer precision. */ - template + template struct TIntVector2 { static_assert(std::is_integral_v, "T must be an integer type."); @@ -70,7 +71,11 @@ namespace Phanes::Core::Math { * @note Components are split into x and y. Access and manipulation is possible by these variables. */ - T comp[2]; + union + { + typename SIMD::Storage<2, T, SIMD::use_simd::value>::type comp; + typename SIMD::Storage<2, T, SIMD::use_simd::value>::type data; + }; }; @@ -89,27 +94,7 @@ namespace Phanes::Core::Math { * Copy constructor */ - TIntVector2(const TIntVector2& v) - { - memcpy(this->comp, comp, sizeof(T) * 2); - } - - /** - * Move constructor - */ - - TIntVector2(TIntVector2&& v) - { - this->comp = v.comp; - v.comp = nullptr; - } - - /** - * Convert other type of vector - */ - - template - explicit TIntVector2(const TIntVector2& v) : x((T)v.x), y((T)v.y) {}; + TIntVector2(const TIntVector2& v); /** * Construct Vector from xy components. @@ -118,11 +103,7 @@ namespace Phanes::Core::Math { * @param y Y component */ - TIntVector2(const T x, const T y) - { - this->x = x; - this->y = y; - } + TIntVector2(const T x, const T y); /** * Construct Vector from two component array. @@ -130,10 +111,7 @@ namespace Phanes::Core::Math { * @param comp Array of components */ - TIntVector2(const T* comp) - { - memcpy(this->comp, comp, sizeof(T) * 2); - } + TIntVector2(const T* comp); /** * Construct Vector from 3D integer Vector's xy. @@ -141,110 +119,65 @@ namespace Phanes::Core::Math { * @param v 3D IntVector to copy from */ - TIntVector2(const TIntVector3& v) - { - this->x = v.x; - this->y = v.y; - } - - /** - * Constructs a vector pointing from start to end. - * - * @param(start) Startingpoint - * @param(end) Endpoint - */ - - TIntVector2(const TIntPoint2& start, const TIntPoint2& end) - { - this->x = end.x - start.x; - this->y = end.y - start.y; - } + TIntVector2(const T s); }; + + // ======================== // // IntVector2 operators // // ======================== // - - + /** - * Addition operation on same TIntVector2 (this) by a floating point value. + * Addition operation on same TIntVector2 (this) by a floating point value. * * @param(v1) Vector to add to * @param(s) Floating point to add */ - template - TIntVector2 operator+= (TIntVector2& v1, T s) - { - v1.x += s; - v1.y += s; - - return v1; - } + template + TIntVector2 operator+= (TIntVector2& v1, T s); /** - * Addition operation on same TIntVector2 (this) by a another TIntVector2. + * Addition operation on same TIntVector2 (this) by a another TIntVector2. * * @param(v1) Vector to add to * @param(v2) Vector to add */ - template - TIntVector2 operator+= (TIntVector2& v1, const TIntVector2& v2) - { - v1.x += v2.x; - v1.y += v2.y; - - return v1; - } + template + TIntVector2 operator+= (TIntVector2& v1, const TIntVector2& v2); /** - * Substraction operation on same TIntVector2 (this) by a floating point. + * Substraction operation on same TIntVector2 (this) by a floating point. * * @param(v1) Vector to substract from * @param(v2) Floating point to substract */ - template - TIntVector2 operator-= (TIntVector2& v1, T s) - { - v1.x -= s; - v1.y -= s; - - return v1; - } + template + TIntVector2 operator-= (TIntVector2& v1, T s); /** - * Substraction operation on same TIntVector2 (this) by a another TIntVector2. + * Substraction operation on same TIntVector2 (this) by a another TIntVector2. * * @param(v1) Vector to substract from * @param(v2) Vector to substract */ - template - TIntVector2 operator-= (TIntVector2& v1, const TIntVector2& v2) - { - v1.x -= v2.x; - v1.y -= v2.y; - - return v1; - } + template + TIntVector2 operator-= (TIntVector2& v1, const TIntVector2& v2); + /** - * Multiplication of TIntVector2 (this) with a floating point. + * Multiplication of TIntVector2 (this) with a floating point. * * @param(v1) Vector to multiply with * @param(s Floating point to multiply with */ - template - TIntVector2 operator*= (TIntVector2& v1, T s) - { - v1.x *= s; - v1.y *= s; - - return v1; - } + template + TIntVector2 operator*= (TIntVector2& v1, T s); /** * Devision of Vector @@ -255,16 +188,8 @@ namespace Phanes::Core::Math { * @note Result is rounded (obviously) */ - template - TIntVector2 operator/= (TIntVector2& v1, T s) - { - float _1_s = 1.0f; - - v1.x *= _1_s; - v1.y *= _1_s; - - return v1; - } + template + TIntVector2 operator/= (TIntVector2& v1, T s); /** * Stores the remainder of division by a scalar. @@ -273,17 +198,44 @@ namespace Phanes::Core::Math { * @param(s) Scalar to divide with */ - template - TIntVector2 operator%= (TIntVector2& v1, T s) - { - v1.x %= s; - v1.y %= s; + template + TIntVector2 operator%= (TIntVector2& v1, const TIntVector2& v2); - return v1; - } + template + TIntVector2 operator%= (TIntVector2& v1, T s); + + template + inline TIntVector2 operator&= (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator&= (TIntVector2& v1, T s); + + template + inline TIntVector2 operator|= (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator|= (TIntVector2& v1, T s); + + template + inline TIntVector2 operator^= (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator^= (TIntVector2& v1, T s); + + template + inline TIntVector2 operator<<= (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator<<= (TIntVector2& v1, T s); + + template + inline TIntVector2 operator>>= (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator>>= (TIntVector2& v1, T s); /** - * Scale of Vector by floating point. (> Creates a new TIntVector2) + * Scale of Vector by floating point. (> Creates a new TIntVector2) * * @param(v1) Vector to multiply with * @param(s Floating point to multiply with @@ -291,14 +243,11 @@ namespace Phanes::Core::Math { * @return Result Vector */ - template - TIntVector2 operator* (const TIntVector2& v1, T s) - { - return TIntVector2(v1.x * s, v1.y * s); - } + template + TIntVector2 operator* (const TIntVector2& v1, T s); /** - * Division of Vector by floating point. (> Creates another TIntVector2) + * Division of Vector by floating point. (> Creates another TIntVector2) * * @see [FUNC]DivideFloat * @@ -309,15 +258,11 @@ namespace Phanes::Core::Math { * @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading. */ - template - TIntVector2 operator/ (const TIntVector2& v1, T s) - { - float _1_s = 1.0f; - return TIntVector2(v1.x * _1_s, v1.y * _1_s); - } + template + TIntVector2 operator/ (const TIntVector2& v1, T s); /** - * Scale of Vector by floating point. (> Creates a new TIntVector2) + * Scale of Vector by floating point. (> Creates a new TIntVector2) * * @param(v1) Vector to multiply with * @param(s Floating point to multiply with @@ -325,11 +270,8 @@ namespace Phanes::Core::Math { * @return Result Vector */ - template - FORCEINLINE TIntVector2 operator* (T s, const TIntVector2& v1) - { - return v1 * s; - } + template + FORCEINLINE TIntVector2 operator* (T s, const TIntVector2& v1) { return v1 * s; }; /** * Division of Vector by floating point. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.) @@ -344,11 +286,8 @@ namespace Phanes::Core::Math { * @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading. */ - template - FORCEINLINE TIntVector2 operator/ (T s, const TIntVector2& v1) - { - return v1 / s; - } + template + FORCEINLINE TIntVector2 operator/ (T s, const TIntVector2& v1) { return v1 / s; }; /** * Dot product between two Vectors. @@ -361,11 +300,8 @@ namespace Phanes::Core::Math { * @result Dot product */ - template - T operator* (const TIntVector2& v1, const TIntVector2& v2) - { - return v1.x * v2.x + v1.y * v2.y; - } + template + T operator* (const TIntVector2& v1, const TIntVector2& v2); /** * Componentwise addition of Vector with floating point. @@ -376,11 +312,8 @@ namespace Phanes::Core::Math { * @return Result Vector */ - template - TIntVector2 operator+ (const TIntVector2& v1, T s) - { - return TIntVector2(v1.x + s, v1.y + s); - } + template + TIntVector2 operator+ (const TIntVector2& v1, T s); /** * Componentwise addition of Vector with floating point. @@ -391,11 +324,8 @@ namespace Phanes::Core::Math { * @return Result Vector */ - template - TIntVector2 operator+ (const TIntVector2& v1, const TIntVector2& v2) - { - return TIntVector2(v1.x + v2.x, v1.y + v2.y); - } + template + TIntVector2 operator+ (const TIntVector2& v1, const TIntVector2& v2); /** * Componentwise substraction of Vector with floating point. @@ -406,11 +336,8 @@ namespace Phanes::Core::Math { * @return Result Vector */ - template - TIntVector2 operator- (const TIntVector2& v1, T s) - { - return TIntVector2(v1.x - s, v1.y - s); - } + template + TIntVector2 operator- (const TIntVector2& v1, T s); /** * Componentwise substraction of Vector with Vector. @@ -421,14 +348,14 @@ namespace Phanes::Core::Math { * @return Result Vector */ - template - TIntVector2 operator- (const TIntVector2& v1, const TIntVector2& v2) - { - return TIntVector2(v1.x - v2.x, v1.y - v2.y); - } + template + TIntVector2 operator- (const TIntVector2& v1, const TIntVector2& v2); + + + /** - * Scale of Vector by floating point. (> Creates a new TIntVector2) + * Scale of Vector by floating point. (> Creates a new TIntVector2) * * @param(v1) Vector to multiply with * @param(s Floating point to multiply with @@ -436,24 +363,47 @@ namespace Phanes::Core::Math { * @return Result Vector */ - template - FORCEINLINE TIntVector2 operator% (const TIntVector2& v1, T s) - { - return TIntVector2(v1.x % s, v1.y % s); - } + template + FORCEINLINE TIntVector2 operator% (const TIntVector2& v1, const TIntVector2& v2); - /** - * Negate Vector. - * - * @param(v1) Vector to negate - */ + template + FORCEINLINE TIntVector2 operator% (const TIntVector2& v1, T s); + + + + template + inline TIntVector2 operator& (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator& (TIntVector2& v1, T s); + + template + inline TIntVector2 operator| (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator| (TIntVector2& v1, T s); + + template + inline TIntVector2 operator^ (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator^ (TIntVector2& v1, T s); + + template + inline TIntVector2 operator<< (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator<< (TIntVector2& v1, T s); + + template + inline TIntVector2 operator>> (TIntVector2& v1, const TIntVector2& v2); + + template + inline TIntVector2 operator>> (TIntVector2& v1, T s); + + template + inline TIntVector2 operator~ (TIntVector2& v1); - template - void operator- (TIntVector2& v1) - { - v1.x = -v1.x; - v1.y = -v1.y; - } /** * Compare Vector for equality. @@ -465,11 +415,8 @@ namespace Phanes::Core::Math { * @return true if equal, false if inequal */ - template - bool operator== (const TIntVector2& v1, const TIntVector2& v2) - { - return (abs(v1.x - v1.x) < P_FLT_INAC && abs(v1.y - v1.y) < P_FLT_INAC); - } + template + bool operator== (const TIntVector2& v1, const TIntVector2& v2); /** @@ -482,18 +429,15 @@ namespace Phanes::Core::Math { * @return true if inequal, false if equal */ - template - bool operator!= (const TIntVector2& v1, const TIntVector2& v2) - { - return (abs(v1.x - v1.x) > P_FLT_INAC || abs(v1.y - v1.y) > P_FLT_INAC); - } + template + bool operator!= (const TIntVector2& v1, const TIntVector2& v2); // ============================================== // // TIntVector2 static function implementation // // ============================================== // template - TIntVector2 MaxV(TIntVector2& v1, const TIntVector2& v2) + TIntVector2 MaxV(TIntVector2& v1, const TIntVector2& v2) { v1.x = Phanes::Core::Math::Max(v1.x, v2.x); v1.y = Phanes::Core::Math::Max(v1.y, v2.y); @@ -511,7 +455,7 @@ namespace Phanes::Core::Math { */ template - TIntVector2 MinV(TIntVector2& v1, const TIntVector2& v2) + TIntVector2 MinV(TIntVector2& v1, const TIntVector2& v2) { v1.x = Phanes::Core::Math::Min(v1.x, v2.x); v1.y = Phanes::Core::Math::Min(v1.y, v2.y); @@ -520,7 +464,7 @@ namespace Phanes::Core::Math { } template - TIntVector2 SignVectorV(TIntVector2& v1) + TIntVector2 SignVectorV(TIntVector2& v1) { v1.x = (v1.x >= 0) ? 1 : -1; v1.y = (v1.y >= 0) ? 1 : -1; @@ -538,7 +482,7 @@ namespace Phanes::Core::Math { */ template - TIntVector2 ScaleV(TIntVector2& v1, const TIntVector2& v2) + TIntVector2 ScaleV(TIntVector2& v1, const TIntVector2& v2) { v1.x *= v2.x; v1.y *= v2.y; @@ -554,7 +498,7 @@ namespace Phanes::Core::Math { */ template - TIntVector2 Set(TIntVector2& v1, const TIntVector2& v2) + TIntVector2 Set(TIntVector2& v1, const TIntVector2& v2) { v1 = v2; @@ -569,7 +513,7 @@ namespace Phanes::Core::Math { */ template - TIntVector2 Set(TIntVector2& v1, T x, T y) + TIntVector2 Set(TIntVector2& v1, T x, T y) { v1.x = x; v1.y = y; @@ -585,7 +529,7 @@ namespace Phanes::Core::Math { */ template - TIntVector2 NegateV(TIntVector2& v1) + TIntVector2 NegateV(TIntVector2& v1) { v1.x = -v1.x; v1.y = -v1.y; @@ -603,7 +547,7 @@ namespace Phanes::Core::Math { */ template - inline bool IsPerpendicular(const TIntVector2& v1, const TIntVector2& v2) + inline bool IsPerpendicular(const TIntVector2& v1, const TIntVector2& v2) { return (abs(DotP(v1, v2)) = 0); } @@ -620,7 +564,7 @@ namespace Phanes::Core::Math { */ template - inline bool IsParallel(const TIntVector2& v1, const TIntVector2& v2) + inline bool IsParallel(const TIntVector2& v1, const TIntVector2& v2) { return (abs(DotP(v1, v2)) = 1); } @@ -637,7 +581,7 @@ namespace Phanes::Core::Math { */ template - inline bool IsCoincident(const TIntVector2& v1, const TIntVector2& v2) + inline bool IsCoincident(const TIntVector2& v1, const TIntVector2& v2) { return (DotP(v1, v2) > 1); } @@ -652,7 +596,7 @@ namespace Phanes::Core::Math { */ //template - //Matrix2 OuterProduct(const TIntVector2& v1, const TIntVector2& v2); + //Matrix2 OuterProduct(const TIntVector2& v1, const TIntVector2& v2); // ================================================================ // @@ -669,9 +613,9 @@ namespace Phanes::Core::Math { */ template - TIntVector2 Negate(const TIntVector2& v1) + TIntVector2 Negate(const TIntVector2& v1) { - return TIntVector2(-v1.x, -v1.y); + return TIntVector2(-v1.x, -v1.y); } /** @@ -684,9 +628,9 @@ namespace Phanes::Core::Math { */ template - TIntVector2 Min(const TIntVector2& v1, const TIntVector2& v2) + TIntVector2 Min(const TIntVector2& v1, const TIntVector2& v2) { - return TIntVector2(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y)); + return TIntVector2(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y)); } /** @@ -699,16 +643,16 @@ namespace Phanes::Core::Math { */ template - TIntVector2 Max(const TIntVector2& v1, const TIntVector2& v2) + TIntVector2 Max(const TIntVector2& v1, const TIntVector2& v2) { - return TIntVector2(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y)); + return TIntVector2(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y)); } template - TIntVector2 SignVector(const TIntVector2& v1) + TIntVector2 SignVector(const TIntVector2& v1) { - return TIntVector2((v1.x >= 0) ? 1 : -1, (v1.y >= 0) ? 1 : -1); + return TIntVector2((v1.x >= 0) ? 1 : -1, (v1.y >= 0) ? 1 : -1); } @@ -716,3 +660,4 @@ namespace Phanes::Core::Math { #endif // !INTVECTOR2_H +#include "Core/public/Math/IntVector2.inl" \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/public/Math/IntVector2.inl b/Engine/Source/Runtime/Core/public/Math/IntVector2.inl new file mode 100644 index 0000000..0d7466c --- /dev/null +++ b/Engine/Source/Runtime/Core/public/Math/IntVector2.inl @@ -0,0 +1,403 @@ +#pragma once + +#include "Core/public/Math/Boilerplate.h" + +#include "Core/public/Math/Detail/IntVector2Decl.inl" +#include "Core/public/Math/SIMD/SIMDIntrinsics.h" + +#include "Core/public/Math/SIMD/PhanesSIMDTypes.h" + +#include "Core/public/Math/IntVector2.hpp" + +namespace Phanes::Core::Math +{ + template + TIntVector2::TIntVector2(const TIntVector2& v) + { + Detail::construct_ivec2::value>::map(*this, v); + } + + template + TIntVector2::TIntVector2(const T _x, const T _y) + { + Detail::construct_ivec2::value>::map(*this, _x, _y); + } + + template + TIntVector2::TIntVector2(const T s) + { + Detail::construct_ivec2::value>::map(*this, s); + } + + template + TIntVector2::TIntVector2(const T* comp) + { + Detail::construct_ivec2::value>::map(*this, comp); + } + + + + + template + TIntVector2 operator+=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_add::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator+=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_add::value>::map(v1, v1, s); + return v1; + } + + template + TIntVector2 operator-=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_sub::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator-=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_sub::value>::map(v1, v1, s); + return v1; + } + + template + TIntVector2 operator*=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_mul::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator*=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_mul::value>::map(v1, v1, s); + return v1; + } + + template + TIntVector2 operator/=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_div::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator/=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_div::value>::map(v1, v1, s); + return v1; + } + + template + TIntVector2 operator%=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_mod::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator%=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_mod::value>::map(v1, v1, s); + return v1; + } + + + template + TIntVector2 operator+(TIntVector2& v1, const TIntVector2& v2) + { + TIntVector2 r; + Detail::compute_ivec2_add::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator+(TIntVector2& v1, T s) + { + TIntVector2 r; + Detail::compute_ivec2_add::value>::map(r, v1, s); + return r; + } + + template + TIntVector2 operator-(TIntVector2& v1, const TIntVector2& v2) + { + TIntVector2 r; + Detail::compute_ivec2_sub::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator-(TIntVector2& v1, T s) + { + TIntVector2 r; + Detail::compute_ivec2_sub::value>::map(r, v1, s); + return r; + } + + template + TIntVector2 operator*(TIntVector2& v1, const TIntVector2& v2) + { + TIntVector2 r; + Detail::compute_ivec2_mul::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator*(TIntVector2& v1, T s) + { + TIntVector2 r; + Detail::compute_ivec2_mul::value>::map(r, v1, s); + return r; + } + + template + TIntVector2 operator/(TIntVector2& v1, const TIntVector2& v2) + { + TIntVector2 r; + Detail::compute_ivec2_div::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator/(TIntVector2& v1, T s) + { + TIntVector2 r; + Detail::compute_ivec2_div::value>::map(r, v1, s); + return r; + } + + template + TIntVector2 operator%(TIntVector2& v1, const TIntVector2& v2) + { + TIntVector2 r; + Detail::compute_ivec2_mod::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator%(TIntVector2& v1, T s) + { + TIntVector2 r; + Detail::compute_ivec2_mod::value>::map(r, v1, s); + return r; + } + + + + + // Bitwise operators + + template + TIntVector2 operator&=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_and::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator&=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_and::value>::map(v1, v1, s); + return v1; + } + + template + TIntVector2 operator|=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_or::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator|=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_or::value>::map(v1, v1, s); + return v1; + } + + template + TIntVector2 operator^=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_xor::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator^=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_xor::value>::map(v1, v1, s); + return v1; + } + + template + TIntVector2 operator<<=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_left_shift::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator<<=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_left_shift::value>::map(v1, v1, s); + return v1; + } + + template + TIntVector2 operator>>=(TIntVector2& v1, const TIntVector2& v2) + { + Detail::compute_ivec2_right_shift::value>::map(v1, v1, v2); + return v1; + } + + template + TIntVector2 operator>>=(TIntVector2& v1, T s) + { + Detail::compute_ivec2_right_shift::value>::map(v1, v1, s); + return v1; + } + + + + template + TIntVector2 operator&(TIntVector2& v1, const TIntVector2& v2) + { + TVector2 r; + Detail::compute_ivec2_and::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator&(TIntVector2& v1, T s) + { + TVector2 r; + Detail::compute_ivec2_and::value>::map(r, v1, s); + return r; + } + + template + TIntVector2 operator|(TIntVector2& v1, const TIntVector2& v2) + { + TVector2 r; + Detail::compute_ivec2_or::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator|(TIntVector2& v1, T s) + { + TVector2 r; + Detail::compute_ivec2_or::value>::map(r, v1, s); + return r; + } + + template + TIntVector2 operator^(TIntVector2& v1, const TIntVector2& v2) + { + TVector2 r; + Detail::compute_ivec2_xor::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator^(TIntVector2& v1, T s) + { + TVector2 r; + Detail::compute_ivec2_xor::value>::map(r, v1, s); + return r; + } + + template + TIntVector2 operator<<(TIntVector2& v1, const TIntVector2& v2) + { + TVector2 r; + Detail::compute_ivec2_left_shift::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator<<(TIntVector2& v1, T s) + { + TVector2 r; + Detail::compute_ivec2_left_shift::value>::map(r, v1, s); + return r; + } + + template + TIntVector2 operator>>(TIntVector2& v1, const TIntVector2& v2) + { + TVector2 r; + Detail::compute_ivec2_right_shift::value>::map(r, v1, v2); + return r; + } + + template + TIntVector2 operator>>(TIntVector2& v1, T s) + { + TVector2 r; + Detail::compute_ivec2_right_shift::value>::map(r, v1, s); + return r; + } + + template + TIntVector2 operator~(TIntVector2& v1) + { + TVector2 r; + Detail::compute_ivec2_bnot::value>::map(r, v1); + return r; + } + + + + // Comparision + + template + bool operator==(const TIntVector2& v1, const TIntVector2& v2) + { + return Detail::compute_ivec2_eq::value>::map(v1, v2); + } + + template + bool operator!=(const TIntVector2& v1, const TIntVector2& v2) + { + return Detail::compute_ivec2_ieq::value>::map(v1, v2); + } + + + + // Inc- / Decrement + + + template + TIntVector2& operator++(TIntVector2& v1) + { + Detail::compute_ivec2_inc::value>::map(v1); + return v1; + } + + template + TIntVector2& operator--(TIntVector2& v1) + { + Detail::compute_ivec2_inc::value>::map(v1); + return v1; + } + + template + TIntVector2& operator++(TIntVector2& v1, int) + { + return ++v1; + } + + template + TIntVector2& operator--(TIntVector2& v1, int) + { + return --v1; + } +} \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/public/Math/MathFwd.h b/Engine/Source/Runtime/Core/public/Math/MathFwd.h index 7c4a8aa..98b3bb5 100644 --- a/Engine/Source/Runtime/Core/public/Math/MathFwd.h +++ b/Engine/Source/Runtime/Core/public/Math/MathFwd.h @@ -37,12 +37,12 @@ namespace Phanes::Core::Math { template struct TPoint2; template struct TPoint3; template struct TPoint4; - template struct TIntVector2; template struct TIntVector3; template struct TIntVector4; template struct TIntPoint2; template struct TIntPoint3; template struct TIntPoint4; + template struct TIntVector2; template struct TVector2; template struct TVector3; template struct TVector4; diff --git a/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp b/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp index e961593..4d6ba96 100644 --- a/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp +++ b/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp @@ -421,5 +421,10 @@ namespace Phanes::Core::Math::Detail } }; + // =============== // + // TIntVector2 // + // =============== // + + } \ No newline at end of file