34 template<
typename Type >
48 Array2D(
int rows,
int cols, Type defaultValue) {
49 data = QVector<QVector<Type>>(rows, QVector<Type>(cols, defaultValue));
65 return (*
this)(p.x(), p.y());
69 return (*
this)(p.x(), p.y());
75 for (QVector<Type> &v :
data)
143 template<
typename Type >
152 return other.
arr ==
arr && other.
x ==
x && other.
y ==
y;
156 return !(*
this == other);
161 if (
x >=
arr->size().width()) {
185 template<
typename Type >
194 return other.
arr ==
arr && other.
x ==
x && other.
y ==
y;
198 return !(*
this == other);
203 if (
x >=
arr->size().width()) {
228 template<
typename Type >
246 return !(*
this == other);
281 if (neighbor == 0 || neighbor == 3 || neighbor == 5)
283 if (neighbor == 1 || neighbor == 6)
297 int wdth =
arr->width();
298 int hght =
arr->height();
303 return 0 <= x && x < wdth
304 && 0 <= y && y < hght;
static Array2DCNeighborIterator ending(const Array2D< Type > *r, int x, int y)
Definition: array2d.h:232
bool operator!=(const Array2DCNeighborIterator< Type > &other) const
Definition: array2d.h:245
bool isInBounds() const
Definition: array2d.h:296
Array2DCNeighborIterator< Type > begin_neighbors(int x, int y) const
Definition: array2d.h:128
Array2DCIterator< Type > operator++(int)
Definition: array2d.h:212
static Array2DCIterator< Type > beginning(const Array2D< Type > *r)
Definition: array2d.h:188
int centerX
Definition: array2d.h:309
Array2D_Private::Array2DPointAndConstDataWrapper< Type > IndexedConstDataCollection
Definition: array2d.h:40
void resize(int rows, int cols)
Definition: array2d.h:72
Array2D()
Definition: array2d.h:43
int width() const
Definition: array2d.h:81
const Type & operator*() const
Definition: array2d.h:218
A lightweight class to allow looping through all the data in an Array2D, outputting QPairs of (positi...
Definition: array2d_private.h:114
int getY(int neighbor) const
Definition: array2d.h:288
int y
Definition: array2d.h:182
QVector< QVector< Type > > data
Definition: array2d.h:137
Type & operator()(int r, int c)
Definition: array2d.h:60
bool operator==(const Array2DIterator< Type > &other) const
Definition: array2d.h:151
static Array2DCNeighborIterator beginning(const Array2D< Type > *r, int x, int y)
Definition: array2d.h:231
int height() const
Definition: array2d.h:82
Array2DCIterator< Type > & operator++()
Definition: array2d.h:201
Array2D(QSize size)
Definition: array2d.h:54
Array2DIterator< Type > operator++(int)
Definition: array2d.h:170
bool operator==(const Array2DCNeighborIterator< Type > &other) const
Definition: array2d.h:241
int x
Definition: array2d.h:182
bool isInBounds(QPoint p) const
Returns true if (p.x(), p.y()) is a valid region.
Definition: array2d.h:88
Array2D(int rows, int cols)
Definition: array2d.h:52
Array2DCNeighborIterator< Type > & operator++()
Definition: array2d.h:249
Array2DCIterator(const Array2D< Type > *r, int x, int y)
Definition: array2d.h:191
int centerY
Definition: array2d.h:309
int getX(int neighbor) const
Definition: array2d.h:280
static Array2DIterator< Type > beginning(Array2D< Type > *r)
Definition: array2d.h:146
Array2DCIterator< Type > begin() const
Definition: array2d.h:109
IndexCollection indices() const
indices Returns a lightweight object for iterating over all valid (x,y) pairs.
Definition: array2d.h:96
Array2DCNeighborIterator< Type > operator++(int)
Definition: array2d.h:260
Array2D_Private::Array2DPointWrapper IndexCollection
Definition: array2d.h:39
const Type & operator*() const
Definition: array2d.h:266
int y
Definition: array2d.h:224
Array2D< Type > * arr
Definition: array2d.h:181
int x
Definition: array2d.h:224
static Array2DIterator< Type > ending(Array2D< Type > *r)
Definition: array2d.h:147
bool operator!=(const Array2DCIterator< Type > &other) const
Definition: array2d.h:197
bool operator==(const Array2DCIterator< Type > &other) const
Definition: array2d.h:193
const Array2D< Type > * arr
Definition: array2d.h:223
Type & operator()(QPoint p)
Definition: array2d.h:68
The Array2D class is basically a 2D implementation of QVector.
Definition: array2d.h:35
IndexedConstDataCollection indexedData() const
indexedData Returns a lightweight object for iterating over all data in the grid that also provides i...
Definition: array2d.h:105
Array2D(int rows, int cols, Type defaultValue)
Definition: array2d.h:48
Array2DIterator(Array2D< Type > *r, int x, int y)
Definition: array2d.h:149
Type & operator*()
Definition: array2d.h:176
static Array2DCIterator< Type > ending(const Array2D< Type > *r)
Definition: array2d.h:189
Array2DCIterator< Type > end() const
Definition: array2d.h:113
int neighborIndex
Definition: array2d.h:310
Array2DIterator< Type > end()
Definition: array2d.h:122
const Type & operator()(int r, int c) const
Definition: array2d.h:56
QSize size() const
Definition: array2d.h:79
const Array2D< Type > * arr
Definition: array2d.h:308
Array2DIterator< Type > & operator++()
Definition: array2d.h:159
Array2DIterator< Type > begin()
Definition: array2d.h:118
bool operator!=(const Array2DIterator< Type > &other) const
Definition: array2d.h:155
A lightweight class to allow looping through all the valid indices in Array2D.
Definition: array2d_private.h:75
Array2DCNeighborIterator< Type > end_neighbors(int x, int y) const
Definition: array2d.h:132
Array2DCNeighborIterator(const Array2D< Type > *r, int x, int y, int idx)
Definition: array2d.h:235