aboutsummaryrefslogtreecommitdiff
path: root/src/matrix.tpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/matrix.tpp')
-rw-r--r--src/matrix.tpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/matrix.tpp b/src/matrix.tpp
new file mode 100644
index 0000000..b9fa495
--- /dev/null
+++ b/src/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;
+}