pub struct PathingGrid {
pub grid: BoolGrid,
pub neighbours: SimpleValueGrid<u8>,
pub jump_point: SimpleValueGrid<u8>,
pub components: UnionFind<usize>,
pub components_dirty: bool,
pub heuristic_factor: f32,
pub improved_pruning: bool,
pub allow_diagonal_move: bool,
/* private fields */
}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: BoolGrid§neighbours: SimpleValueGrid<u8>§jump_point: SimpleValueGrid<u8>§components: UnionFind<usize>§components_dirty: bool§heuristic_factor: f32§improved_pruning: bool§allow_diagonal_move: boolImplementations§
Source§impl PathingGrid
impl PathingGrid
Sourcepub fn heuristic(&self, p1: &Point, p2: &Point) -> i32
pub fn heuristic(&self, p1: &Point, p2: &Point) -> i32
Uses C as cost for cardinal (straight) moves and D for diagonal moves.
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 reachable(&self, start: &Point, goal: &Point) -> bool
pub fn reachable(&self, start: &Point, goal: &Point) -> bool
Checks if start and goal are on the same component.
Sourcepub fn unreachable(&self, start: &Point, goal: &Point) -> bool
pub fn unreachable(&self, start: &Point, goal: &Point) -> bool
Checks if start and goal are not on the same component.
Sourcepub fn neighbours_reachable(&self, start: &Point, goal: &Point) -> bool
pub fn neighbours_reachable(&self, start: &Point, goal: &Point) -> bool
Checks if any neighbour of the goal is on the same component as the start.
Sourcepub fn neighbours_unreachable(&self, start: &Point, goal: &Point) -> bool
pub fn neighbours_unreachable(&self, start: &Point, goal: &Point) -> bool
Checks if every neighbour of the goal is on a different 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 the goal itself is blocked. If diagonals are allowed, the heuristic used computes the path cost of taking the maximal number of diagonal moves before continuing straight. If diagonals are not allowed, the Manhattan distance is used instead (see heuristic). This can be specified by setting allow_diagonal_move. The heuristic will be scaled by heuristic_factor which can be used to trade optimality for faster solving for many practical problems, a technique called Weighted A*. In pathfinding language, a factor greater than 1.0 will make the heuristic inadmissible, a requirement for solution optimality. By default, the heuristic_factor is 1.0 which gives optimal solutions.
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 the start to one of the given goals and returns the selected goal in addition to the found path. Otherwise behaves similar to get_path_single_goal.
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.
pub fn update_all_neighbours(&mut self)
pub fn set_jumppoints(&mut self, point: Point)
pub fn fix_jumppoints(&mut self, point: Point)
Sourcepub fn set_all_jumppoints(&mut self)
pub fn set_all_jumppoints(&mut self)
Performs the full jump point precomputation
pub fn initialize(&mut self)
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§
Source§impl Clone for PathingGrid
impl Clone for PathingGrid
Source§fn clone(&self) -> PathingGrid
fn clone(&self) -> PathingGrid
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PathingGrid
impl Debug for PathingGrid
Source§impl Default for PathingGrid
impl Default for PathingGrid
Source§fn default() -> PathingGrid
fn default() -> PathingGrid
Source§impl Display for PathingGrid
impl Display for PathingGrid
Source§impl ValueGrid<bool> for PathingGrid
impl ValueGrid<bool> for PathingGrid
Source§fn set(&mut self, x: i32, y: i32, blocked: bool)
fn set(&mut self, x: i32, y: i32, 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.