pub struct PathfindingConfig<C>{
pub max_distance: Option<u32>,
pub obstacles: HashSet<C>,
pub terrain_costs: HashMap<C, u32>,
pub blocking_entities: HashMap<C, u32>,
pub base_cost: u32,
pub allow_diagonal: bool,
}Expand description
Pathfinding configuration for complex scenarios.
This struct provides a builder pattern for configuring advanced pathfinding with multiple constraint types and optimization options.
Fields§
§max_distance: Option<u32>Maximum search distance (prevents infinite searches)
obstacles: HashSet<C>Set of impassable coordinates
terrain_costs: HashMap<C, u32>Terrain cost modifiers for specific coordinates
blocking_entities: HashMap<C, u32>Entities that block movement
base_cost: u32Base movement cost
allow_diagonal: boolWhether diagonal movement is allowed (for applicable grids)
Implementations§
Source§impl<C> PathfindingConfig<C>
impl<C> PathfindingConfig<C>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new pathfinding configuration.
Examples found in repository?
examples/advanced_pathfinding_demo.rs (line 69)
64fn demonstrate_advanced_pathfinding() {
65 println!("\n=== Advanced A* with Configuration ===");
66 let start = SquareCoord::<FourConnected>::new(0, 0);
67 let goal = SquareCoord::<FourConnected>::new(5, 5);
68
69 let config = PathfindingConfig::new()
70 .with_max_distance(20)
71 .with_terrain_cost(SquareCoord::<FourConnected>::new(1, 1), 3)
72 .with_terrain_cost(SquareCoord::<FourConnected>::new(1, 2), 3)
73 .with_base_cost(1);
74
75 if let Some((path, cost)) = astar_advanced(&start, &goal, &config) {
76 println!("Advanced path found: {} steps, cost: {}", path.len(), cost);
77 println!("Path: {path:?}");
78 } else {
79 println!("No advanced path found");
80 }
81}Sourcepub fn with_max_distance(self, max_distance: u32) -> Self
pub fn with_max_distance(self, max_distance: u32) -> Self
Sets the maximum search distance.
Examples found in repository?
examples/advanced_pathfinding_demo.rs (line 70)
64fn demonstrate_advanced_pathfinding() {
65 println!("\n=== Advanced A* with Configuration ===");
66 let start = SquareCoord::<FourConnected>::new(0, 0);
67 let goal = SquareCoord::<FourConnected>::new(5, 5);
68
69 let config = PathfindingConfig::new()
70 .with_max_distance(20)
71 .with_terrain_cost(SquareCoord::<FourConnected>::new(1, 1), 3)
72 .with_terrain_cost(SquareCoord::<FourConnected>::new(1, 2), 3)
73 .with_base_cost(1);
74
75 if let Some((path, cost)) = astar_advanced(&start, &goal, &config) {
76 println!("Advanced path found: {} steps, cost: {}", path.len(), cost);
77 println!("Path: {path:?}");
78 } else {
79 println!("No advanced path found");
80 }
81}Sourcepub fn with_obstacle(self, coord: C) -> Self
pub fn with_obstacle(self, coord: C) -> Self
Adds an obstacle at the specified coordinate.
Sourcepub fn with_obstacles<I>(self, obstacles: I) -> Selfwhere
I: IntoIterator<Item = C>,
pub fn with_obstacles<I>(self, obstacles: I) -> Selfwhere
I: IntoIterator<Item = C>,
Adds multiple obstacles.
Sourcepub fn with_terrain_cost(self, coord: C, cost: u32) -> Self
pub fn with_terrain_cost(self, coord: C, cost: u32) -> Self
Sets terrain cost for a specific coordinate.
Examples found in repository?
examples/advanced_pathfinding_demo.rs (line 71)
64fn demonstrate_advanced_pathfinding() {
65 println!("\n=== Advanced A* with Configuration ===");
66 let start = SquareCoord::<FourConnected>::new(0, 0);
67 let goal = SquareCoord::<FourConnected>::new(5, 5);
68
69 let config = PathfindingConfig::new()
70 .with_max_distance(20)
71 .with_terrain_cost(SquareCoord::<FourConnected>::new(1, 1), 3)
72 .with_terrain_cost(SquareCoord::<FourConnected>::new(1, 2), 3)
73 .with_base_cost(1);
74
75 if let Some((path, cost)) = astar_advanced(&start, &goal, &config) {
76 println!("Advanced path found: {} steps, cost: {}", path.len(), cost);
77 println!("Path: {path:?}");
78 } else {
79 println!("No advanced path found");
80 }
81}Sourcepub fn with_blocking_entity(self, coord: C, entity_id: u32) -> Self
pub fn with_blocking_entity(self, coord: C, entity_id: u32) -> Self
Adds a blocking entity at the specified position.
Sourcepub fn with_base_cost(self, cost: u32) -> Self
pub fn with_base_cost(self, cost: u32) -> Self
Sets the base movement cost.
Examples found in repository?
examples/advanced_pathfinding_demo.rs (line 73)
64fn demonstrate_advanced_pathfinding() {
65 println!("\n=== Advanced A* with Configuration ===");
66 let start = SquareCoord::<FourConnected>::new(0, 0);
67 let goal = SquareCoord::<FourConnected>::new(5, 5);
68
69 let config = PathfindingConfig::new()
70 .with_max_distance(20)
71 .with_terrain_cost(SquareCoord::<FourConnected>::new(1, 1), 3)
72 .with_terrain_cost(SquareCoord::<FourConnected>::new(1, 2), 3)
73 .with_base_cost(1);
74
75 if let Some((path, cost)) = astar_advanced(&start, &goal, &config) {
76 println!("Advanced path found: {} steps, cost: {}", path.len(), cost);
77 println!("Path: {path:?}");
78 } else {
79 println!("No advanced path found");
80 }
81}Sourcepub fn without_diagonal(self) -> Self
pub fn without_diagonal(self) -> Self
Disables diagonal movement.
Trait Implementations§
Source§impl<C> Clone for PathfindingConfig<C>
impl<C> Clone for PathfindingConfig<C>
Source§fn clone(&self) -> PathfindingConfig<C>
fn clone(&self) -> PathfindingConfig<C>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<C> Debug for PathfindingConfig<C>
impl<C> Debug for PathfindingConfig<C>
Auto Trait Implementations§
impl<C> Freeze for PathfindingConfig<C>
impl<C> RefUnwindSafe for PathfindingConfig<C>where
C: RefUnwindSafe,
impl<C> Send for PathfindingConfig<C>where
C: Send,
impl<C> Sync for PathfindingConfig<C>where
C: Sync,
impl<C> Unpin for PathfindingConfig<C>where
C: Unpin,
impl<C> UnsafeUnpin for PathfindingConfig<C>
impl<C> UnwindSafe for PathfindingConfig<C>where
C: UnwindSafe,
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