pub struct SpatialHashGrid3D { /* private fields */ }Expand description
A uniform-grid spatial hash for broad-phase collision culling in 3D.
Bodies are inserted by their world-space axis-aligned bounding box. A query returns all candidate indices whose AABBs overlap the query region, dramatically reducing narrow-phase collision checks from O(n²) to near O(n).
Implementations§
Source§impl SpatialHashGrid3D
Implements construction, insertion, and querying for SpatialHashGrid3D.
impl SpatialHashGrid3D
Implements construction, insertion, and querying for SpatialHashGrid3D.
Sourcepub fn create(cell_size: f64) -> SpatialHashGrid3D
pub fn create(cell_size: f64) -> SpatialHashGrid3D
Sourcepub fn with_default_size() -> SpatialHashGrid3D
pub fn with_default_size() -> SpatialHashGrid3D
Creates a new 3D spatial hash grid with the default cell size.
§Returns
SpatialHashGrid3D- The new grid.
Sourcepub fn insert(&mut self, index: usize, min: Vector3D, max: Vector3D)
pub fn insert(&mut self, index: usize, min: Vector3D, max: Vector3D)
Inserts a body index into all cells overlapping the given 3D bounding box.
§Arguments
usize- The body index to insert.Vector3D- The minimum corner of the bounding box.Vector3D- The maximum corner of the bounding box.
Sourcepub fn query(&self, min: Vector3D, max: Vector3D) -> Vec<usize>
pub fn query(&self, min: Vector3D, max: Vector3D) -> Vec<usize>
Returns all candidate body indices whose cells overlap the given 3D bounding box.
Deduplicates indices so each candidate appears at most once.
§Arguments
Vector3D- The minimum corner of the query box.Vector3D- The maximum corner of the query box.
§Returns
Vec<usize>- The list of candidate body indices.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all entries from the grid, preparing it for a fresh insertion pass.
Sourcepub fn query_into(
&self,
min: Vector3D,
max: Vector3D,
out: &mut Vec<usize>,
seen: &mut HashSet<usize>,
)
pub fn query_into( &self, min: Vector3D, max: Vector3D, out: &mut Vec<usize>, seen: &mut HashSet<usize>, )
Appends all candidate body indices overlapping the query box into out,
deduplicating via the caller-provided seen set.
Both out and seen are cleared first, so the caller can reuse the same
buffers across all queries in a step without any per-query allocation.
§Arguments
Vector3D- The minimum corner of the query box.Vector3D- The maximum corner of the query box.&mut Vec<usize>- The output buffer, cleared then filled with candidates.&mut HashSet<usize>- The dedup scratch set, cleared then reused.
Source§impl SpatialHashGrid3D
impl SpatialHashGrid3D
pub fn get_cell_size(&self) -> f64
pub fn get_mut_cell_size(&mut self) -> &mut f64
pub fn set_cell_size(&mut self, val: f64) -> &mut Self
pub fn get_inverse_cell_size(&self) -> f64
pub fn get_mut_inverse_cell_size(&mut self) -> &mut f64
pub fn get_cells(&self) -> &SpatialCellMap3D
pub fn set_cells(&mut self, val: SpatialCellMap3D) -> &mut Self
Trait Implementations§
Source§impl Clone for SpatialHashGrid3D
impl Clone for SpatialHashGrid3D
Source§fn clone(&self) -> SpatialHashGrid3D
fn clone(&self) -> SpatialHashGrid3D
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SpatialHashGrid3D
impl Debug for SpatialHashGrid3D
Source§impl Default for SpatialHashGrid3D
Implements Default for SpatialHashGrid3D with the default cell size.
impl Default for SpatialHashGrid3D
Implements Default for SpatialHashGrid3D with the default cell size.