summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Math/Vector.hpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Math/Vector.hpp b/src/Math/Vector.hpp
index a7c3782..a31afec 100644
--- a/src/Math/Vector.hpp
+++ b/src/Math/Vector.hpp
@@ -46,10 +46,10 @@ struct Vector {
     }
 
     template<typename F>
-    Vector map_indexed(F f) const {
+    Vector zip(const Vector other, F f) const {
         Vector result{};
         for (Int i = 0; i < S; i++) {
-            result[i] = f(i, elements[i]);
+            result[i] = f(elements[i], other[i]);
         }
         return result;
     }
@@ -108,7 +108,7 @@ struct Vector {
     }
 
     Vector operator+(const Vector other) const {
-        return map_indexed([&](auto i, auto x) { return x + other[i]; });
+        return zip(other, [](auto a, auto b) { return a + b; });
     }
 
     Vector operator+(T scalar) const {
@@ -120,11 +120,11 @@ struct Vector {
     }
 
     T operator*(const Vector other) const {
-        return map_indexed([&](auto i, auto x) { return x * other[i]; }).sum();
+        return zip(other, [](auto a, auto b) { return a * b; }).sum();
     }
 
     Vector operator-(const Vector other) const {
-        return map_indexed([&](auto i, auto x) { return x - other[i]; });
+        return zip(other, [](auto a, auto b) { return a - b; });
     }
 
     Vector operator-() const {
@@ -135,6 +135,10 @@ struct Vector {
         return map([=](auto x) { return x / scalar; });
     }
 
+    Vector operator/(const Vector other) const {
+        return zip(other, [](auto a, auto b) { return a / b; });
+    }
+
     Bool operator==(const Vector& other) {
         for (Int i = 0; i < S; i++) {
             if (elements[i] != other[i]) {