-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.cpp
More file actions
40 lines (34 loc) · 779 Bytes
/
matrix.cpp
File metadata and controls
40 lines (34 loc) · 779 Bytes
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
#include "matrix.h"
#include <algorithm>
GOLMatrix::GOLMatrix(int size) {
this->size = size;
data.resize(size);
std::fill(data.begin(), data.begin() + size, *new std::vector<int>(size));
}
void GOLMatrix::calibrate(int *x, int *y) {
if (*x >= size)
*x -= size;
if (*y >= size)
*y -= size;
if (*x < 0)
*x = size + *x;
if (*y < 0)
*y = size + *y;
}
int GOLMatrix::get(int x, int y) {
calibrate(&x, &y);
return data[x][y];
}
int &GOLMatrix::operator()(int x, int y) {
calibrate(&x, &y);
return data[x][y];
}
void GOLMatrix::set(int x, int y, int val) {
calibrate(&x, &y);
data[x][y] = val;
}
void GOLMatrix::clear() {
data.clear();
data.resize(size);
std::fill(data.begin(), data.begin() + size, *new std::vector<int>(size));
}