aboutsummaryrefslogtreecommitdiff
path: root/src/engine/matrix.tpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-13 19:55:53 +0100
committerHampusM <hampus@hampusmat.com>2022-02-13 19:55:53 +0100
commitb0c265ee3d94921f55266a679d3801a4d2b4505b (patch)
treeb489dcbafddafdb05b415e920e9a2ca8524158e6 /src/engine/matrix.tpp
parent36ce8d5d2c9b3bb9588a2bc1d96ee2678c2b990c (diff)
refactor: move some components to a engine dir
Diffstat (limited to 'src/engine/matrix.tpp')
-rw-r--r--src/engine/matrix.tpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/engine/matrix.tpp b/src/engine/matrix.tpp
new file mode 100644
index 0000000..b9fa495
--- /dev/null
+++ b/src/engine/matrix.tpp
@@ -0,0 +1,62 @@
+#include "matrix.hpp"
+#include <iostream>
+
+template <typename Element>
+Matrix<Element>::Matrix(unsigned int rows, unsigned int columns)
+{
+ _rows = rows;
+ _columns = columns;
+
+ _matrix.reserve(rows);
+ _matrix.assign(_matrix.capacity(), std::vector<Element>(columns));
+};
+
+template <typename Element>
+void Matrix<Element>::fill(Element element)
+{
+ for (unsigned int row = 0U; row < _matrix.capacity(); row++)
+ {
+ std::vector<Element> row_vector = _matrix[row];
+
+ for (unsigned int column = 0U; column < row_vector.capacity(); column++)
+ _matrix[row][column] = element;
+ }
+}
+
+template <typename Element>
+void Matrix<Element>::print()
+{
+ for (std::vector<Element> row : _matrix)
+ {
+ for (Element element : row)
+ std::cout << element;
+
+ std::cout << "\n";
+ }
+
+ std::cout << std::flush;
+}
+
+template <typename Element>
+Element Matrix<Element>::get(Vector2 pos)
+{
+ return _matrix[pos.y()][pos.x()];
+}
+
+template <typename Element>
+void Matrix<Element>::set(Vector2 pos, Element element)
+{
+ _matrix[pos.y()][pos.x()] = element;
+}
+
+template <typename Element>
+unsigned int Matrix<Element>::rows()
+{
+ return _rows;
+}
+
+template <typename Element>
+unsigned int Matrix<Element>::columns()
+{
+ return _columns;
+}