PathingGrid

Struct PathingGrid 

Source
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: bool

Implementations§

Source§

impl PathingGrid

Source

pub fn heuristic(&self, p1: &Point, p2: &Point) -> i32

Uses C as cost for cardinal (straight) moves and D for diagonal moves.

Source

pub fn get_component(&self, point: &Point) -> usize

Retrieves the component id a given Point belongs to.

Source

pub fn reachable(&self, start: &Point, goal: &Point) -> bool

Checks if start and goal are on the same component.

Source

pub fn unreachable(&self, start: &Point, goal: &Point) -> bool

Checks if start and goal are not on the same component.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn update(&mut self)

Regenerates the components if they are marked as dirty.

Source

pub fn update_all_neighbours(&mut self)

Source

pub fn set_jumppoints(&mut self, point: Point)

Source

pub fn fix_jumppoints(&mut self, point: Point)

Source

pub fn set_all_jumppoints(&mut self)

Performs the full jump point precomputation

Source

pub fn initialize(&mut self)

Source

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

Source§

fn clone(&self) -> PathingGrid

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PathingGrid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PathingGrid

Source§

fn default() -> PathingGrid

Returns the “default value” for a type. Read more
Source§

impl Display for PathingGrid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ValueGrid<bool> for PathingGrid

Source§

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.

Source§

fn new(width: usize, height: usize, default_value: bool) -> Self

Source§

fn get(&self, x: i32, y: i32) -> bool

Source§

fn width(&self) -> usize

Source§

fn height(&self) -> usize

Source§

fn get_point(&self, point: Point) -> T

Source§

fn get_ix(&self, ix: usize) -> T

Source§

fn get_ix_point(&self, point: &Point) -> usize

Source§

fn compute_ix(&self, x: i32, y: i32) -> usize

Gets the index corresponding to a coordinate, which is row-wise.
Source§

fn set_point(&mut self, point: Point, value: T)

Source§

fn set_ix(&mut self, ix: usize, value: T)

Source§

fn point_in_bounds(&self, point: Point) -> bool

Tests whether a point is in bounds.
Source§

fn index_in_bounds(&self, x: i32, y: i32) -> bool

Tests whether an index is in bounds.
Source§

fn set_rect(&mut self, rect: Rect, value: T)

Sets a given rectangle on the grid to the value.
Source§

fn rect(&self) -> Rect

Retrieves the rectangle corresponding to the grid dimensions at the origin.
Source§

fn get_rect(&self, rect: Rect) -> Vec<T>

Retrieves a column-wise vector of grid values in the given rectangle.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V