rustsim-pathfinding 0.0.1

Generic A* and grid-specific pathfinding for rustsim
Documentation
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rustsim_pathfinding::astar::{astar, astar_grid2d};

fn bench_astar_grid_50x50(c: &mut Criterion) {
    c.bench_function("A* grid 50x50 corner-to-corner (diagonal)", |b| {
        b.iter(|| {
            let result = astar_grid2d((0, 0), (49, 49), 50, 50, &|_, _| true, true);
            black_box(result);
        });
    });
}

fn bench_astar_grid_100x100(c: &mut Criterion) {
    c.bench_function("A* grid 100x100 corner-to-corner (cardinal)", |b| {
        b.iter(|| {
            let result = astar_grid2d((0, 0), (99, 99), 100, 100, &|_, _| true, false);
            black_box(result);
        });
    });
}

fn bench_astar_grid_with_obstacles(c: &mut Criterion) {
    // Wall at x=25, gap at y=25
    let walkable = |x: usize, y: usize| -> bool { !(x == 25 && y != 25) };

    c.bench_function("A* grid 50x50 with wall obstacle", |b| {
        b.iter(|| {
            let result = astar_grid2d((0, 0), (49, 49), 50, 50, &walkable, true);
            black_box(result);
        });
    });
}

fn bench_astar_generic_graph(c: &mut Criterion) {
    // 1000-node chain graph
    c.bench_function("A* generic 1000-node chain", |b| {
        b.iter(|| {
            let result = astar(
                0usize,
                999,
                |a, b| (*b as f64 - *a as f64).abs(),
                |n| {
                    let mut neighbors = Vec::new();
                    if *n > 0 {
                        neighbors.push((*n - 1, 1.0));
                    }
                    if *n < 999 {
                        neighbors.push((*n + 1, 1.0));
                    }
                    neighbors
                },
            );
            black_box(result);
        });
    });
}

criterion_group!(
    benches,
    bench_astar_grid_50x50,
    bench_astar_grid_100x100,
    bench_astar_grid_with_obstacles,
    bench_astar_generic_graph,
);
criterion_main!(benches);