Skip to main content

PathfindingConfig

Struct PathfindingConfig 

Source
pub struct PathfindingConfig<C>
where C: Clone + Hash + Eq,
{ 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: u32

Base movement cost

§allow_diagonal: bool

Whether diagonal movement is allowed (for applicable grids)

Implementations§

Source§

impl<C> PathfindingConfig<C>
where C: Clone + Hash + Eq,

Source

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}
Source

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}
Source

pub fn with_obstacle(self, coord: C) -> Self

Adds an obstacle at the specified coordinate.

Source

pub fn with_obstacles<I>(self, obstacles: I) -> Self
where I: IntoIterator<Item = C>,

Adds multiple obstacles.

Source

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}
Source

pub fn with_blocking_entity(self, coord: C, entity_id: u32) -> Self

Adds a blocking entity at the specified position.

Source

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}
Source

pub fn without_diagonal(self) -> Self

Disables diagonal movement.

Trait Implementations§

Source§

impl<C> Clone for PathfindingConfig<C>
where C: Clone + Hash + Eq + Clone,

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<C> Debug for PathfindingConfig<C>
where C: Clone + Hash + Eq + Debug,

Source§

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

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

impl<C> Default for PathfindingConfig<C>
where C: Clone + Hash + Eq,

Source§

fn default() -> Self

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

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> 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> CloneDyn for T
where T: Clone,

Source§

fn __clone_dyn(&self, _: DontCallMe) -> *mut ()

Source§

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

Source§

fn __clone_dyn(&self, _: DontCallMe) -> *mut ()

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> Component for T
where T: Send + Sync + 'static,

Source§

impl<T> Event for T
where T: Any + Send + Sync + Debug + Clone,

Source§

impl<All> From1<()> for All
where All: Default,

Source§

fn from1(_a: ()) -> All

Constructor with a single arguments.
Source§

impl<T, All> From1<(T,)> for All
where All: From1<T>,

Source§

fn from1(arg: (T,)) -> All

Constructor with a single arguments.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<All, F> Into1<F> for All
where F: From1<All>,

Source§

fn to(self) -> F

Converts this type into the (usually inferred) input type.
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> IntoResult<T> for T

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> ToRef<T> for T
where T: ?Sized,

Source§

fn to_ref(&self) -> &T

Converts the implementing type to an immutable reference. Read more
Source§

impl<T> ToValue<T> for T

Source§

fn to_value(self) -> T

Obtains the value from the implementing type. 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.