Skip to main content

SpatialGrid

Struct SpatialGrid 

Source
pub struct SpatialGrid<T> { /* private fields */ }
Expand description

Spatial grid for efficient 2D neighbor queries.

Uses a dense grid-based approach where the detector area is divided into cells. This implementation is optimized for fixed-size detectors and avoids hashing overhead.

Implementations§

Source§

impl<T: Clone> SpatialGrid<T>

Source

pub fn new(cell_size: usize, width: usize, height: usize) -> Self

Create a new spatial grid.

§Arguments
  • cell_size - Size of each cell in pixels (e.g., 32).
  • width - Total width of the detector in pixels (e.g., 256).
  • height - Total height of the detector in pixels (e.g., 256).
Source

pub fn clear(&mut self)

Clear all data but keep allocations.

Source

pub fn ensure_dimensions(&mut self, width: usize, height: usize)

Ensure the grid is large enough for the given dimensions.

If the grid is resized, all existing data is CLEARED.

Source

pub fn insert(&mut self, x: i32, y: i32, value: T)

Insert a value at the given coordinates.

Ignores values outside the grid bounds.

Source

pub fn remove(&mut self, x: i32, y: i32, value: &T)
where T: PartialEq,

Remove a value from the given coordinates.

Source

pub fn get_cell_slice(&self, x: i32, y: i32) -> Option<&[T]>

Get reference to the slice of values in the cell at (x, y).

Source

pub fn width_cells(&self) -> usize

Get the grid width in cells.

Source

pub fn height_cells(&self) -> usize

Get the grid height in cells.

Source

pub fn cell_size(&self) -> usize

Get the configured cell size.

Source

pub fn query_neighborhood(&self, x: i32, y: i32, buffer: &mut Vec<T>)

Query the 3x3 neighborhood around a point.

Appends neighbors to the provided buffer to avoid allocation.

Trait Implementations§

Source§

impl<T: Debug> Debug for SpatialGrid<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for SpatialGrid<T>

Source§

fn default() -> SpatialGrid<T>

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

Auto Trait Implementations§

§

impl<T> Freeze for SpatialGrid<T>

§

impl<T> RefUnwindSafe for SpatialGrid<T>
where T: RefUnwindSafe,

§

impl<T> Send for SpatialGrid<T>
where T: Send,

§

impl<T> Sync for SpatialGrid<T>
where T: Sync,

§

impl<T> Unpin for SpatialGrid<T>
where T: Unpin,

§

impl<T> UnwindSafe for SpatialGrid<T>
where T: 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.