pub struct SpatialIndex { /* private fields */ }Expand description
A flat spatial index that stores points in a contiguous f32 buffer.
Points are stored in a flat Vec<f32> with stride equal to dimensions,
eliminating per-point heap allocations and improving cache locality.
Implementations§
Source§impl SpatialIndex
impl SpatialIndex
Sourcepub fn new(dimensions: usize) -> Self
pub fn new(dimensions: usize) -> Self
Create a new index with the given dimensionality and Euclidean metric.
Sourcepub fn with_metric(dimensions: usize, metric: DistanceMetric) -> Self
pub fn with_metric(dimensions: usize, metric: DistanceMetric) -> Self
Create a new index with an explicit distance metric.
Sourcepub fn insert_point_cloud(&mut self, cloud: &PointCloud)
pub fn insert_point_cloud(&mut self, cloud: &PointCloud)
Insert all points from a PointCloud into the index.
Sourcepub fn insert_vectors(&mut self, vectors: &[Vec<f32>])
pub fn insert_vectors(&mut self, vectors: &[Vec<f32>])
Insert pre-built vectors. Vectors whose length does not match the index dimensionality are silently skipped.
Sourcepub fn search_nearest(
&self,
query: &[f32],
k: usize,
) -> Result<Vec<(usize, f32)>, IndexError>
pub fn search_nearest( &self, query: &[f32], k: usize, ) -> Result<Vec<(usize, f32)>, IndexError>
Find the k nearest neighbours to query.
Returns (index, distance) pairs sorted by ascending distance.
Uses a max-heap of size k for O(n log k) instead of O(n log n).
For the Euclidean metric, squared distances are used internally and
only the final k results are square-rooted.
Sourcepub fn search_radius(
&self,
center: &[f32],
radius: f32,
) -> Result<Vec<(usize, f32)>, IndexError>
pub fn search_radius( &self, center: &[f32], radius: f32, ) -> Result<Vec<(usize, f32)>, IndexError>
Find all points within radius of center.
Returns (index, distance) pairs in arbitrary order.
For the Euclidean metric, squared distances are compared against
radius² internally.
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
The dimensionality of this index.
Sourcepub fn metric(&self) -> DistanceMetric
pub fn metric(&self) -> DistanceMetric
The distance metric in use.
Trait Implementations§
Source§impl Clone for SpatialIndex
impl Clone for SpatialIndex
Source§fn clone(&self) -> SpatialIndex
fn clone(&self) -> SpatialIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more