Skip to main content

GridPathfinder

Struct GridPathfinder 

Source
pub struct GridPathfinder { /* private fields */ }
Expand description

Weighted 2D grid pathfinder supporting A*, multi-goal Dijkstra, and Jump Point Search.

Implementations§

Source§

impl GridPathfinder

Core operations for GridPathfinder including A*, multi-goal Dijkstra, and Jump Point Search.

Source

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

Creates a uniform-cost GridPathfinder with every cell initialized to 1.0.

§Arguments
  • usize - Number of grid columns.
  • usize - Number of grid rows.
§Returns
  • Self - Initialized uniform-cost grid pathfinder.
Source

pub fn from_costs(width: usize, height: usize, costs: Vec<f32>) -> Self

Creates a GridPathfinder from explicit row-major cell traversal costs (<= 0.0 blocks).

§Arguments
  • usize - Number of grid columns.
  • usize - Number of grid rows.
  • Vec<f32> - Row-major cost array of length width * height.
§Returns
  • Self - Configured weighted grid pathfinder.
Source

pub fn index_of(&self, coord: GridCoord) -> Option<usize>

Converts a grid coordinate into a flat index if in bounds.

§Arguments
  • GridCoord - Cell coordinate to check.
§Returns
  • Option<usize> - Row-major cell index when inside grid bounds.
Source

pub fn coord_of(&self, index: usize) -> GridCoord

Converts a flat row-major cell index back into a GridCoord.

§Arguments
  • usize - Flat cell index.
§Returns
  • GridCoord - Corresponding (x, y) coordinate.
Source

pub fn is_walkable(&self, coord: GridCoord) -> bool

Returns whether coord is in bounds and has a positive finite traversal cost.

§Arguments
  • GridCoord - Cell coordinate to inspect.
§Returns
  • bool - true when walkable.
Source

pub fn set_cell_cost(&mut self, coord: GridCoord, cost: f32)

Sets the traversal cost of coord (<= 0.0 marks the cell blocked).

§Arguments
  • GridCoord - Cell coordinate to update.
  • f32 - New traversal cost (<= 0.0 or non-finite blocks the cell).
Source

pub fn set_blocked(&mut self, coord: GridCoord, blocked: bool)

Marks coord blocked (blocked == true) or walkable with cost 1.0 (blocked == false).

§Arguments
  • GridCoord - Cell coordinate to update.
  • bool - Whether the cell should be impassable.
Source

pub fn find_path( &mut self, start: GridCoord, goal: GridCoord, connectivity: GridConnectivity, algorithm: GridSearchAlgorithm, ) -> Option<GridPathResult>

Finds an optimal shortest path using the selected algorithm and connectivity policy.

§Arguments
  • GridCoord - Start cell coordinate.
  • GridCoord - Goal cell coordinate.
  • GridConnectivity - 4-way or 8-way (no-corner-cutting) connectivity.
  • GridSearchAlgorithm - Search strategy (AStar, Dijkstra, or JumpPointSearch).
§Returns
  • Option<GridPathResult> - Optimal path and cost if reachable.
Source

pub fn find_path_astar( &mut self, start: GridCoord, goal: GridCoord, connectivity: GridConnectivity, ) -> Option<GridPathResult>

Finds an optimal shortest path using A* with admissible Manhattan or Octile heuristics.

§Arguments
  • GridCoord - Start cell coordinate.
  • GridCoord - Goal cell coordinate.
  • GridConnectivity - 4-way or 8-way (no-corner-cutting) connectivity.
§Returns
  • Option<GridPathResult> - Optimal path and total cost if reachable.
Source

pub fn find_path_astar_into( &mut self, start: GridCoord, goal: GridCoord, connectivity: GridConnectivity, out_path: &mut Vec<GridCoord>, ) -> Option<f32>

Finds an optimal shortest path using A* while writing waypoints into a caller-owned buffer.

§Arguments
  • GridCoord - Start cell coordinate.
  • GridCoord - Goal cell coordinate.
  • GridConnectivity - 4-way or 8-way connectivity.
  • &mut Vec<GridCoord> - Reusable output path buffer.
§Returns
  • Option<f32> - Optimal total path cost when reachable.
Source

pub fn find_path_dijkstra( &mut self, start: GridCoord, goal: GridCoord, connectivity: GridConnectivity, ) -> Option<GridPathResult>

Finds an optimal shortest path to a single goal using Dijkstra’s algorithm.

§Arguments
  • GridCoord - Start cell coordinate.
  • GridCoord - Goal cell coordinate.
  • GridConnectivity - 4-way or 8-way connectivity.
§Returns
  • Option<GridPathResult> - Optimal path and total cost if reachable.
Source

pub fn find_path_dijkstra_multi_goal( &mut self, start: GridCoord, goals: &[GridCoord], connectivity: GridConnectivity, ) -> Option<GridPathResult>

Finds the optimal shortest path to the nearest reachable goal in goals using Dijkstra.

§Arguments
  • GridCoord - Start cell coordinate.
  • &[GridCoord] - Candidate target goal cells.
  • GridConnectivity - 4-way or 8-way (no-corner-cutting) connectivity.
§Returns
  • Option<GridPathResult> - Shortest path to whichever goal has minimum total cost.
Source

pub fn find_path_jps( &mut self, start: GridCoord, goal: GridCoord, connectivity: GridConnectivity, ) -> Option<GridPathResult>

Finds an optimal shortest path using Jump Point Search on uniform-cost grids (falling back to A* if weighted).

§Arguments
  • GridCoord - Start cell coordinate.
  • GridCoord - Goal cell coordinate.
  • GridConnectivity - 4-way or 8-way (no-corner-cutting) connectivity.
§Returns
  • Option<GridPathResult> - Optimal expanded cell-by-cell path with exact shortest cost.
Source§

impl GridPathfinder

Implements impl #impl_generics #name #ty_generics #where_clause.

Source

pub fn get_width(&self) -> usize

Source

pub fn get_mut_width(&mut self) -> &mut usize

Source

pub fn set_width(&mut self, val: usize) -> &mut Self

Source

pub fn get_height(&self) -> usize

Source

pub fn get_mut_height(&mut self) -> &mut usize

Source

pub fn set_height(&mut self, val: usize) -> &mut Self

Source

pub fn get_min_walkable_cost(&self) -> f32

Source

pub fn get_mut_min_walkable_cost(&mut self) -> &mut f32

Source

pub fn set_min_walkable_cost(&mut self, val: f32) -> &mut Self

Source

pub fn get_uniform_walkable(&self) -> bool

Source

pub fn get_mut_uniform_walkable(&mut self) -> &mut bool

Source

pub fn set_uniform_walkable(&mut self, val: bool) -> &mut Self

Trait Implementations§

Source§

impl Clone for GridPathfinder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for GridPathfinder

Source§

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

Formats the value using the given formatter. Read more

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.