3#include "structure/math/spk_vector2.hpp"
87 spk::Vector2UInt _size{};
88 std::vector<Unit> _data;
90 static size_t _index(
size_t x,
size_t y,
size_t height)
108 _data(static_cast<size_t>(
size.x) *
size.y, fill)
116 const spk::Vector2UInt &
size()
const
145 return _data[_index(x, y, _size.y)];
155 return _data[_index(x, y, _size.y)];
165 return Row{_data.data() + x * _size.y, _size.y};
174 return ConstRow{_data.data() + x * _size.y, _size.y};
const spk::Vector2UInt & size() const
Returns the grid dimensions.
Definition spk_grid_2d.hpp:116
T Unit
Stored element type for each grid cell.
Definition spk_grid_2d.hpp:25
Unit & operator()(size_t x, size_t y)
Mutable access to a cell using column and row indices.
Definition spk_grid_2d.hpp:143
Grid2D()=default
Constructs an empty grid with zero dimensions.
size_t width() const
Reports the horizontal cell count.
Definition spk_grid_2d.hpp:124
const Unit * data() const
Exposes the underlying contiguous buffer (const overload).
Definition spk_grid_2d.hpp:189
Unit * data()
Exposes the underlying contiguous buffer.
Definition spk_grid_2d.hpp:181
Row operator[](size_t x)
Provides a mutable column slice.
Definition spk_grid_2d.hpp:163
size_t height() const
Reports the vertical cell count.
Definition spk_grid_2d.hpp:132
ConstRow operator[](size_t x) const
Provides a read-only column slice.
Definition spk_grid_2d.hpp:172
const Unit & operator()(size_t x, size_t y) const
Read-only access to a cell using column and row indices.
Definition spk_grid_2d.hpp:153
Grid2D(const spk::Vector2UInt &size, const Unit &fill=Unit{})
Builds a grid with the given dimensions and fill value.
Definition spk_grid_2d.hpp:106
Immutable view over a single column in the grid.
Definition spk_grid_2d.hpp:66
size_t len
Number of elements in the column slice.
Definition spk_grid_2d.hpp:74
const Unit & operator[](size_t y) const
Read-only access to an element within the column.
Definition spk_grid_2d.hpp:80
const Unit * ptr
Pointer to the first element of the column slice.
Definition spk_grid_2d.hpp:70
Mutable view over a single column in the grid.
Definition spk_grid_2d.hpp:32
const Unit & operator[](size_t y) const
Read-only access to an element within the column.
Definition spk_grid_2d.hpp:55
Unit * ptr
Pointer to the first element of the column slice.
Definition spk_grid_2d.hpp:36
size_t len
Number of elements in the column slice.
Definition spk_grid_2d.hpp:40
Unit & operator[](size_t y)
Accesses an element within the column.
Definition spk_grid_2d.hpp:46