Skip to main content

SpatialHashGrid2D

Struct SpatialHashGrid2D 

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

Source

pub fn create(cell_size: f64) -> SpatialHashGrid2D

Creates a new 2D spatial hash grid with the given cell size.

§Arguments
  • f64 - The world-space size of each grid cell.
§Returns
  • SpatialHashGrid2D - The new grid.
Source

pub fn with_default_size() -> SpatialHashGrid2D

Creates a new 2D spatial hash grid with the default cell size.

§Returns
  • SpatialHashGrid2D - The new grid.
Source

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

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

pub fn clear(&mut self)

Removes all entries from the grid, preparing it for a fresh insertion pass.

Source§

impl SpatialHashGrid2D

Source

pub fn get_cell_size(&self) -> f64

Source

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

Source

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

Source

pub fn get_inverse_cell_size(&self) -> f64

Source

pub fn get_mut_inverse_cell_size(&mut self) -> &mut f64

Source

pub fn get_cells(&self) -> &SpatialCellMap2D

Source

pub fn set_cells(&mut self, val: SpatialCellMap2D) -> &mut Self

Source§

impl SpatialHashGrid2D

Source

pub fn new(cell_size: f64) -> Self

Trait Implementations§

Source§

impl Clone for SpatialHashGrid2D

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Default for SpatialHashGrid2D

Implements Default for SpatialHashGrid2D with the default cell size.

Source§

fn default() -> SpatialHashGrid2D

Returns the “default value” for a type. Read more
Source§

impl PartialEq for SpatialHashGrid2D

Source§

fn eq(&self, other: &SpatialHashGrid2D) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for SpatialHashGrid2D

Auto Trait Implementations§

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 = 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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more