pub struct SpatialHashGrid2D { /* private fields */ }Expand description
A uniform-grid spatial hash for broad-phase collision culling in 2D.
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 SpatialHashGrid2D
Implements construction, insertion, and querying for SpatialHashGrid2D.
impl SpatialHashGrid2D
Implements construction, insertion, and querying for SpatialHashGrid2D.
Sourcepub fn create(cell_size: f64) -> SpatialHashGrid2D
pub fn create(cell_size: f64) -> SpatialHashGrid2D
Sourcepub fn with_default_size() -> SpatialHashGrid2D
pub fn with_default_size() -> SpatialHashGrid2D
Creates a new 2D spatial hash grid with the default cell size.
§Returns
SpatialHashGrid2D- The new grid.
Sourcepub fn insert(&mut self, index: usize, min: Vector2D, max: Vector2D)
pub fn insert(&mut self, index: usize, min: Vector2D, max: Vector2D)
Inserts a body index into all cells overlapping the given bounding box.
§Arguments
usize- The body index to insert.Vector2D- The minimum corner of the bounding box.Vector2D- The maximum corner of the bounding box.
Sourcepub fn query(&self, min: Vector2D, max: Vector2D) -> Vec<usize>
pub fn query(&self, min: Vector2D, max: Vector2D) -> Vec<usize>
Returns all candidate body indices whose cells overlap the given bounding box.
Deduplicates indices so each candidate appears at most once.
§Arguments
Vector2D- The minimum corner of the query box.Vector2D- The maximum corner of the query box.
§Returns
Vec<usize>- The list of candidate body indices.
Source§impl SpatialHashGrid2D
impl SpatialHashGrid2D
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) -> &SpatialCellMap2D
pub fn set_cells(&mut self, val: SpatialCellMap2D) -> &mut Self
Trait Implementations§
Source§impl Clone for SpatialHashGrid2D
impl Clone for SpatialHashGrid2D
Source§fn clone(&self) -> SpatialHashGrid2D
fn clone(&self) -> SpatialHashGrid2D
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for SpatialHashGrid2D
Implements Default for SpatialHashGrid2D with the default cell size.
impl Default for SpatialHashGrid2D
Implements Default for SpatialHashGrid2D with the default cell size.
Source§fn default() -> SpatialHashGrid2D
fn default() -> SpatialHashGrid2D
Returns the “default value” for a type. Read more
Source§impl PartialEq for SpatialHashGrid2D
impl PartialEq for SpatialHashGrid2D
Source§fn eq(&self, other: &SpatialHashGrid2D) -> bool
fn eq(&self, other: &SpatialHashGrid2D) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for SpatialHashGrid2D
Auto Trait Implementations§
impl Freeze for SpatialHashGrid2D
impl RefUnwindSafe for SpatialHashGrid2D
impl Send for SpatialHashGrid2D
impl Sync for SpatialHashGrid2D
impl Unpin for SpatialHashGrid2D
impl UnsafeUnpin for SpatialHashGrid2D
impl UnwindSafe for SpatialHashGrid2D
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