pub struct SpatialHashGrid { /* private fields */ }Expand description
Dense spatial grid for O(1) entity lookup by position.
Grid cells are cell_size x cell_size world units.
Uses u64 entity handles — zero-copy, no per-entity String allocation.
Implementations§
Source§impl SpatialHashGrid
impl SpatialHashGrid
Sourcepub fn cell_key(&self, x: i32, y: i32) -> (i32, i32)
pub fn cell_key(&self, x: i32, y: i32) -> (i32, i32)
Compute the cell key for a world-space position.
Sourcepub fn insert(&mut self, entity_id: u64, x: i32, y: i32)
pub fn insert(&mut self, entity_id: u64, x: i32, y: i32)
Insert an entity at world position (x, y).
Sourcepub fn remove(&mut self, entity_id: u64, x: i32, y: i32)
pub fn remove(&mut self, entity_id: u64, x: i32, y: i32)
Remove an entity from its cell at world position (x, y). Removes the first occurrence. No-ops if not present.
Sourcepub fn query_radius(&self, cx: i32, cy: i32, radius: i32) -> Vec<u64>
pub fn query_radius(&self, cx: i32, cy: i32, radius: i32) -> Vec<u64>
Query all entities within radius world units of (cx, cy).
Scans O(radius^2 / cell_size^2) cells.
Sourcepub fn query_cell(&self, x: i32, y: i32) -> &[u64]
pub fn query_cell(&self, x: i32, y: i32) -> &[u64]
Return all entity IDs in the cell containing world position (x, y).
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Return the total number of entity references across all cells.
Sourcepub fn cell_count(&self) -> usize
pub fn cell_count(&self) -> usize
Return the number of occupied cells.
Auto Trait Implementations§
impl Freeze for SpatialHashGrid
impl RefUnwindSafe for SpatialHashGrid
impl Send for SpatialHashGrid
impl Sync for SpatialHashGrid
impl Unpin for SpatialHashGrid
impl UnsafeUnpin for SpatialHashGrid
impl UnwindSafe for SpatialHashGrid
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