Function grid_pathfinding::waypoints_to_path

source ·
pub fn waypoints_to_path(waypoints: Vec<Point>) -> Vec<Point>
Expand description

Turns waypoints into a path on the grid which can be followed step by step. Due to symmetry this is typically one of many ways to follow the waypoints.

Examples found in repository?
examples/paths_and_waypoints.rs (line 35)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
fn main() {
    let mut pathing_grid: PathingGrid = PathingGrid::new(5, 5, false);
    pathing_grid.set(1, 1, true);
    pathing_grid.generate_components();
    println!("{}", pathing_grid);
    let start = Point::new(0, 0);
    let end = Point::new(4, 4);
    if let Some(path) = pathing_grid.get_waypoints_single_goal(start, end, false) {
        println!("Waypoints:");
        for p in &path {
            println!("{:?}", p);
        }
        println!("\nPath generated from waypoints:");
        for p in waypoints_to_path(path) {
            println!("{:?}", p);
        }
    }
    println!("\nDirectly computed path");
    let expanded_path = pathing_grid
        .get_path_single_goal(start, end, false)
        .unwrap();
    for p in expanded_path {
        println!("{:?}", p);
    }
}