condor_core/lib.rs
1//! Neutral cross-domain primitives shared by Condor owner crates.
2//!
3//! Holds only lane-agnostic types: continuous [`Point2`] and the search outcome
4//! surface in [`search`]. Domain algorithms, scene geometry, grids, and prepared
5//! builders stay in their owner crates. The facade re-exports selected items;
6//! consumers should prefer `condor` over depending on this crate directly unless
7//! they are implementing a domain crate.
8//!
9//! # Shared outcome vocabulary
10//!
11//! A valid search can compute either a route or no route; both carry
12//! algorithm-defined statistics. Input validation is deliberately separate and
13//! remains an outer owner-specific `Result::Err`.
14//!
15//! ```
16//! use condor_core::SearchOutcome;
17//!
18//! let outcome = SearchOutcome::<&str, usize>::no_path(4);
19//! assert!(!outcome.is_found());
20//! assert_eq!(outcome.path(), None);
21//! assert_eq!(outcome.stats(), &4);
22//! ```
23
24#![forbid(unsafe_code)]
25
26/// Optional expansion and wall-clock budgets shared by online search lanes.
27pub mod budget;
28/// Shared found/no-path outcome vocabulary (stats-bearing, separate from validation `Err`).
29pub mod search;
30
31pub use budget::{BudgetExhausted, BudgetWatch, SearchBudget};
32pub use search::{SearchOutcome, SearchPathCost, SearchVisitStats};
33
34/// Continuous 2D point in world / scene coordinates (not grid cells).
35///
36/// Shared by polygonal free-space, any-angle continuous, and navmesh surfaces.
37/// Equality is exact `f64` bit identity; geometry epsilon lives in domain crates.
38#[derive(Debug, Clone, Copy, PartialEq)]
39pub struct Point2 {
40 /// Horizontal world/scene coordinate (same units as domain geometry).
41 pub x: f64,
42 /// Vertical world/scene coordinate (same units as domain geometry).
43 pub y: f64,
44}
45
46impl Point2 {
47 /// Constructs a 2D point without additional validation.
48 #[must_use]
49 pub const fn new(x: f64, y: f64) -> Self {
50 Self { x, y }
51 }
52
53 /// Euclidean distance to `other`.
54 #[must_use]
55 pub fn distance_to(self, other: Self) -> f64 {
56 let dx = self.x - other.x;
57 let dy = self.y - other.y;
58 (dx * dx + dy * dy).sqrt()
59 }
60}
61
62impl From<(f64, f64)> for Point2 {
63 fn from((x, y): (f64, f64)) -> Self {
64 Self::new(x, y)
65 }
66}