pub struct GridLayout {
pub origin: Vec2,
pub cell_size: Vec2,
}Expand description
Maps grid cells to world-space cells.
Cell (x, y) covers origin + (x, y) * cell_size to one cell further along
both axes. In 3D, use the vector’s y as world z. Searches measure
distance in cells, so with non-square cells a path is shortest in cell
steps rather than in world units.
Fields§
§origin: Vec2World position of cell (0, 0)’s minimum corner.
cell_size: Vec2Width and height of one cell in world units. Must be finite and positive.
Implementations§
Source§impl GridLayout
impl GridLayout
Sourcepub fn new(origin: Vec2, cell_size: Vec2) -> Self
pub fn new(origin: Vec2, cell_size: Vec2) -> Self
Creates a layout. Panics for a nonfinite origin or a nonpositive or nonfinite cell size.
Sourcepub fn cell_center(&self, cell: UVec2) -> Vec2
pub fn cell_center(&self, cell: UVec2) -> Vec2
World position of a cell’s center.
Sourcepub fn cell_bounds(&self, cell: UVec2) -> Aabb2
pub fn cell_bounds(&self, cell: UVec2) -> Aabb2
World bounds of a cell, for example as a static collider. Neighboring cells share exact edges.
Sourcepub fn clearance(&self, half_size: Vec2) -> Vec2
pub fn clearance(&self, half_size: Vec2) -> Vec2
A body’s clearance in cell units, for
smooth_path and line_of_sight: its half size divided by the
cell size, such as layout.clearance(body.half_size).