pub struct SparseGrid<T> { /* private fields */ }
Expand description
A simple data structure for storing values in a sparse 2d grid.
Implementations§
Source§impl<T> SparseGrid<T>
impl<T> SparseGrid<T>
pub fn new(size: UVec2) -> Self
pub fn insert(&mut self, pos: impl GridPoint, value: T)
pub fn get(&self, pos: impl GridPoint) -> Option<&T>
pub fn get_mut(&mut self, pos: impl GridPoint) -> Option<&mut T>
pub fn remove(&mut self, pos: impl GridPoint) -> Option<T>
pub fn iter(&self) -> impl Iterator<Item = (&IVec2, &T)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&IVec2, &mut T)>
Trait Implementations§
Source§impl<T, P: GridPoint> Index<P> for SparseGrid<T>
impl<T, P: GridPoint> Index<P> for SparseGrid<T>
Source§impl<T> SizedGrid for SparseGrid<T>
impl<T> SizedGrid for SparseGrid<T>
fn size(&self) -> UVec2
fn width(&self) -> usize
fn height(&self) -> usize
fn tile_count(&self) -> usize
fn in_bounds(&self, p: impl Into<PivotedPoint>) -> bool
Source§fn transform_lti(&self, pos: impl Into<PivotedPoint>) -> usize
fn transform_lti(&self, pos: impl Into<PivotedPoint>) -> usize
Transform a local 2d grid position to a 1d array index.
Source§fn transform_itl(&self, i: usize) -> IVec2
fn transform_itl(&self, i: usize) -> IVec2
Transform an 1d array index to a local 2d grid position.
Source§fn try_transform_lti(&self, pos: impl Into<PivotedPoint>) -> Option<usize>
fn try_transform_lti(&self, pos: impl Into<PivotedPoint>) -> Option<usize>
Attempt to transform a 2d grid position to a 1d array index, returning
None if the position is out of bounds.
Source§fn try_transform_itl(&self, i: usize) -> Option<IVec2>
fn try_transform_itl(&self, i: usize) -> Option<IVec2>
Attempt to transform an 1d array index to a local 2d grid position.
Returns None if the index is out of bounds.
Source§fn bottom_index(&self) -> usize
fn bottom_index(&self) -> usize
Index of the bottom row of the rect. Read more
Source§fn left_index(&self) -> usize
fn left_index(&self) -> usize
Index of the left column of the rect. Read more
Source§fn right_index(&self) -> usize
fn right_index(&self) -> usize
The index of the right most column of the rect. Read more
fn grid_bounds(&self) -> GridRect
fn iter_grid_points(&self) -> GridRectIter
Auto Trait Implementations§
impl<T> Freeze for SparseGrid<T>
impl<T> RefUnwindSafe for SparseGrid<T>where
T: RefUnwindSafe,
impl<T> Send for SparseGrid<T>where
T: Send,
impl<T> Sync for SparseGrid<T>where
T: Sync,
impl<T> Unpin for SparseGrid<T>
impl<T> UnwindSafe for SparseGrid<T>where
T: RefUnwindSafe,
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