From b0c265ee3d94921f55266a679d3801a4d2b4505b Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 13 Feb 2022 19:55:53 +0100 Subject: refactor: move some components to a engine dir --- src/engine/matrix.tpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/engine/matrix.tpp (limited to 'src/engine/matrix.tpp') 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 + +template +Matrix::Matrix(unsigned int rows, unsigned int columns) +{ + _rows = rows; + _columns = columns; + + _matrix.reserve(rows); + _matrix.assign(_matrix.capacity(), std::vector(columns)); +}; + +template +void Matrix::fill(Element element) +{ + for (unsigned int row = 0U; row < _matrix.capacity(); row++) + { + std::vector row_vector = _matrix[row]; + + for (unsigned int column = 0U; column < row_vector.capacity(); column++) + _matrix[row][column] = element; + } +} + +template +void Matrix::print() +{ + for (std::vector row : _matrix) + { + for (Element element : row) + std::cout << element; + + std::cout << "\n"; + } + + std::cout << std::flush; +} + +template +Element Matrix::get(Vector2 pos) +{ + return _matrix[pos.y()][pos.x()]; +} + +template +void Matrix::set(Vector2 pos, Element element) +{ + _matrix[pos.y()][pos.x()] = element; +} + +template +unsigned int Matrix::rows() +{ + return _rows; +} + +template +unsigned int Matrix::columns() +{ + return _columns; +} -- cgit v1.2.3-18-g5258