Skip to main content

SpatialHashGrid2D

Struct SpatialHashGrid2D 

Source
pub struct SpatialHashGrid2D { /* private fields */ }
Expand description

O(1) uniform-cell 2D spatial hash grid with reusable scratch buffers and zero steady-state allocations.

Implementations§

Source§

impl SpatialHashGrid2D

Zero-allocation open-addressed uniform-cell 2D spatial hash grid operations.

Source

pub fn new(cell_size: f32) -> Self

Creates an empty SpatialHashGrid2D with uniform cell_size.

§Arguments
  • f32 - Cell edge length (clamped to >= 1e-4).
§Returns
  • Self - Pre-allocated 2D spatial hash grid.
Source

pub fn clear(&mut self)

Clears all entries in O(active_cells) time while retaining every internal buffer’s capacity.

Source

pub fn insert_bounds(&mut self, id: u64, bounds: Bounds2D)

Inserts an item (id, bounds) into every cell overlapped by bounds.

§Arguments
  • u64 - Entity identifier.
  • Bounds2D - World-space 2D bounding rectangle.
Source

pub fn insert_point(&mut self, id: u64, position: Vec2)

Inserts a point item (id, position) into its enclosing cell.

§Arguments
  • u64 - Entity identifier.
  • Vec2 - World-space 2D position.
Source

pub fn query_rect_into(&self, query_bounds: Bounds2D, out: &mut Vec<u64>)

Queries all items overlapping query_bounds, writing deduplicated IDs into out.

§Arguments
  • Bounds2D - Query rectangle.
  • &mut Vec<u64> - Reusable output buffer (cleared and deduplicated).
Source

pub fn query_radius_into(&self, center: Vec2, radius: f32, out: &mut Vec<u64>)

Queries all items overlapping circle (center, radius), writing deduplicated IDs into out.

§Arguments
  • Vec2 - Query circle center.
  • f32 - Query radius.
  • &mut Vec<u64> - Reusable output buffer (cleared and deduplicated).
Source

pub fn query_radius(&mut self, center: Vec2, radius: f32) -> &[u64]

Queries items within (center, radius) into the grid’s internal reusable scratch slice.

§Arguments
  • Vec2 - Query circle center.
  • f32 - Query radius.
§Returns
  • &[u64] - Deduplicated matching IDs stored in the internal scratch buffer.
Source§

impl SpatialHashGrid2D

Implements impl #impl_generics #name #ty_generics #where_clause.

Source

pub fn get_cell_size(&self) -> f32

Source

pub fn get_mut_cell_size(&mut self) -> &mut f32

Source

pub fn set_cell_size(&mut self, val: f32) -> &mut Self

Source

pub fn get_inv_cell_size(&self) -> f32

Source

pub fn get_mut_inv_cell_size(&mut self) -> &mut f32

Source

pub fn set_inv_cell_size(&mut self, val: f32) -> &mut Self

Source

pub fn get_occupied_buckets(&self) -> usize

Source

pub fn get_mut_occupied_buckets(&mut self) -> &mut usize

Source

pub fn set_occupied_buckets(&mut self, val: usize) -> &mut Self

Trait Implementations§

Source§

impl Clone for SpatialHashGrid2D

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpatialHashGrid2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for SpatialHashGrid2D

§

impl Freeze for SpatialHashGrid2D
where *const u8 is !null: Freeze, PhantomData<SpatialHashBucket2D>: Freeze, PhantomData<usize>: Freeze, PhantomData<SpatialHashEntry2D>: Freeze, PhantomData<u64>: Freeze,

§

impl Move for SpatialHashGrid2D

§

impl RefUnwindSafe for SpatialHashGrid2D

§

impl Send for SpatialHashGrid2D
where RawVecInner: Send,

§

impl Sync for SpatialHashGrid2D
where RawVecInner: Sync,

§

impl Unpin for SpatialHashGrid2D
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for SpatialHashGrid2D
where *const u8 is !null: UnsafeUnpin, PhantomData<SpatialHashBucket2D>: UnsafeUnpin, PhantomData<usize>: UnsafeUnpin, PhantomData<SpatialHashEntry2D>: UnsafeUnpin, PhantomData<u64>: UnsafeUnpin,

§

impl UnwindSafe for SpatialHashGrid2D
where RawVecInner: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.