Explorar el Código

Add += operator and alike for vectors

Locria Cyber hace 4 años
padre
commit
75679017a6
Se han modificado 1 ficheros con 14 adiciones y 0 borrados
  1. 14 0
      source/raymathext.d

+ 14 - 0
source/raymathext.d

@@ -75,6 +75,13 @@ mixin template Linear()
             enum fragment = [FieldNameTuple!T].map!(field => field ~ op ~ "rhs." ~ field).join(",");
             return mixin("T(" ~ fragment ~ ")");
         }
+
+        T opOpAssign(string op)(inout T rhs) if (["+", "-", "*", "/"].canFind(op))
+        {
+            static foreach (field; [FieldNameTuple!T])
+                mixin(field ~ op ~ "= rhs." ~ field ~ ";");
+            return this;
+        }
     }
 
     inout T opBinary(string op)(inout float rhs) if (["+", "-", "*", "/"].canFind(op))
@@ -88,6 +95,13 @@ mixin template Linear()
         enum fragment = [FieldNameTuple!T].map!(field => "lhs" ~ op ~ field).join(",");
         return mixin("T(" ~ fragment ~ ")");
     }
+
+    T opOpAssign(string op)(inout float rhs) if (["+", "-", "*", "/"].canFind(op))
+    {
+        static foreach (field; [FieldNameTuple!T])
+            mixin(field ~ op ~ "= rhs;");
+        return this;
+    }
 }
 
 unittest