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

A sparse grid that stores elements in a BTreeMap.

Implementations§

source§

impl<T: Clone> SparseGrid<T>

source

pub fn new(size: impl GridPoint) -> Self

Creates a new SparseGrid.

source

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.

source

pub fn iter_values(&self) -> impl Iterator<Item = &T>

An iterator over just the values in the grid.

Yields &T.

source

pub fn iter_values_mut(&mut self) -> impl Iterator<Item = &mut T>

A mutable iterator over just the values in the grid.

Yields &mut T.

source

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.

source

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.

source

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.

source

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.

source

pub fn insert_row_at( &mut self, xy: impl GridPoint, 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.

source

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.

source

pub fn insert_column_at( &mut self, xy: impl GridPoint, 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.

source

pub fn remove(&mut self, pos: impl GridPoint) -> Option<T>

Remove the element/tile at the given position.

Returns the removed element if one was present.

source

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.

source

pub fn clear(&mut self)

Clears the grid, removing all elements.

source

pub fn width(&self) -> usize

source

pub fn height(&self) -> usize

source

pub fn size(&self) -> IVec2

source

pub fn len(&self) -> usize

How many tiles/elements are in the grid.

source

pub fn is_empty(&self) -> bool

source

pub fn transform_lti(&self, pos: impl GridPoint) -> usize

Converts a 2d grid position to it’s corresponding 1D index.

source

pub fn transform_itl(&self, index: usize) -> impl GridPoint

Converts a 1d index to it’s corresponding grid position.

source

pub fn side_index(&self, side: Side) -> usize

Gets the index for a given side.

source

pub fn in_bounds(&self, pos: impl GridPoint) -> bool

Returns true if the position is in the bounds of the grid. Note this doesn’t necessarily mean a tile exists at that point - just that it’s in bounds.

source

pub fn bounds(&self) -> GridRect

Returns the bounds of the grid.

source

pub fn insert_index(&mut self, index: usize, value: T) -> Option<T>

Insert a value in the grid at the given 1d index.

Returns None if no value was already present. Otherwise the old value is returned.

source

pub fn insert(&mut self, pos: impl GridPoint, value: T) -> Option<T>

Insert a value in the grid.

Returns None if no value was already present. Otherwise the old value is returned.

source

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.

source

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.

source

pub fn get(&self, pos: impl GridPoint) -> Option<&T>

Retrieve a value in the grid from it’s 2d position.

Returns None if there is no value at the position, or if the position is out of bounds.

source

pub fn get_mut(&mut self, pos: impl GridPoint) -> Option<&mut T>

Retrieve a mutable value in the grid from it’s 2d position.

Returns None if there is no value at the position.

Trait Implementations§

source§

impl<T: Clone> Clone for SparseGrid<T>

source§

fn clone(&self) -> SparseGrid<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for SparseGrid<T>

source§

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

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

impl<T: Default> Default for SparseGrid<T>

source§

fn default() -> SparseGrid<T>

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

impl<T: Clone, P: GridPoint> Index<P> for SparseGrid<T>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: P) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T: Clone> Index<usize> for SparseGrid<T>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T, P: GridPoint> IndexMut<P> for SparseGrid<T>
where T: Default + Clone,

source§

fn index_mut(&mut self, index: P) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T> IndexMut<usize> for SparseGrid<T>
where T: Default + Clone,

source§

fn index_mut(&mut self, index: usize) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more

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> 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.