32 return (x>=0 and x<xsize and y>=0 and y<ysize);
36 std::fill(value.begin(), value.end(), x);
39 void resize(
const int x,
const int y) {
51 if(y_at >= ysize+1)
return;
53 for(
int x=0;x<nxt.xsize;x++) {
54 for(
int y=0;y<nxt.ysize;y++) {
55 if(y < y_at) nxt.
at(x,y) = this->
at(x,y);
56 else if(y == y_at) nxt.at(x,y) = b;
57 else nxt.at(x,y) = this->
at(x,y-1);
61 this->operator=(std::move(nxt));
65 if(x_at >= xsize+1)
return;
67 for(
int x=0;x<nxt.xsize;x++) {
68 for(
int y=0;y<nxt.ysize;y++) {
69 if(x < x_at) nxt.
at(x,y) = this->
at(x,y);
70 else if(x == x_at) nxt.at(x,y) = b;
71 else nxt.at(x,y) = this->
at(x-1,y);
75 this->operator=(std::move(nxt));
78 if(ysize == 0 or y_at >= ysize or y_at < 0)
return;
81 for(
int x=0;x<nxt.xsize;x++) {
82 for(
int y=0;y<
ysize;y++) {
83 if(y < y_at) nxt.
at(x,y) = this->
at(x,y);
84 else if(y > y_at) nxt.at(x,y-1) = this->
at(x,y);
88 this->operator=(std::move(nxt));
91 if(xsize == 0 or x_at >= xsize or x_at < 0)
return;
94 for(
int x=0;x<
xsize;x++) {
95 for(
int y=0;y<nxt.ysize;y++) {
96 if(x < x_at) nxt.
at(x,y) = this->
at(x,y);
97 else if(x > x_at) nxt.at(x-1,y) = this->
at(x,y);
101 this->operator=(std::move(nxt));
105 const T&
at(
const int x,
const int y)
const {
106 if constexpr (std::is_same<T,bool>::value) { assert(
false &&
"*** Golly you can't have references in std::vector<bool>."); }
108 return value.at(x*ysize + y);
112 T&
at(
const int x,
const int y) {
113 if constexpr (std::is_same<T,bool>::value) { assert(
false &&
"*** Golly you can't have references in std::vector<bool>."); }
115 return value.at(x*ysize + y);
120 if constexpr (std::is_same<T,bool>::value) { assert(
false &&
"*** Golly you can't have references in std::vector<bool>."); }
122 return value.at(x*ysize + y);
127 return value.at(x*ysize + y);
132 void set(
const int x,
const int y,
const T& val) {
133 value.at(x*ysize + y) = val;
135 void set(
const int x,
const int y,
const T&& val) {
136 value.at(x*ysize + y) = val;
138 T
get(
const int x,
const int y) {
139 return value.at(x*ysize+y);
144 CERR "**** Cannot use [] with Vector2d, use .at()" ENDL;
149 std::string out =
"[";
150 for(
int y=0;y<
ysize;y++) {
152 for(
int x=0;x<
xsize;x++) {
153 out +=
str(
at(x,y)) +
",";
155 if(ysize > 0) out.pop_back();
158 if(xsize > 0) out.pop_back();
void delete_y(const int y_at)
Definition: Vector2D.h:77
Vector2D(int x, int y)
Definition: Vector2D.h:22
void operator[](X x)
Definition: Vector2D.h:143
int xsize
Definition: Vector2D.h:15
T & operator()(const int x, const int y) const
Definition: Vector2D.h:119
void reserve(const int x, const int y)
Definition: Vector2D.h:44
void fill(T x)
Definition: Vector2D.h:35
std::vector< T > value
Definition: Vector2D.h:18
std::string string()
Definition: Vector2D.h:148
std::string str(BindingTree *t)
Definition: BindingTree.h:195
const T & operator()(const int x, const int y)
Definition: Vector2D.h:126
#define CERR
Definition: IO.h:23
void insert_y(const int y_at, T b)
Definition: Vector2D.h:49
void delete_x(const int x_at)
Definition: Vector2D.h:90
Just a little wrapper to allow vectors to be handled as 2D arrays, which simplifie some stuff in Gram...
Definition: Vector2D.h:14
void insert_x(const int x_at, T b)
Definition: Vector2D.h:63
#define ENDL
Definition: IO.h:21
bool inbounds(int x, int y)
Definition: Vector2D.h:31
Vector2D(int x, int y, T b)
Definition: Vector2D.h:26
const T & at(const int x, const int y) const
Definition: Vector2D.h:105
Vector2D()
Definition: Vector2D.h:20
int ysize
Definition: Vector2D.h:16
T & at(const int x, const int y)
Definition: Vector2D.h:112
void resize(const int x, const int y)
Definition: Vector2D.h:39