pub struct SpatialHash3D<T: Clone> {
pub cell_size: f64,
pub n_items: usize,
/* private fields */
}Expand description
A uniform-grid spatial hash that maps 3-D positions to arbitrary data.
Items are bucketed by their cell coordinate
(floor(x/cell_size), floor(y/cell_size), floor(z/cell_size)).
Fields§
§cell_size: f64Side length of each cubic cell.
n_items: usizeTotal number of items currently stored.
Implementations§
Source§impl<T: Clone> SpatialHash3D<T>
impl<T: Clone> SpatialHash3D<T>
Sourcepub fn cell_coord(&self, x: f64) -> i32
pub fn cell_coord(&self, x: f64) -> i32
Maps a single coordinate to its cell index via floor(x / cell_size).
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 (id, data) at pos and returns the cell key it was placed in.
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 that contains 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 the cells overlapping a sphere of radius
centred at center. Note: without stored positions, exact distance
filtering is not possible; use SpatialHashPos3D for exact queries.
Auto Trait Implementations§
impl<T> Freeze for SpatialHash3D<T>
impl<T> RefUnwindSafe for SpatialHash3D<T>where
T: RefUnwindSafe,
impl<T> Send for SpatialHash3D<T>where
T: Send,
impl<T> Sync for SpatialHash3D<T>where
T: Sync,
impl<T> Unpin for SpatialHash3D<T>where
T: Unpin,
impl<T> UnsafeUnpin for SpatialHash3D<T>
impl<T> UnwindSafe for SpatialHash3D<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.