Struct sark_grids::grid::Grid

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

A dense sized grid that stores it’s elements in a Vec.

Implementations§

source§

impl<T> Grid<T>

source

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

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

source

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

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 width(&self) -> usize

source

pub fn height(&self) -> usize

source

pub fn size(&self) -> UVec2

source

pub fn len(&self) -> usize

How many tiles/elements are in the grid.

source

pub fn pivot_position(&self, pivot: Pivot) -> IVec2

Get the position of the given pivot point on the grid.

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 in_bounds(&self, pos: impl GridPoint) -> bool

source

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

Gets the index for a given side.

source

pub fn axis_size(&self, axis: usize) -> usize

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_rows( &self, range: impl RangeBounds<usize> ) -> impl DoubleEndedIterator<Item = &[T]>

Iterate over a range of rows.

Yields &[T] (Slice of T)

source

pub fn iter_rows_mut( &mut self, range: impl RangeBounds<usize> ) -> impl DoubleEndedIterator<Item = &mut [T]>

Iterate mutably over a range of rows.

Yields &mut [T] (Slice of mutable T)

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 axis_index(&self, axis: usize) -> usize

Final index along a given axis, where 0 == width, and 1 == height.

source

pub fn rect_iter( &self, range: impl RangeBounds<[i32; 2]> ) -> impl Iterator<Item = (IVec2, &T)>

An iterator over a rectangular portion of the grid defined by the given range.

Yields (IVec2, &T), where IVec2 is the corresponding position of the value in the grid.

source

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

Returns an iterator which enumerates the 2d position of every value in the grid.

Yields (IVec2, &T), where IVec2 is the corresponding position of the value in the grid.

source

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

Returns a mutable iterator which enumerates the 2d position of every value in the grid.

Yields (IVec2, &mut T), where IVec2 is the corresponding position of the value in the grid.

source

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

Retrieve a linear slice of the underlying grid data.

source

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

Retrieve a mutable linear slice of the underlying grid data.

source

pub fn bounds(&self) -> GridRect

Returns the bounds of the grid.

source

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

Converts a 2d grid position to it’s corresponding 1D index. If a pivot was applied to the given grid point, it will be accounted for.

source

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

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

source

pub fn transform_ltw(&self, xy: impl GridPoint) -> IVec2

Convert a point from grid space (bottom-left origin) to world space (center origin).

source

pub fn transform_wtl(&self, xy: impl GridPoint) -> IVec2

Convert a point from world space (center origin) to grid space (bottom-left origin).

source

pub fn pivoted_point(&self, xy: impl GridPoint) -> IVec2

Retrieve a grid position from a pivoted point.

If no pivot has been applied, the point will be returned directly.

Trait Implementations§

source§

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

source§

fn clone(&self) -> Grid<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 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>

§

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>

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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> 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.