pub struct SpatialHashPos3D<T: Clone> {
pub cell_size: f64,
pub n_items: usize,
/* private fields */
}Expand description
A uniform-grid spatial hash with position storage for exact radius queries.
Fields§
§cell_size: f64Side length of each cubic cell.
n_items: usizeTotal number of items currently stored.
Implementations§
Source§impl<T: Clone> SpatialHashPos3D<T>
impl<T: Clone> SpatialHashPos3D<T>
Sourcepub fn cell_coord(&self, x: f64) -> i32
pub fn cell_coord(&self, x: f64) -> i32
Maps a coordinate to its cell index.
Sourcepub fn cell_key(&self, pos: [f64; 3]) -> (i32, i32, i32)
pub fn cell_key(&self, pos: [f64; 3]) -> (i32, i32, i32)
Returns the 3-D cell key for a world-space position.
Sourcepub fn insert(&mut self, id: usize, pos: [f64; 3], data: T) -> (i32, i32, i32)
pub fn insert(&mut self, id: usize, pos: [f64; 3], data: T) -> (i32, i32, i32)
Inserts item and returns its cell key.
Sourcepub fn remove(&mut self, id: usize, pos: [f64; 3])
pub fn remove(&mut self, id: usize, pos: [f64; 3])
Removes the entry with the given id from the cell containing pos.
Sourcepub fn query_radius(&self, center: [f64; 3], radius: f64) -> Vec<(usize, &T)>
pub fn query_radius(&self, center: [f64; 3], radius: f64) -> Vec<(usize, &T)>
Returns all items within a sphere, with exact distance filtering.
Sourcepub fn query_aabb(&self, min: [f64; 3], max: [f64; 3]) -> Vec<(usize, &T)>
pub fn query_aabb(&self, min: [f64; 3], max: [f64; 3]) -> Vec<(usize, &T)>
Returns all items within an axis-aligned box defined by min and max.
Sourcepub fn k_nearest(&self, center: [f64; 3], k: usize) -> Vec<(usize, f64, &T)>
pub fn k_nearest(&self, center: [f64; 3], k: usize) -> Vec<(usize, f64, &T)>
Find the k nearest neighbours of center.
Uses an expanding search radius starting at cell_size and doubling until at least k candidates are found, then filters to the true k nearest.
Sourcepub fn query_cell(&self, key: (i32, i32, i32)) -> Vec<(usize, &T)>
pub fn query_cell(&self, key: (i32, i32, i32)) -> Vec<(usize, &T)>
Returns all items stored in the given cell.
Sourcepub fn statistics(&self) -> SpatialHashStats
pub fn statistics(&self) -> SpatialHashStats
Compute statistics about the spatial hash distribution.
Auto Trait Implementations§
impl<T> Freeze for SpatialHashPos3D<T>
impl<T> RefUnwindSafe for SpatialHashPos3D<T>where
T: RefUnwindSafe,
impl<T> Send for SpatialHashPos3D<T>where
T: Send,
impl<T> Sync for SpatialHashPos3D<T>where
T: Sync,
impl<T> Unpin for SpatialHashPos3D<T>where
T: Unpin,
impl<T> UnsafeUnpin for SpatialHashPos3D<T>
impl<T> UnwindSafe for SpatialHashPos3D<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.