pub struct Translate<G> { /* private fields */ }Expand description
Grid adapter that translates the locations of the wrapped grid. The
translation is added to the inner grid location; that is, if the inner
grid has a root at (0, 0), and the translation is (2, 3), the new
root will be (2, 3).
§Example
use gridly_grids::VecGrid;
use gridly_adapters::Translate;
use gridly::prelude::*;
let grid: VecGrid<i32> = VecGrid::new_row_major(
Rows(2) + Columns(2),
[1, 2, 3, 4].iter().copied()
).unwrap();
let grid = Translate::new(grid, Rows(2) + Columns(3));
assert_eq!(grid.get((2, 3)).ok(), Some(&1));
assert_eq!(grid.get((2, 4)).ok(), Some(&2));
assert_eq!(grid.get((3, 3)).ok(), Some(&3));
assert_eq!(grid.get((3, 4)).ok(), Some(&4));
assert_eq!(grid.get((0, 0)).ok(), None);Implementations§
Source§impl<G: GridBounds> Translate<G>
impl<G: GridBounds> Translate<G>
pub fn new(grid: G, translation: impl VectorLike) -> Self
Source§impl<G> Translate<G>
impl<G> Translate<G>
pub fn into_inner(self) -> G
pub fn translation(&self) -> Vector
Trait Implementations§
Source§impl<G: Grid> Grid for Translate<G>
impl<G: Grid> Grid for Translate<G>
Source§unsafe fn get_unchecked(&self, location: Location) -> &Self::Item
unsafe fn get_unchecked(&self, location: Location) -> &Self::Item
Get a reference to a cell, without doing bounds checking. Implementors
of this method are allowed to assume that bounds checking has already
been performed on the location, which means that implementors are allowed
to do their own unsafe
get operations on the underlying storage,
where relevant / possible. Read moreSource§fn get(&self, location: impl LocationLike) -> Result<&Self::Item, BoundsError>
fn get(&self, location: impl LocationLike) -> Result<&Self::Item, BoundsError>
Get a reference to a cell in a grid. Returns an error if the location
is out of bounds with the specific boundary violation.
Source§fn view<T>(&self) -> View<'_, Self, T>where
T: Component,
fn view<T>(&self) -> View<'_, Self, T>where
T: Component,
Get a view of a grid, over its rows or columns. A view of a grid is
similar to a slice, but instead of being a view over specific elements,
it’s a view over the rows and columns. See
[View] for details.Source§fn columns(&self) -> View<'_, Self, Column>
fn columns(&self) -> View<'_, Self, Column>
Get a view of a grid’s columns. See
[View] for details.Source§unsafe fn single_view_unchecked<T>(&self, index: T) -> SingleView<'_, Self, T>where
T: Component,
unsafe fn single_view_unchecked<T>(&self, index: T) -> SingleView<'_, Self, T>where
T: Component,
Get a view of a single row or column in a grid, without bounds
checking that row or column index. Read more
Source§unsafe fn row_unchecked(&self, row: Row) -> SingleView<'_, Self, Row>
unsafe fn row_unchecked(&self, row: Row) -> SingleView<'_, Self, Row>
Get a view of a single row in a grid, without bounds checking that row’s index. Read more
Source§unsafe fn column_unchecked(
&self,
column: Column,
) -> SingleView<'_, Self, Column>
unsafe fn column_unchecked( &self, column: Column, ) -> SingleView<'_, Self, Column>
Get a view of a single column in a grid, without bounds checking that column’s index. Read more
Source§fn single_view<T>(
&self,
index: T,
) -> Result<SingleView<'_, Self, T>, RangeError<T>>where
T: Component,
fn single_view<T>(
&self,
index: T,
) -> Result<SingleView<'_, Self, T>, RangeError<T>>where
T: Component,
Get a view of a single row or column in a grid. Returns an error if the index of the
row or column is out of bounds for the grid.
Source§fn row(
&self,
row: impl Into<Row>,
) -> Result<SingleView<'_, Self, Row>, RangeError<Row>>
fn row( &self, row: impl Into<Row>, ) -> Result<SingleView<'_, Self, Row>, RangeError<Row>>
Get a view of a single row in a grid. Returns an error if the index of the row is
out of bounds for the grid.
Source§fn column(
&self,
column: impl Into<Column>,
) -> Result<SingleView<'_, Self, Column>, RangeError<Column>>
fn column( &self, column: impl Into<Column>, ) -> Result<SingleView<'_, Self, Column>, RangeError<Column>>
Get a view of a single column in a grid. Returns an error if the index of the column
is out of bounds for the grid.
Source§fn display_with<T, F>(&self, func: F) -> DisplayAdapter<&Self, F>
fn display_with<T, F>(&self, func: F) -> DisplayAdapter<&Self, F>
Source§impl<G: GridBounds> GridBounds for Translate<G>
impl<G: GridBounds> GridBounds for Translate<G>
Source§fn dimensions(&self) -> Vector
fn dimensions(&self) -> Vector
Get the dimensions of the grid, as a
Vector. The dimensions of
must be >= 0.Source§fn outer_bound(&self) -> Location
fn outer_bound(&self) -> Location
Get the outer bound of the grid; that is, the location for which all
valid locations in the grid have
row < outer.row && column < outer.columnSource§fn num_columns(&self) -> Columns
fn num_columns(&self) -> Columns
Get the width of the grid, in
Columns.Source§fn root_row(&self) -> Row
fn root_row(&self) -> Row
Return the index of the topmost row of this grid. For most grids,
this is 0, but some grids may include negatively indexed locations,
or even offsets.
Source§fn root_column(&self) -> Column
fn root_column(&self) -> Column
Return the index of the leftmost column of this grid. For most grids,
this is 0, but some grids may include negatively indexed locations,
or even offsets.
Source§fn root_component<C>(&self) -> Cwhere
C: Component,
fn root_component<C>(&self) -> Cwhere
C: Component,
Return the index of the leftmost column or topmost row of this grid.
Source§fn row_range(&self) -> ComponentRange<Row>
fn row_range(&self) -> ComponentRange<Row>
Get a range iterator over all the
Row indexes in this gridSource§fn column_range(&self) -> ComponentRange<Column>
fn column_range(&self) -> ComponentRange<Column>
Get a range iterator over all the
Column indexes in this gridSource§fn range<C>(&self) -> ComponentRange<C>where
C: Component,
fn range<C>(&self) -> ComponentRange<C>where
C: Component,
Get a range iterator over the row or column indexes
Source§fn check_component<C>(&self, c: C) -> Result<C, RangeError<C>>where
C: Component,
fn check_component<C>(&self, c: C) -> Result<C, RangeError<C>>where
C: Component,
Source§fn check_row(&self, row: impl Into<Row>) -> Result<Row, RangeError<Row>>
fn check_row(&self, row: impl Into<Row>) -> Result<Row, RangeError<Row>>
Check that a
Row is inside the bounds described by this grid.
Returns the component if it’s inside the bounds, or an error
describing the violated boundary if not. This function is intended
to help write more expressive code; ie,
grid.check_row(10).and_then(|row| ...).Source§fn check_column(
&self,
column: impl Into<Column>,
) -> Result<Column, RangeError<Column>>
fn check_column( &self, column: impl Into<Column>, ) -> Result<Column, RangeError<Column>>
Check that a
Column is inside the bounds described by this grid.
Returns the component if it’s inside the bounds, or an error
describing the violated boundary if not. This function is intended
to help write more expressive code; ie,
grid.check_column(10).and_then(|row| ...).Source§fn component_in_bounds<C>(&self, c: C) -> boolwhere
C: Component,
fn component_in_bounds<C>(&self, c: C) -> boolwhere
C: Component,
Source§fn row_in_bounds(&self, row: impl Into<Row>) -> bool
fn row_in_bounds(&self, row: impl Into<Row>) -> bool
Returns true if a
Row is inside the bounds described
by this grid.Source§fn column_in_bounds(&self, column: impl Into<Column>) -> bool
fn column_in_bounds(&self, column: impl Into<Column>) -> bool
Returns true if a
Column is inside the bounds described
by this grid.Source§fn check_location(
&self,
location: impl LocationLike,
) -> Result<Location, BoundsError>
fn check_location( &self, location: impl LocationLike, ) -> Result<Location, BoundsError>
Check that a location is inside the bounds of this grid. Read more
Source§fn location_in_bounds(&self, location: impl LocationLike) -> bool
fn location_in_bounds(&self, location: impl LocationLike) -> bool
Returns true if a locaton is inside the bounds of this grid.
Source§impl<G: GridMut> GridMut for Translate<G>
impl<G: GridMut> GridMut for Translate<G>
Source§unsafe fn get_unchecked_mut(&mut self, location: Location) -> &mut Self::Item
unsafe fn get_unchecked_mut(&mut self, location: Location) -> &mut Self::Item
Get a mutable reference to a cell, without doing bounds checking.
Implementors of this method are allowed to assume that bounds checking
has already been performed on the location, which means that
implementors are allowed to do their own unsafe
get_mut operations
on the underlying storage, where relevant / possible. Read moreSource§fn get_mut(
&mut self,
location: impl LocationLike,
) -> Result<&mut Self::Item, BoundsError>
fn get_mut( &mut self, location: impl LocationLike, ) -> Result<&mut Self::Item, BoundsError>
Get a reference to a cell in a grid. Returns an error if the location
is out of bounds with the specific boundary violation.
Source§impl<G: GridSetter> GridSetter for Translate<G>
impl<G: GridSetter> GridSetter for Translate<G>
Source§unsafe fn replace_unchecked(
&mut self,
location: Location,
value: Self::Item,
) -> Self::Item
unsafe fn replace_unchecked( &mut self, location: Location, value: Self::Item, ) -> Self::Item
Replace the value at the given
location with value, without
bounds checking location. Returns the previous value in the grid. Read moreSource§unsafe fn set_unchecked(&mut self, location: Location, value: Self::Item)
unsafe fn set_unchecked(&mut self, location: Location, value: Self::Item)
Source§fn replace(
&mut self,
location: impl LocationLike,
value: Self::Item,
) -> Result<Self::Item, BoundsError>
fn replace( &mut self, location: impl LocationLike, value: Self::Item, ) -> Result<Self::Item, BoundsError>
Replace the value at the given
location with value. Returns the
previous value in the grid, or an error if the location was out of
bounds.Source§fn set(
&mut self,
location: impl LocationLike,
value: Self::Item,
) -> Result<(), BoundsError>
fn set( &mut self, location: impl LocationLike, value: Self::Item, ) -> Result<(), BoundsError>
Set the value at the given
location in the grid. Returns an error
if the location was out of bounds.Auto Trait Implementations§
impl<G> Freeze for Translate<G>where
G: Freeze,
impl<G> RefUnwindSafe for Translate<G>where
G: RefUnwindSafe,
impl<G> Send for Translate<G>where
G: Send,
impl<G> Sync for Translate<G>where
G: Sync,
impl<G> Unpin for Translate<G>where
G: Unpin,
impl<G> UnwindSafe for Translate<G>where
G: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more