CellModules
CellGrid.hpp
Go to the documentation of this file.
1#ifndef GRID2D_HPP
2#define GRID2D_HPP
3
8namespace Grid2D {
9
14 struct Vec2D {
15 int xc = 0;
16 int yc = 0;
23 Vec2D(int x_, int y_) : xc(x_), yc(y_) {}
24
29 inline int x() const { return xc; }
30
35 inline int y() const { return yc; }
36
42 bool operator==(Vec2D v){ return(v.x() == this->x() && v.y() == this->y()); }
43 };
44
51 template<typename cell_t>
52 struct CellGrid {
53 vector<vector<vector<cell_t *>>> grid;
55 bool toreX = false;
56 bool toreY = false;
57 int height = 10;
58 int width = 10;
64 void resizeGrid(int size) {
65 resizeGrid(size, size);
66 }
67
73 void resizeGrid(int w, int h) {
74 width = w;
75 height = h;
76 grid.resize(w, vector<vector<cell_t *>>(h, vector<cell_t *>()));
77 for(int i = 0 ; i < w ; ++i) grid[i].resize(h, vector<cell_t *>());
78 }
79
84 inline void setToreX(bool b){ toreX = b; }
85
90 inline void setToreY(bool b){ toreY = b; }
91
97 inline void setTore(bool x, bool y){ toreX = x; toreY = y; }
98
104 }
105 };
106}
107
108#endif
A simple vector class template.
Definition: std.hpp:290
Namespace for 2D grid-related structures and classes.
Template class representing a 2D grid of cell pointers.
Definition: CellGrid.hpp:52
CellGrid()
Default constructor initializing the grid with default width and height.
Definition: CellGrid.hpp:102
void resizeGrid(int w, int h)
Set the grid size to given width and height.
Definition: CellGrid.hpp:73
void setToreY(bool b)
Set the toreY property.
Definition: CellGrid.hpp:90
void setToreX(bool b)
Set the toreX property.
Definition: CellGrid.hpp:84
void setTore(bool x, bool y)
Set both toreX and toreY properties.
Definition: CellGrid.hpp:97
void resizeGrid(int size)
Set the grid size to a square of given size.
Definition: CellGrid.hpp:64
vector< vector< vector< cell_t * > > > grid
Definition: CellGrid.hpp:53
Structure representing a 2D vector.
Definition: CellGrid.hpp:14
Vec2D(int x_, int y_)
Constructor to initialize the vector with given coordinates.
Definition: CellGrid.hpp:23
int x() const
Get the X-coordinate.
Definition: CellGrid.hpp:29
int y() const
Get the Y-coordinate.
Definition: CellGrid.hpp:35
bool operator==(Vec2D v)
Equality operator to compare two Vec2D objects.
Definition: CellGrid.hpp:42