Skip to main content

spatialrust_search/
traits.rs

1/// One neighbor search result.
2#[derive(Clone, Copy, Debug, PartialEq)]
3pub struct Neighbor {
4    /// Index of the neighbor point in the source cloud.
5    pub index: usize,
6    /// Squared Euclidean distance to the query point.
7    pub distance_squared: f32,
8}
9
10/// Common spatial index operations.
11pub trait SpatialIndex {
12    /// Returns the number of indexed points.
13    fn len(&self) -> usize;
14
15    /// Returns whether the index is empty.
16    fn is_empty(&self) -> bool {
17        self.len() == 0
18    }
19}
20
21/// Exact nearest neighbor queries.
22pub trait NearestNeighborIndex: SpatialIndex {
23    /// Finds the single nearest neighbor.
24    fn nearest_one(&self, x: f32, y: f32, z: f32) -> Option<Neighbor>;
25
26    /// Finds up to `k` nearest neighbors sorted by ascending distance.
27    fn nearest_k(&self, x: f32, y: f32, z: f32, k: usize) -> Vec<Neighbor>;
28}
29
30/// Radius search queries.
31pub trait RadiusSearchIndex: SpatialIndex {
32    /// Finds all neighbors within `radius` (not squared).
33    fn radius_search(&self, x: f32, y: f32, z: f32, radius: f32) -> Vec<Neighbor>;
34}