diff options
Diffstat (limited to 'src/Math/Vector.hpp')
| -rw-r--r-- | src/Math/Vector.hpp | 29 |
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 << "[ "; |
