From 2cd51e29accfa26f31726f5306939685cbd4a40c Mon Sep 17 00:00:00 2001
From: THoehne <77296181+THoehne@users.noreply.github.com>
Date: Wed, 28 Aug 2024 14:27:08 +0200
Subject: [PATCH] Optimization

---
 .../Core/public/Math/Detail/Vector2Decl.inl   |  2 +-
 .../Runtime/Core/public/Math/Vector2.hpp      | 45 ++++++++-----------
 .../Runtime/Core/public/Math/Vector2.inl      | 16 +++----
 3 files changed, 27 insertions(+), 36 deletions(-)

diff --git a/Engine/Source/Runtime/Core/public/Math/Detail/Vector2Decl.inl b/Engine/Source/Runtime/Core/public/Math/Detail/Vector2Decl.inl
index 718f058..a43805d 100644
--- a/Engine/Source/Runtime/Core/public/Math/Detail/Vector2Decl.inl
+++ b/Engine/Source/Runtime/Core/public/Math/Detail/Vector2Decl.inl
@@ -189,7 +189,7 @@ namespace Phanes::Core::Math::Detail
         static constexpr bool map(const Phanes::Core::Math::TVector2<T, S>& v1, const Phanes::Core::Math::TVector2<T, S>& v2)
         {
             return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC ||
-                Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC);
+                    Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC);
         }
     };
 
