bsp_pathfinding/
lib.rs

1//! Provides a path finding search space generation and A* search algorithm
2//! using Binary Spatial Partitioning.
3//!
4//! The navigable space is defined by polygons delimiting the space. A graph of
5//! navigable nodes and edges will be generated.
6//!
7//! The algorithm does not impose any constraints on size or angle of the scene
8//! as is the case for grid or quadtree based approaches.
9//!
10//! # Usage
11//! ```rust
12//! use bsp_pathfinding::*;
13//! use glam::*;
14//! // Define a simple scene
15//! let square = Shape::rect(Vec2::new(50.0, 50.0), Vec2::new(0.0, 0.0));
16//! let left = Shape::rect(Vec2::new(10.0, 200.0), Vec2::new(-200.0, 10.0));
17//! let right = Shape::rect(Vec2::new(10.0, 200.0), Vec2::new(200.0, 10.0));
18//! let bottom = Shape::rect(Vec2::new(200.0, 10.0), Vec2::new(10.0, -200.0));
19//! let top = Shape::rect(Vec2::new(200.0, 10.0), Vec2::new(10.0, 200.0));
20//!
21//! // Create navigational context from the scene
22//! let nav = NavigationContext::new([square, left, right, top, bottom].iter().flatten());
23//!
24//! // Find a path
25//! let start = Vec2::new(-100.0, 0.0);
26//! let end = Vec2::new(100.0, 30.0);
27//!
28//! let path = nav
29//!     .find_path(start, end, heuristics::euclidiean, SearchInfo::default())
30//!     .expect("Failed to find a path");
31//! ```
32//!
33pub mod astar;
34pub mod heuristics;
35mod navigation_context;
36mod shape;
37mod tree;
38mod util;
39
40pub use astar::*;
41pub use navigation_context::*;
42pub use shape::*;
43pub use tree::*;
44
45pub const TOLERANCE: f32 = 0.01;