Skip to main content

SpatialHash3D

Struct SpatialHash3D 

Source
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: f64

Side length of each cubic cell.

§n_items: usize

Total number of items currently stored.

Implementations§

Source§

impl<T: Clone> SpatialHash3D<T>

Source

pub fn new(cell_size: f64) -> Self

Creates a new empty spatial hash with the given cell size.

Source

pub fn cell_coord(&self, x: f64) -> i32

Maps a single coordinate to its cell index via floor(x / cell_size).

Source

pub fn cell_key(&self, pos: [f64; 3]) -> (i32, i32, i32)

Returns the 3-D cell key for a world-space position.

Source

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.

Source

pub fn remove(&mut self, id: usize, pos: [f64; 3])

Removes the entry with the given id from the cell that contains pos.

Source

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.

Source

pub fn query_cell(&self, key: (i32, i32, i32)) -> Vec<(usize, &T)>

Returns all items stored in the given cell key.

Source

pub fn clear(&mut self)

Removes all items.

Source

pub fn len(&self) -> usize

Returns the total number of items stored.

Source

pub fn is_empty(&self) -> bool

Returns true if no items are stored.

Source

pub fn n_cells(&self) -> usize

Returns the number of non-empty cells.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.