summaryrefslogtreecommitdiff
path: root/src/Math
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-11-20 23:50:25 +0100
committerMel <einebeere@gmail.com>2023-11-21 01:52:28 +0100
commit272e6a63df7369e5afcb16c5a6c14f7dd6a75893 (patch)
tree6951e8b53913e9afe2c0a5e4960421a916835135 /src/Math
parent7562a79fa214245544cb379423314c3a0766a7f2 (diff)
downloadmeowcraft-272e6a63df7369e5afcb16c5a6c14f7dd6a75893.tar.zst
meowcraft-272e6a63df7369e5afcb16c5a6c14f7dd6a75893.zip
Replace `Vector::map_indexed` with `zip` and add vector division
Diffstat (limited to 'src/Math')
-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]) {