diff options
author | HampusM <hampus@hampusmat.com> | 2022-01-09 21:47:23 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-01-09 21:47:23 +0100 |
commit | 8ceb79db1d0687bba005cef4a77bb889bf7ec3c3 (patch) | |
tree | b7c13359f652506d60c8556ea386ae8d50bfc5bc /src/matrix.tpp | |
parent | 097aa95c1f0cb159e7d9d0a3edf9284c421ee298 (diff) |
refactor: rewrite to c++
Diffstat (limited to 'src/matrix.tpp')
-rw-r--r-- | src/matrix.tpp | 62 |
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; +} |