blob: b9fa49584c530cca540300a4c490d7338a64da93 (
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
|
#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;
}
|