Struct sark_grids::grid::Grid
source · [−]pub struct Grid<T: Clone> { /* private fields */ }
Expand description
A dense sized grid that stores it’s elements in a Vec
.
This grid assumes that [0,0]
refers to the bottom-left most tile, and
[width -1, height -1]
refers to the top-right-most tile.
Implementations
sourceimpl<T: Clone> Grid<T>
impl<T: Clone> Grid<T>
sourcepub fn new(value: T, size: impl Size2d) -> Self
pub fn new(value: T, size: impl Size2d) -> Self
Creates a new Grid
sourcepub fn default(size: impl Size2d) -> Self where
T: Default,
pub fn default(size: impl Size2d) -> Self where
T: Default,
Creates a new Grid
sourcepub fn row_iter(&self, y: usize) -> Iter<'_, T>
pub fn row_iter(&self, y: usize) -> Iter<'_, T>
An iterator over a single row of the grid.
Goes from left to right.
sourcepub fn row_iter_mut(&mut self, y: usize) -> impl Iterator<Item = &mut T>
pub fn row_iter_mut(&mut self, y: usize) -> impl Iterator<Item = &mut T>
A mutable iterator over a single row of the grid.
Goes from left to right.
sourcepub fn insert_row(&mut self, y: usize, row: impl Iterator<Item = T>)
pub fn insert_row(&mut self, y: usize, row: impl 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 GridPoint,
row: impl Iterator<Item = T>
)
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.
sourcepub fn insert_column(&mut self, x: usize, column: impl IntoIterator<Item = T>)
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.
sourcepub fn insert_column_at(
&mut self,
xy: impl GridPoint,
column: impl IntoIterator<Item = T>
)
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.
sourcepub fn column_iter(&self, x: usize) -> StepBy<Iter<'_, T>>
pub fn column_iter(&self, x: usize) -> StepBy<Iter<'_, T>>
An iterator over a single column of the grid.
Goes from bottom to top.
sourcepub fn column_iter_mut(&mut self, x: usize) -> StepBy<IterMut<'_, T>>
pub fn column_iter_mut(&mut self, x: usize) -> StepBy<IterMut<'_, T>>
A mutable iterator over a single column of the grid.
Goes from bottom to top.
pub fn width(&self) -> usize
pub fn height(&self) -> usize
pub fn size(&self) -> UVec2
sourcepub fn pos_to_index(&self, pos: impl GridPoint) -> usize
pub fn pos_to_index(&self, pos: impl GridPoint) -> usize
Converts a 2d grid position to it’s corresponding 1D index.
sourcepub fn index_to_pos(&self, index: usize) -> IVec2
pub fn index_to_pos(&self, index: usize) -> IVec2
Converts a 1d index to it’s corresponding grid position.
sourcepub fn pivot_position(&self, pivot: Pivot) -> IVec2
pub fn pivot_position(&self, pivot: Pivot) -> IVec2
Get the position of the given pivot point on the grid.
pub fn in_bounds(&self, pos: IVec2) -> bool
sourcepub fn side_index(&self, side: Side) -> usize
pub fn side_index(&self, side: Side) -> usize
Gets the index for a given side.
sourcepub fn rect_iter<RANGE: RangeBounds<[i32; 2]>>(
&self,
range: RANGE
) -> impl Iterator<Item = (IVec2, &T)>
pub fn rect_iter<RANGE: RangeBounds<[i32; 2]>>(
&self,
range: RANGE
) -> 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.
sourcepub fn iter_2d(&self) -> impl Iterator<Item = (IVec2, &T)>
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.
sourcepub fn iter_2d_mut(&mut self) -> impl Iterator<Item = (IVec2, &mut T)>
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.
sourcepub fn to_world_pivot(&self, pivot: Pivot) -> WorldGrid
pub fn to_world_pivot(&self, pivot: Pivot) -> WorldGrid
Creates a crate::world_grid::WorldGrid from this grid with the given pivot. This can be used to translate between grid points and world space.
sourcepub fn to_world(&self) -> WorldGrid
pub fn to_world(&self) -> WorldGrid
Creates a crate::world_grid::WorldGrid from this grid with the default bottom left pivot. This can be used to translate between grid points and world space.
pub fn slice<R: RangeBounds<usize>>(&self, slice: R) -> &[T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn slice_mut<R: RangeBounds<usize>>(&mut self, slice: R) -> &mut [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
sourcepub fn rows_iter(
&self,
range: impl RangeBounds<usize>
) -> impl Iterator<Item = &[T]>
pub fn rows_iter(
&self,
range: impl RangeBounds<usize>
) -> impl Iterator<Item = &[T]>
Iterate over a range of rows.
Yields &[T] (Slice of T)
sourcepub fn rows_iter_mut(
&mut self,
range: impl RangeBounds<usize>
) -> impl Iterator<Item = &mut [T]>
pub fn rows_iter_mut(
&mut self,
range: impl RangeBounds<usize>
) -> impl Iterator<Item = &mut [T]>
Iterate mutably over a range of rows.
Yields &mut [T
] (Slice of mutable T
)
sourcepub fn axis_index(&self, axis: usize) -> usize
pub fn axis_index(&self, axis: usize) -> usize
Final index along a given axis, where 0 == width, and 1 == height.
pub fn axis_size(&self, axis: usize) -> usize
Trait Implementations
Auto Trait Implementations
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
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