Grid

Struct Grid 

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

A data structure for storing a 2d sized grid of data.

Implementations§

Source§

impl<T> Grid<T>

Source

pub fn new(size: impl GridPoint) -> Self
where T: Default + Clone,

Source

pub fn filled(value: T, size: impl GridPoint) -> Self
where T: Clone,

Creates a new Grid with all elements set to the given default value.

Source

pub fn insert_row(&mut self, y: usize, row: impl DoubleEndedIterator<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 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>)

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

Insert into a column of the grid using an iterator.

Will insert up to the height of a column.

Source

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

Try to retrieve the value at the given position.

Returns None if the position is out of bounds.

Source

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

Try to retrieve the mutable value at the given position.

Returns None if the position is out of bounds.

Source

pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T>

An iterator over all elements in the grid.

Source

pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T>

A mutable iterator over all elements in the grid.

Source

pub fn iter_row(&self, y: usize) -> impl DoubleEndedIterator<Item = &T>

An iterator over a single row of the grid.

Goes from left to right.

Source

pub fn iter_row_mut( &mut self, y: usize, ) -> impl DoubleEndedIterator<Item = &mut T>

A mutable iterator over a single row of the grid.

Iterates from left to right.

Source

pub fn iter_column(&self, x: usize) -> impl DoubleEndedIterator<Item = &T>

An iterator over a single column of the grid.

Goes from bottom to top.

Source

pub fn iter_column_mut( &mut self, x: usize, ) -> impl DoubleEndedIterator<Item = &mut T>

A mutable iterator over a single column of the grid.

Goes from bottom to top.

Source

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

Iterate over all grid elements along with their 2d positions.

Source

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

Iterate over all grid elements along with their 2d positions.

Source

pub fn iter_rect(&self, rect: GridRect) -> impl Iterator<Item = (IVec2, &T)>

Iterate over a rectangular section of grid elements along with their 2d positions.

Source

pub fn iter_rect_mut( &mut self, rect: GridRect, ) -> impl Iterator<Item = (IVec2, &mut T)>

Iterate over a rectangular section of grid elements along with their 2d positions.

Source

pub fn slice(&self) -> &[T]

Retrieve a slice of the underlying grid data.

Source

pub fn slice_mut(&mut self) -> &mut [T]

Retrieve a mutable slice of the underlying grid data.

Source

pub fn bounds(&self) -> GridRect

Returns the bounds of the grid, with it’s bottom left tile at world origin.

Trait Implementations§

Source§

impl<T: Clone> Clone for Grid<T>

Source§

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

Returns a duplicate 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 Grid<T>

Source§

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

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

impl<T> Default for Grid<T>

Source§

fn default() -> Self

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

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

Source§

type Output = T

The returned type after indexing.
Source§

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

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

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

Source§

type Output = T

The returned type after indexing.
Source§

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

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

impl<T, P: GridPoint> IndexMut<P> for Grid<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 Grid<T>
where T: Default + Clone,

Source§

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

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

impl<T: PartialEq> PartialEq for Grid<T>

Source§

fn eq(&self, other: &Grid<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> SizedGrid for Grid<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

Source§

impl<T: Eq> Eq for Grid<T>

Source§

impl<T> StructuralPartialEq for Grid<T>

Auto Trait Implementations§

§

impl<T> Freeze for Grid<T>

§

impl<T> RefUnwindSafe for Grid<T>
where T: RefUnwindSafe,

§

impl<T> Send for Grid<T>
where T: Send,

§

impl<T> Sync for Grid<T>
where T: Sync,

§

impl<T> Unpin for Grid<T>
where T: Unpin,

§

impl<T> UnwindSafe for Grid<T>
where T: UnwindSafe,

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.