Skip to main content

SpatialHashPos3D

Struct SpatialHashPos3D 

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

Side length of each cubic cell.

§n_items: usize

Total number of items currently stored.

Implementations§

Source§

impl<T: Clone> SpatialHashPos3D<T>

Source

pub fn new(cell_size: f64) -> Self

Creates a new empty hash with the given cell size.

Source

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

Maps a coordinate to its cell index.

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 item and returns its cell key.

Source

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

Removes the entry with the given id from the cell containing pos.

Source

pub fn query_radius(&self, center: [f64; 3], radius: f64) -> Vec<(usize, &T)>

Returns all items within a sphere, with exact distance filtering.

Source

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.

Source

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.

Source

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

Returns all items stored in the given cell.

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.

Source

pub fn statistics(&self) -> SpatialHashStats

Compute statistics about the spatial hash distribution.

Source

pub fn update_position( &mut self, id: usize, old_pos: [f64; 3], new_pos: [f64; 3], data: T, )

Update the position of an item (remove from old cell, insert into new).

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> 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.