Expand description
A simple 2d grid container
§Example
use cell_grid::DynamicGrid;
// Create a new empty grid
let mut grid: DynamicGrid<i32> = DynamicGrid::new();
// Push rows
grid.push_row([1, 2]).unwrap();
grid.push_row([3, 4]).unwrap();
// Access by coordinate
assert_eq!(grid.get(0, 0), Some(&1));
assert_eq!(grid.get(1, 0), Some(&2));
assert_eq!(grid.get(0, 1), Some(&3));
assert_eq!(grid.get(1, 1), Some(&4));
// Iterate the content
assert_eq!(grid.cells().copied().collect::<Vec<_>>(), vec![1, 2, 3, 4]);
assert_eq!(grid.rows().collect::<Vec<_>>(), vec![&[1, 2], &[3, 4]]);
It is also possible to:
- Create a grid from size and init function:
DynamicGrid::new_with
- Iterate the cells which overlap a rectangle:
DynamicGrid::cells_in_rect
§Features
std
: (enabled by default) enable use of the standard library. Must be disabled forno_std
crates.
Structs§
- Coord
Deprecated A coordinate of a grid - A row-major 2d grid
- Grid
Deprecated A 2d fixed-size grid containers for cells of typeT
- Error returned by
DynamicGrid::push_row
if the length of the row being pushed is incompatible with the current width of the grid - Rect
Deprecated A rectangle of coordinates