aboutsummaryrefslogtreecommitdiff
path: root/src/engine/matrix.tpp
blob: d25de28ad26426687fa9668b66ae05f8ddfdd49d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once

#include "matrix.hpp"

#include <iostream>

template <typename Element>
Matrix<Element>::Matrix(const Bounds &bounds)
	: _rows(bounds.height()), _columns(bounds.width())
{
	_matrix.reserve(bounds.height());
	_matrix.assign(_matrix.capacity(), std::vector<Element>(bounds.width()));
};

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 (const std::vector<Element> &row : _matrix)
	{
		for (const 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;
}