32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
75 , m_data(size.width * size.height)
88 , m_data(size.width * size.height, value)
127 return m_data.data();
136 return m_data.size();
175 return m_data.empty();
229 constexpr Vector2u
toPosition(std::size_t pos)
const noexcept {
230 return { pos % m_size.col, pos / m_size.col };
261 template<
typename Func>
264 Vector2u neighbour
{ pos.col
, pos.row - 1
};
265 func(neighbour, get(neighbour));
268 if (pos.row < m_size.row - 1) {
269 Vector2u neighbour
{ pos.col
, pos.row + 1
};
270 func(neighbour, get(neighbour));
274 Vector2u neighbour
{ pos.col - 1
, pos.row
};
275 func(neighbour, get(neighbour));
278 if (pos.col < m_size.col - 1) {
279 Vector2u neighbour
{ pos.col + 1
, pos.row
};
280 func(neighbour, get(neighbour));
305 template<
typename Func>
308 Vector2u neighbour
{ pos.col
, pos.row - 1
};
309 func(neighbour, get(neighbour));
312 if (pos.row < m_size.row - 1) {
313 Vector2u neighbour
{ pos.col
, pos.row + 1
};
314 func(neighbour, get(neighbour));
318 Vector2u neighbour
{ pos.col - 1
, pos.row
};
319 func(neighbour, get(neighbour));
322 if (pos.col < m_size.col - 1) {
323 Vector2u neighbour
{ pos.col + 1
, pos.row
};
324 func(neighbour, get(neighbour));
349 template<
typename Func>
351 for (
int i = -1; i <= 1; ++i) {
352 if (pos.row == 0 && i == -1) {
356 if (pos.row + 1 == m_size.row && i == 1) {
360 for (
int j = -1; j <= 1; ++j) {
361 if (pos.col == 0 && j == -1) {
365 if (pos.col + 1 == m_size.col && j == 1) {
369 if (i != 0 || j != 0) {
370 Vector2u neighbour
{ pos.col + i
, pos.row + j
};
371 func(neighbour, get(neighbour));
398 template<
typename Func>
400 for (
int i = -1; i <= 1; ++i) {
401 if (pos.row == 0 && i == -1) {
405 if (pos.row + 1 == m_size.row && i == 1) {
409 for (
int j = -1; j <= 1; ++j) {
410 if (pos.col == 0 && j == -1) {
414 if (pos.col + 1 == m_size.col && j == 1) {
418 if (i != 0 || j != 0) {
419 Vector2u neighbour
{ pos.col + i
, pos.row + j
};
420 func(neighbour, get(neighbour));
440 return m_data.data();
449 const T *
end()
const noexcept {
450 return m_data.data() + m_data.size();
460 return m_data.data();
470 return m_data.data() + m_data.size();
479 return { 0, m_size.col * m_size.row };
488 return { 0, m_size.row };
497 return { 0, m_size.col };
503 T& get(Vector2u pos) {
504 return m_data[pos.row * m_size.col + pos.col];
507 const T& get(Vector2u pos)
const {
508 return m_data[pos.row * m_size.col + pos.col];
513 std::vector<T> m_data;
516 #ifndef DOXYGEN_SHOULD_SKIP_THIS
A two-dimensional array.
Definition: Array2D.h:55
constexpr unsigned getCols() const noexcept
Get the number of columns.
Definition: Array2D.h:153
Array2D(Vector2u size)
Constructor with a size.
Definition: Array2D.h:73
constexpr RangeU getRowRange() const noexcept
Get the row range.
Definition: Array2D.h:487
Array2D & operator=(const Array2D &)=default
Default copy assignment.
const T * begin() const noexcept
Get an iterator to the first element of the array.
Definition: Array2D.h:439
constexpr Vector(T x, T y)
Constructor that takes 2 components.
Definition: Vector.h:354
const T & operator()(Vector2u pos) const
Get the element at a given 2D position.
Definition: Array2D.h:209
void visit4Neighbours(Vector2u pos, Func func)
Visit the 4 neighbours of a given position.
Definition: Array2D.h:262
T & operator()(std::size_t pos)
Get the element at a given 1D position.
Definition: Array2D.h:200
T * begin() noexcept
Get an iterator to the first element of the array.
Definition: Array2D.h:459
std::size_t getDataSize() const noexcept
Get the raw data size.
Definition: Array2D.h:135
constexpr Vector2u getSize() const noexcept
Get the size of the array.
Definition: Array2D.h:144
void visit8Neighbours(const Vector2u &pos, Func func)
Visit the 8 neighbours of a given position.
Definition: Array2D.h:350
const T * end() const noexcept
Get an iterator to the element following the last element of the array.
Definition: Array2D.h:449
void visit8Neighbours(Vector2u pos, Func func) const
Visit the 8 neighbours of a given position.
Definition: Array2D.h:399
const T * getDataPtr() const noexcept
Get the pointer to raw data.
Definition: Array2D.h:126
T & operator()(Vector2u pos)
Get the element at a given 2D position.
Definition: Array2D.h:190
const T & operator()(std::size_t pos) const
Get the element at a given 1D position.
Definition: Array2D.h:219
Array2D()
Default constructor.
Definition: Array2D.h:62
Vector(const Vector &other)=default
Default copy constructor.
Array2D(Vector2u size, const T &value)
Constructor with a size and a value.
Definition: Array2D.h:86
constexpr RangeU getColRange() const noexcept
Get the column range.
Definition: Array2D.h:496
constexpr RangeZ getPositionRange() const noexcept
Get the 1D position range of the array.
Definition: Array2D.h:478
Array2D(Array2D &&)=default
Default move constructor.
constexpr Vector2u toPosition(std::size_t pos) const noexcept
Transform a 1D position into a 2D position.
Definition: Array2D.h:229
constexpr unsigned getRows() const noexcept
Get the number of rows.
Definition: Array2D.h:162
Array2D & operator=(Array2D &&)=default
Default move assignement.
void visit4Neighbours(Vector2u pos, Func func) const
Visit the 4 neighbours of a given position.
Definition: Array2D.h:306
constexpr bool isEmpty() const noexcept
Check if the array is empty.
Definition: Array2D.h:174
T * end() noexcept
Get an iterator to the element following the last element of the array.
Definition: Array2D.h:469
Array2D(const Array2D &)=default
Default copy constructor.