diff --git a/Engine/Source/Runtime/Core/public/Math/Vector2.hpp b/Engine/Source/Runtime/Core/public/Math/Vector2.hpp
index 3aaa6ae..fcba05c 100644
--- a/Engine/Source/Runtime/Core/public/Math/Vector2.hpp
+++ b/Engine/Source/Runtime/Core/public/Math/Vector2.hpp
@@ -127,7 +127,7 @@ namespace Phanes::Core::Math {
      */
 
     template<RealType T, bool S>
-    TVector2<T, S> operator+= (TVector2<T, S>& v1, T s);
+    TVector2<T, S>& operator+= (TVector2<T, S>& v1, T s);
 
     /**
      * Addition operation on same TVector2<T, S> (this) by a another TVector2<T, S>.
@@ -137,7 +137,7 @@ namespace Phanes::Core::Math {
      */
 
     template<RealType T, bool S>
-    TVector2<T, S> operator+= (TVector2<T, S>& v1, const TVector2<T, S>& v2);
+    TVector2<T, S>& operator+= (TVector2<T, S>& v1, const TVector2<T, S>& v2);
 
     /**
      * Substraction operation on same TVector2<T, S> (this) by a floating point.
@@ -147,7 +147,7 @@ namespace Phanes::Core::Math {
      */
 
     template<RealType T, bool S>
-    TVector2<T, S> operator-= (TVector2<T, S>& v1, T s);
+    TVector2<T, S>& operator-= (TVector2<T, S>& v1, T s);
 
     /**
      * Substraction operation on same TVector2<T, S> (this) by a another TVector2<T, S>.
@@ -157,7 +157,7 @@ namespace Phanes::Core::Math {
      */
 
     template<RealType T, bool S>
-    TVector2<T, S> operator-= (TVector2<T, S>& v1, const TVector2<T, S>& v2);
+    TVector2<T, S>& operator-= (TVector2<T, S>& v1, const TVector2<T, S>& v2);
 
     /**
      * Multiplication of TVector2<T, S> (this) with a floating point.
@@ -167,7 +167,7 @@ namespace Phanes::Core::Math {
      */
 
     template<RealType T, bool S>
-    TVector2<T, S> operator*= (TVector2<T, S>& v1, T s);
+    TVector2<T, S>& operator*= (TVector2<T, S>& v1, T s);
 
     /// <summary>
     /// Componentwise multiplication of vector by other vector.
@@ -178,7 +178,7 @@ namespace Phanes::Core::Math {
     /// <param name="v2"></param>
     /// <returns>Copy of v1.</returns>
     template<RealType T, bool S>
-    TVector2<T, S> operator*= (TVector2<T, S>& v1, const TVector2<T, S>& v2);
+    TVector2<T, S>& operator*= (TVector2<T, S>& v1, const TVector2<T, S>& v2);
 
     /**
      * Devision of Vector (this) by floating point.
@@ -188,7 +188,7 @@ namespace Phanes::Core::Math {
      */
 
     template<RealType T, bool S>
-    TVector2<T, S> operator/= (TVector2<T, S>& v1, T s);
+    TVector2<T, S>& operator/= (TVector2<T, S>& v1, T s);
 
     /// <summary>
     /// Componentwise division of vector by other vector.
@@ -199,7 +199,7 @@ namespace Phanes::Core::Math {
     /// <param name="v2"></param>
     /// <returns>Copy of v1.</returns>
     template<RealType T, bool S>
-    TVector2<T, S> operator/= (TVector2<T, S>& v1, const TVector2<T, S>& v2);
+    TVector2<T, S>& operator/= (TVector2<T, S>& v1, const TVector2<T, S>& v2);
 
     /**
      * Scale of Vector by floating point. (> Creates a new TVector2<T, S>)
@@ -236,6 +236,10 @@ namespace Phanes::Core::Math {
     template<RealType T, bool S>
     TVector2<T, S> operator/ (const TVector2<T, S>& v1, T s);
 
+
+    template<RealType T, bool S>
+    inline TVector2<T, S> operator/ (T s, const TVector2<T, S>& v1);
+
     /// <summary>
     /// Componentwise multiplication with vector by vector.
     /// </summary>
@@ -262,24 +266,6 @@ namespace Phanes::Core::Math {
         return v1 * s;
     }
 
-    /**
-     * Division of Vector by floating point. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.)
-     *
-     * @param(v1) Vector to multiply with
-     * @param(s Floating point to divide with
-     *
-     * @return Result Vector
-     */
-
-
-    template<RealType T, bool S>
-    inline TVector2<T, S> operator/ (T s, const TVector2<T, S>& v1);
-
-
-
-    template<RealType T, bool S>
-    inline TVector2<T, S> operator- (T s, const TVector2<T, S>& v1);
-
     /**
      * Componentwise addition of Vector with floating point.
      *
@@ -316,6 +302,10 @@ namespace Phanes::Core::Math {
     template<RealType T, bool S>
     TVector2<T, S> operator- (const TVector2<T, S>& v1, T s);
 
+
+    template<RealType T, bool S>
+    inline TVector2<T, S> operator- (T s, const TVector2<T, S>& v1);
+
     /**
      * Componentwise substraction of Vector with Vector.
      *
@@ -356,6 +346,7 @@ namespace Phanes::Core::Math {
     bool operator!= (const TVector2<T, S>& v1, const TVector2<T, S>& v2);
 
 
+
     template<RealType T, bool A>
     TVector2<T, A>& operator++(TVector2<T, A>& v1);
 
@@ -812,7 +803,7 @@ namespace Phanes::Core::Math {
     template<RealType T, bool S>
     TVector2<T, S> Negate(const TVector2<T, S>& v1)
     {
-        return ((T)1.0 - v1);
+        return ((T)0.0 - v1);
     }
 
     /**
diff --git a/Engine/Source/Runtime/Core/public/Math/Vector2.inl b/Engine/Source/Runtime/Core/public/Math/Vector2.inl
index 31ac958..466b1f1 100644
--- a/Engine/Source/Runtime/Core/public/Math/Vector2.inl
+++ b/Engine/Source/Runtime/Core/public/Math/Vector2.inl
@@ -43,56 +43,56 @@ namespace Phanes::Core::Math
 
 
     template<RealType T, bool S>
-    TVector2<T, S> operator+=(TVector2<T, S>& v1, const TVector2<T, S>& v2)
+    TVector2<T, S>& operator+=(TVector2<T, S>& v1, const TVector2<T, S>& v2)
     {
         Detail::compute_vec2_add<T, S>::map(v1, v1, v2);
         return v1;
     }
 
     template<RealType T, bool S>
-    TVector2<T, S> operator+=(TVector2<T, S>& v1, T s)
+    TVector2<T, S>& operator+=(TVector2<T, S>& v1, T s)
     {
         Detail::compute_vec2_add<T, S>::map(v1, v1, s);
         return v1;
     }
 
     template<RealType T, bool S>
-    TVector2<T, S> operator-=(TVector2<T, S>& v1, const TVector2<T, S>& v2)
+    TVector2<T, S>& operator-=(TVector2<T, S>& v1, const TVector2<T, S>& v2)
     {
         Detail::compute_vec2_sub<T, S>::map(v1, v1, v2);
         return v1;
     }
 
     template<RealType T, bool S>
-    TVector2<T, S> operator-=(TVector2<T, S>& v1, T s)
+    TVector2<T, S>& operator-=(TVector2<T, S>& v1, T s)
     {
         Detail::compute_vec2_sub<T, S>::map(v1, v1, s);
         return v1;
     }
 
     template<RealType T, bool S>
-    TVector2<T, S> operator*=(TVector2<T, S>& v1, const TVector2<T, S>& v2)
+    TVector2<T, S>& operator*=(TVector2<T, S>& v1, const TVector2<T, S>& v2)
     {
         Detail::compute_vec2_mul<T, S>::map(v1, v1, v2);
         return v1;
     }
 
     template<RealType T, bool S>
-    TVector2<T, S> operator*=(TVector2<T, S>& v1, T s)
+    TVector2<T, S>& operator*=(TVector2<T, S>& v1, T s)
     {
         Detail::compute_vec2_mul<T, S>::map(v1, v1, s);
         return v1;
     }
 
     template<RealType T, bool S>
-    TVector2<T, S> operator/=(TVector2<T, S>& v1, const TVector2<T, S>& v2)
+    TVector2<T, S>& operator/=(TVector2<T, S>& v1, const TVector2<T, S>& v2)
     {
         Detail::compute_vec2_div<T, S>::map(v1, v1, v2);
         return v1;
     }
 
     template<RealType T, bool S>
-    TVector2<T, S> operator/=(TVector2<T, S>& v1, T s)
+    TVector2<T, S>& operator/=(TVector2<T, S>& v1, T s)
     {
         Detail::compute_vec2_div<T, S>::map(v1, v1, s);
         return v1;