Skip to main content

Module grid

Module grid 

Source
Expand description

§Grid<T>

A rectangular, row-major grid for game boards, maps, pathfinding fields, and other two-dimensional data.

Cells are addressed with Point values rather than raw row/column pairs. Points use col for the horizontal coordinate and row for the vertical coordinate, with (0, 0) at the top-left corner.

§Examples

use gametools::{GameResult, Grid, GridSize, Point};

let size = GridSize::new(3, 2)?;
let grid = Grid::new_with_fn(size, |point| point.row * 10 + point.col)?;

assert_eq!(grid[Point::new(0, 0)], 0);
assert_eq!(grid[Point::new(2, 1)], 12);
assert_eq!(grid.get(Point::new(3, 0)), None);

Re-exports§

pub use point::Point;
pub use pointdelta::PointDelta;

Modules§

point
Point
pointdelta
PointDelta

Structs§

Grid
A generic rectangular grid addressed by Point.
GridSize
Non-zero dimensions used to create a Grid.