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>
impl<T: Clone> SpatialGrid<T>
Sourcepub fn new(cell_size: usize, width: usize, height: usize) -> Self
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).
Sourcepub fn ensure_dimensions(&mut self, width: usize, height: usize)
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.
Sourcepub fn insert(&mut self, x: i32, y: i32, value: T)
pub fn insert(&mut self, x: i32, y: i32, value: T)
Insert a value at the given coordinates.
Ignores values outside the grid bounds.
Sourcepub fn remove(&mut self, x: i32, y: i32, value: &T)where
T: PartialEq,
pub fn remove(&mut self, x: i32, y: i32, value: &T)where
T: PartialEq,
Remove a value from the given coordinates.
Sourcepub fn get_cell_slice(&self, x: i32, y: i32) -> Option<&[T]>
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).
Sourcepub fn width_cells(&self) -> usize
pub fn width_cells(&self) -> usize
Get the grid width in cells.
Sourcepub fn height_cells(&self) -> usize
pub fn height_cells(&self) -> usize
Get the grid height in cells.
Sourcepub fn query_neighborhood(&self, x: i32, y: i32, buffer: &mut Vec<T>)
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>
impl<T: Debug> Debug for SpatialGrid<T>
Source§impl<T: Default> Default for SpatialGrid<T>
impl<T: Default> Default for SpatialGrid<T>
Source§fn default() -> SpatialGrid<T>
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> 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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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