summary refs log tree commit diff
path: root/src/Math/Vector.hpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-10-04 01:18:19 +0200
committerMel <einebeere@gmail.com>2022-10-04 01:18:19 +0200
commit0631fb666d2a28a6eb9b8d1578675699b41a5de6 (patch)
tree1db9b88d9c11074864f6959d32960eb6c54d3c4b /src/Math/Vector.hpp
parent75f3941579c756655fc7d4d29e7b92b6eae436b7 (diff)
downloadmeowcraft-0631fb666d2a28a6eb9b8d1578675699b41a5de6.tar.zst
meowcraft-0631fb666d2a28a6eb9b8d1578675699b41a5de6.zip
Cube Rendering
Diffstat (limited to 'src/Math/Vector.hpp')
-rw-r--r--src/Math/Vector.hpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/Math/Vector.hpp b/src/Math/Vector.hpp
index 0145b58..2e97217 100644
--- a/src/Math/Vector.hpp
+++ b/src/Math/Vector.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#include <stddef.h>
+#include <cstddef>
 #include <sstream>
 #include <iostream>
 #include <iterator>
@@ -17,10 +17,35 @@ public:
         std::copy(values, values + S, elements);
     };
 
+    Vector<S, T>(Vector<S - 1, T> vector, T scalar) {
+        std::copy(vector.elements, vector.elements + S - 1, elements);
+        elements[S - 1] = scalar;
+    }
+
+    Vector<S, T> apply(T f(T)) {
+        return apply(static_cast<std::function<T(T)>>(f));
+    }
+
+    Vector<S, T> apply(std::function<T(T)> f) {
+        Vector<S, T> result{};
+        for (int i = 0; i < S; i++) {
+            result[i] = f(elements[i]);
+        }
+        return result;
+    }
+
     T& operator[](size_t index) {
         return elements[index];
     }
 
+    Vector<S, T> operator+(Vector<S, T> other) const {
+        Vector<S, T> result{};
+        for (int i = 0; i < S; i++) {
+            result[i] = elements[i] + other[i];
+        }
+        return result;
+    }
+
     Vector<S, T> operator*(T scalar) const {
         Vector<S, T> result;
         for (size_t index; index < S; index++) {
@@ -57,7 +82,7 @@ public:
         return elements[3];
     }
 
-    std::string string() {
+    std::string string() const {
         std::stringstream str{};
 
         str << "[ ";