pub struct PathGrid {
pub width: usize,
pub height: usize,
pub cell_size: f32,
pub walkable: Vec<bool>,
pub weights: Vec<f32>,
pub origin: Vec2,
}Expand description
A uniform grid used for all grid-based pathfinding algorithms.
Fields§
§width: usize§height: usize§cell_size: f32§walkable: Vec<bool>§weights: Vec<f32>§origin: Vec2Implementations§
Source§impl PathGrid
impl PathGrid
Sourcepub fn new(width: usize, height: usize, cell_size: f32) -> Self
pub fn new(width: usize, height: usize, cell_size: f32) -> Self
Create a new fully-walkable grid.
Sourcepub fn with_origin(
width: usize,
height: usize,
cell_size: f32,
origin: Vec2,
) -> Self
pub fn with_origin( width: usize, height: usize, cell_size: f32, origin: Vec2, ) -> Self
Create grid with a world-space origin offset.
Sourcepub fn set_walkable(&mut self, x: usize, y: usize, walkable: bool)
pub fn set_walkable(&mut self, x: usize, y: usize, walkable: bool)
Mark a cell walkable or not.
Sourcepub fn set_weight(&mut self, x: usize, y: usize, weight: f32)
pub fn set_weight(&mut self, x: usize, y: usize, weight: f32)
Set the traversal weight of a cell (higher = more expensive).
Sourcepub fn world_to_grid(&self, pos: Vec2) -> (usize, usize)
pub fn world_to_grid(&self, pos: Vec2) -> (usize, usize)
Convert a world position to grid coordinates. Clamps to valid range.
Sourcepub fn grid_to_world(&self, x: usize, y: usize) -> Vec2
pub fn grid_to_world(&self, x: usize, y: usize) -> Vec2
Convert grid coordinates to the world-space centre of that cell.
Sourcepub fn is_walkable(&self, x: usize, y: usize) -> bool
pub fn is_walkable(&self, x: usize, y: usize) -> bool
Check whether a cell is walkable.
Sourcepub fn neighbors(&self, x: usize, y: usize) -> Vec<(usize, usize, f32)>
pub fn neighbors(&self, x: usize, y: usize) -> Vec<(usize, usize, f32)>
Returns walkable neighbours of (x, y) together with their movement cost. Includes diagonals; diagonal cost is sqrt(2) * avg_weight.
Sourcepub fn neighbors_cardinal(&self, x: usize, y: usize) -> Vec<(usize, usize, f32)>
pub fn neighbors_cardinal(&self, x: usize, y: usize) -> Vec<(usize, usize, f32)>
Cardinal-only neighbours (no diagonals).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PathGrid
impl RefUnwindSafe for PathGrid
impl Send for PathGrid
impl Sync for PathGrid
impl Unpin for PathGrid
impl UnsafeUnpin for PathGrid
impl UnwindSafe for PathGrid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.