Struct SparseGrid

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

Source

pub fn new(size: UVec2) -> Self

Source

pub fn insert(&mut self, pos: impl GridPoint, value: T)

Source

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

Source

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

Source

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

Source

pub fn iter(&self) -> impl Iterator<Item = (&IVec2, &T)>

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&IVec2, &mut T)>

Trait Implementations§

Source§

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

Source§

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, P: GridPoint> IndexMut<P> for SparseGrid<T>
where T: Default,

Source§

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

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

impl<T> SizedGrid for SparseGrid<T>

Source§

fn size(&self) -> UVec2

Source§

fn width(&self) -> usize

Source§

fn height(&self) -> usize

Source§

fn tile_count(&self) -> usize

Source§

fn in_bounds(&self, p: impl Into<PivotedPoint>) -> bool

Source§

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

Transform an 1d array index to a local 2d grid position.
Source§

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>

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

Index of the bottom row of the rect. Read more
Source§

fn top_index(&self) -> usize

Index of the top row of the rect. Read more
Source§

fn left_index(&self) -> usize

Index of the left column of the rect. Read more
Source§

fn right_index(&self) -> usize

The index of the right most column of the rect. Read more
Source§

fn grid_bounds(&self) -> GridRect

Source§

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