pub struct RegionTree<const D: usize> { /* private fields */ }Expand description
A point tree over an axis-aligned region of D-space. Each leaf holds up to capacity points
before splitting into 2^D equal sub-boxes (down to max_depth levels, so coincident points
cannot cause unbounded splitting). Entries are (id, point) pairs; ids are chosen by the caller.
Implementations§
Source§impl<const D: usize> RegionTree<D>
impl<const D: usize> RegionTree<D>
Sourcepub fn new(min: [f64; D], max: [f64; D]) -> Self
pub fn new(min: [f64; D], max: [f64; D]) -> Self
An empty tree covering [min, max] with leaf capacity 8 and depth limit 20.
pub fn with_limits( min: [f64; D], max: [f64; D], capacity: usize, max_depth: usize, ) -> Self
Sourcepub fn from_points(points: &[[f64; D]]) -> Self
pub fn from_points(points: &[[f64; D]]) -> Self
Builds a tree sized to the bounding box of points, using each point’s index as its id.
Sourcepub fn insert(&mut self, id: usize, point: [f64; D]) -> bool
pub fn insert(&mut self, id: usize, point: [f64; D]) -> bool
Adds a point; returns false (and stores nothing) if it is non-finite or outside the region.
Sourcepub fn remove(&mut self, id: usize, point: [f64; D]) -> bool
pub fn remove(&mut self, id: usize, point: [f64; D]) -> bool
Removes the entry with this id and point; returns whether it was present.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn query_box(&self, min: [f64; D], max: [f64; D]) -> Vec<usize>
pub fn query_box(&self, min: [f64; D], max: [f64; D]) -> Vec<usize>
Ids of all points in the box [min, max] (inclusive).
Sourcepub fn query_radius(&self, centre: [f64; D], radius: f64) -> Vec<usize>
pub fn query_radius(&self, centre: [f64; D], radius: f64) -> Vec<usize>
Ids of all points within radius of centre (inclusive).
Sourcepub fn k_nearest(&self, query: [f64; D], k: usize) -> Vec<(usize, f64)>
pub fn k_nearest(&self, query: [f64; D], k: usize) -> Vec<(usize, f64)>
The k nearest points as (id, distance), nearest first (ties by id).