Struct sark_grids::sparse_grid::SparseGrid
source · [−]pub struct SparseGrid<T: Clone> { /* private fields */ }
Expand description
A sparse grid that stores elements in a BTreeMap.
Implementations
sourceimpl<T: Clone> SparseGrid<T>
impl<T: Clone> SparseGrid<T>
sourcepub fn new(size: impl Size2d) -> Self
pub fn new(size: impl Size2d) -> Self
Creates a new SparseGrid
sourcepub fn iter(&self) -> impl Iterator<Item = (&usize, &T)>
pub fn iter(&self) -> impl Iterator<Item = (&usize, &T)>
An iterator over all elements in the grid.
Yields (&usize,&mut T)
where usize
is the 1d position of the element in the grid.
sourcepub fn iter_values(&self) -> impl Iterator<Item = &T>
pub fn iter_values(&self) -> impl Iterator<Item = &T>
An iterator over just the values in the grid.
Yields &T
.
sourcepub fn iter_values_mut(&self) -> impl Iterator<Item = &T>
pub fn iter_values_mut(&self) -> impl Iterator<Item = &T>
A mutable iterator over just the values in the grid.
Yields &mut T
.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&usize, &mut T)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&usize, &mut T)>
A mutable iterator over all elements in the grid.
Yields (&usize,&mut T)
where usize
is the 1d position of the element in the grid.
sourcepub fn iter_2d(&self) -> impl Iterator<Item = (IVec2, &T)>
pub fn iter_2d(&self) -> impl Iterator<Item = (IVec2, &T)>
A 2d iterator over all elements in the grid.
Yields (IVec2,&mut T)
where IVec2
is the 2d position of the element in the grid.
sourcepub fn iter_mut_2d(&mut self) -> impl Iterator<Item = (IVec2, &mut T)>
pub fn iter_mut_2d(&mut self) -> impl Iterator<Item = (IVec2, &mut T)>
A mutable iterator over all elements in the grid.
Yields (IVec,&mut T)
where IVec2
is the 2d position of the element in the grid.
sourcepub fn insert_row(
&mut self,
y: usize,
row: impl IntoIterator<Item = T> + Iterator<Item = T>
)
pub fn insert_row(
&mut self,
y: usize,
row: impl IntoIterator<Item = T> + Iterator<Item = T>
)
Insert into a row of the grid using an iterator.
Will insert up to the length of a row.
sourcepub fn insert_row_at(
&mut self,
xy: impl Point2d,
row: impl IntoIterator<Item = T> + Iterator<Item = T>
)
pub fn insert_row_at(
&mut self,
xy: impl Point2d,
row: impl IntoIterator<Item = T> + Iterator<Item = T>
)
Insert into a row of the grid using an iterator.
Will insert up to the length of a row.
sourcepub fn insert_column(
&mut self,
x: usize,
column: impl IntoIterator<Item = T> + Iterator<Item = T>
)
pub fn insert_column(
&mut self,
x: usize,
column: impl IntoIterator<Item = T> + Iterator<Item = T>
)
Insert into a column of the grid using an iterator.
Will insert up to the height of a column.
sourcepub fn insert_column_at(
&mut self,
xy: impl Point2d,
column: impl IntoIterator<Item = T> + Iterator<Item = T>
)
pub fn insert_column_at(
&mut self,
xy: impl Point2d,
column: impl IntoIterator<Item = T> + Iterator<Item = T>
)
Insert into a column of the grid starting from some point using an iterator.
Will insert up to the height of a column.
sourcepub fn remove(&mut self, pos: impl Point2d) -> Option<T>
pub fn remove(&mut self, pos: impl Point2d) -> Option<T>
Remove the element/tile at the given position.
Returns the removed element if one was present.
sourcepub fn remove_index(&mut self, index: usize) -> Option<T>
pub fn remove_index(&mut self, index: usize) -> Option<T>
Remove the element/tile at the given 1d index.
Returns the removed element if one was present.
pub fn width(&self) -> usize
pub fn height(&self) -> usize
pub fn size(&self) -> impl Point2d
pub fn is_empty(&self) -> bool
sourcepub fn pos_to_index(&self, pos: impl Point2d) -> usize
pub fn pos_to_index(&self, pos: impl Point2d) -> usize
Converts a 2d grid position to it’s corresponding 1D index.
sourcepub fn index_to_pos(&self, index: usize) -> impl Point2d
pub fn index_to_pos(&self, index: usize) -> impl Point2d
Converts a 1d index to it’s corresponding grid position.
sourcepub fn side_index(&self, side: Side) -> usize
pub fn side_index(&self, side: Side) -> usize
Gets the index for a given side.
pub fn is_in_bounds(&self, pos: impl Point2d) -> bool
sourcepub fn insert_index(&mut self, index: usize, value: T) -> Option<T>
pub fn insert_index(&mut self, index: usize, value: T) -> Option<T>
Insert a value in the grid.
Returns None
if no value was already present. Otherwise the old value
is returned.
sourcepub fn insert(&mut self, pos: impl Point2d, value: T) -> Option<T>
pub fn insert(&mut self, pos: impl Point2d, value: T) -> Option<T>
Insert a value in the grid.
Returns None
if no value was already present. Otherwise the old value
is returned.
sourcepub fn get_index(&self, index: usize) -> Option<&T>
pub fn get_index(&self, index: usize) -> Option<&T>
Retrieve a value in the grid from it’s 1d index.
Returns None
if there is no value at the index.
sourcepub fn get_mut_index(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut_index(&mut self, index: usize) -> Option<&mut T>
Retrieve a mutable value in the grid from it’s 1d index.
Returns None
if there is no value at the index.
Trait Implementations
sourceimpl<T: Clone + Clone> Clone for SparseGrid<T>
impl<T: Clone + Clone> Clone for SparseGrid<T>
sourcefn clone(&self) -> SparseGrid<T>
fn clone(&self) -> SparseGrid<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T: Debug + Clone> Debug for SparseGrid<T>
impl<T: Debug + Clone> Debug for SparseGrid<T>
sourceimpl<T: Default + Clone> Default for SparseGrid<T>
impl<T: Default + Clone> Default for SparseGrid<T>
sourcefn default() -> SparseGrid<T>
fn default() -> SparseGrid<T>
Returns the “default value” for a type. Read more
sourceimpl<T: Clone, P: Point2d> Index<P> for SparseGrid<T>
impl<T: Clone, P: Point2d> Index<P> for SparseGrid<T>
sourceimpl<T: Clone> Index<usize> for SparseGrid<T>
impl<T: Clone> Index<usize> for SparseGrid<T>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more