Struct grid_pathfinding::PathingGrid
source · [−]pub struct PathingGrid {
pub grid: BoolGrid,
pub neighbours: SimpleGrid<u8>,
pub components: UnionFind<usize>,
pub components_dirty: bool,
}Expand description
PathingGrid maintains information about components using a UnionFind structure in addition to the raw bool grid values in the BoolGrid that determine whether a space is occupied (true) or empty (false). It also records neighbours in u8 format for fast lookups during search. Implements Grid by building on BoolGrid.
Fields
grid: BoolGridneighbours: SimpleGrid<u8>components: UnionFind<usize>components_dirty: boolImplementations
sourceimpl PathingGrid
impl PathingGrid
sourcepub fn get_component(&self, point: &Point) -> usize
pub fn get_component(&self, point: &Point) -> usize
Retrieves the component id a given Point belongs to.
sourcepub fn unreachable(&self, start: &Point, goal: &Point) -> bool
pub fn unreachable(&self, start: &Point, goal: &Point) -> bool
Checks if start and goal are on the same component.
sourcepub fn neighbours_unreachable(&self, start: &Point, goal: &Point) -> bool
pub fn neighbours_unreachable(&self, start: &Point, goal: &Point) -> bool
Checks if any neighbour of the goal is on the same component as the start.
sourcepub fn get_path_single_goal(
&self,
start: Point,
goal: Point,
approximate: bool
) -> Option<Vec<Point>>
pub fn get_path_single_goal(
&self,
start: Point,
goal: Point,
approximate: bool
) -> Option<Vec<Point>>
Computes a path from start to goal using JPS. If approximate is true, then it will path to one of the neighbours of the goal, which is useful if goal itself is blocked. The heuristic used is the Chebyshev distance.
sourcepub fn get_path_multiple_goals(
&self,
start: Point,
goals: Vec<&Point>
) -> Option<(Point, Vec<Point>)>
pub fn get_path_multiple_goals(
&self,
start: Point,
goals: Vec<&Point>
) -> Option<(Point, Vec<Point>)>
Computes a path from start to one of the given goals. This is done by taking the Chebyshev distance to the closest goal as heuristic value.
sourcepub fn get_waypoints_multiple_goals(
&self,
start: Point,
goals: Vec<&Point>
) -> Option<(Point, Vec<Point>)>
pub fn get_waypoints_multiple_goals(
&self,
start: Point,
goals: Vec<&Point>
) -> Option<(Point, Vec<Point>)>
The raw waypoints (jump points) from which get_path_multiple_goals makes a path.
sourcepub fn get_waypoints_single_goal(
&self,
start: Point,
goal: Point,
approximate: bool
) -> Option<Vec<Point>>
pub fn get_waypoints_single_goal(
&self,
start: Point,
goal: Point,
approximate: bool
) -> Option<Vec<Point>>
The raw waypoints (jump points) from which get_path_single_goal makes a path.
sourcepub fn generate_components(&mut self)
pub fn generate_components(&mut self)
Generates a new UnionFind structure and links up grid neighbours to the same components.
Trait Implementations
sourceimpl Clone for PathingGrid
impl Clone for PathingGrid
sourcefn clone(&self) -> PathingGrid
fn clone(&self) -> PathingGrid
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for PathingGrid
impl Debug for PathingGrid
sourceimpl Default for PathingGrid
impl Default for PathingGrid
sourcefn default() -> PathingGrid
fn default() -> PathingGrid
Returns the “default value” for a type. Read more
sourceimpl Display for PathingGrid
impl Display for PathingGrid
sourceimpl Grid<bool> for PathingGrid
impl Grid<bool> for PathingGrid
sourcefn set(&mut self, x: usize, y: usize, blocked: bool)
fn set(&mut self, x: usize, y: usize, blocked: bool)
Updates a position on the grid. Joins newly connected components and flags the components as dirty if components are (potentially) broken apart into multiple.
fn new(width: usize, height: usize, default_value: bool) -> Self
fn get(&self, x: usize, y: usize) -> bool
fn width(&self) -> usize
fn height(&self) -> usize
fn get_point(&self, point: Point) -> T
fn set_point(&mut self, point: Point, value: T)
sourcefn get_ix(&self, x: usize, y: usize) -> usize
fn get_ix(&self, x: usize, y: usize) -> usize
Gets the index corresponding to a coordinate, which is row-wise.
fn get_ix_point(&self, point: &Point) -> usize
sourcefn point_in_bounds(&self, point: Point) -> bool
fn point_in_bounds(&self, point: Point) -> bool
Tests whether a point is in bounds.
sourcefn index_in_bounds(&self, x: usize, y: usize) -> bool
fn index_in_bounds(&self, x: usize, y: usize) -> bool
Tests whether an index is in bounds.
sourcefn set_rectangle(&mut self, rect: &Rect, value: T)
fn set_rectangle(&mut self, rect: &Rect, value: T)
Sets a given rectangle on the grid to the value.
Auto Trait Implementations
impl RefUnwindSafe for PathingGrid
impl Send for PathingGrid
impl Sync for PathingGrid
impl Unpin for PathingGrid
impl UnwindSafe for PathingGrid
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more