[−][src]Trait hierarchical_pathfinding::neighbors::Neighborhood
Defines how a Path can move along the Grid.
Different Scenarios may have different constraints as to how a Path may be formed. For example if Agents can only move along the 4 cardinal directions, any Paths generated should reflect that by only containing those steps.
This Trait is a generalized solution to that problem. It provides a function to query all neighboring Points of an existing Point and a Heuristic for how long it might take to reach a goal from a Point.
The most common implementations of this Trait are already provided by this Module:
ManhattanNeighborhood
for Agents that can move up, down, left or rightMooreNeighborhood
for Agents that can move up, down, left, right, as well as the 4 diagonals (up-right, ...)
Required methods
fn get_all_neighbors(&self, point: Point) -> Box<dyn Iterator<Item = Point>>
Provides a list of Neighbors of a Point
Note that it is not necessary to check weather the Tile at a Point is solid or not. That check is done later.
fn heuristic(&self, point: Point, goal: Point) -> usize
Gives a Heuristic for how long it takes to reach goal
from point
.
This is usually the Distance between the two Points in the Metric of your Neighborhood.
If there is no proper way of calculation how long it takes, simply return 0. This will increase the time it takes to calculate the Path, but at least it will always be correct.