Trait gridly::grid::GridBounds

source ·
pub trait GridBounds {
Show 20 methods // Required methods fn dimensions(&self) -> Vector; fn root(&self) -> Location; // Provided methods fn outer_bound(&self) -> Location { ... } fn num_rows(&self) -> Rows { ... } fn num_columns(&self) -> Columns { ... } fn dimension<C: VecComponent>(&self) -> C { ... } fn root_row(&self) -> Row { ... } fn root_column(&self) -> Column { ... } fn root_component<C: LocComponent>(&self) -> C { ... } fn row_range(&self) -> RowRange { ... } fn column_range(&self) -> ColumnRange { ... } fn range<C: LocComponent>(&self) -> ComponentRange<C> { ... } fn check_component<C: LocComponent>(&self, c: C) -> Result<C, RangeError<C>> { ... } fn check_row(&self, row: impl Into<Row>) -> Result<Row, RowRangeError> { ... } fn check_column( &self, column: impl Into<Column> ) -> Result<Column, ColumnRangeError> { ... } fn component_in_bounds<C: LocComponent>(&self, c: C) -> bool { ... } fn row_in_bounds(&self, row: impl Into<Row>) -> bool { ... } fn column_in_bounds(&self, column: impl Into<Column>) -> bool { ... } fn check_location( &self, location: impl LocationLike ) -> Result<Location, BoundsError> { ... } fn location_in_bounds(&self, location: impl LocationLike) -> bool { ... }
}
Expand description

Grid trait implementing grid sizes and boundary checking.

This trait doesn’t provide any direct grid storage functionality, but instead provides the bounds checking which is generic to all of the different kinds of grid.

All gridly grids have dimensions– the size of the grid in rows and columns– and a root location, which is the location index of the top-left cell of the grid ((0, 0) by default).

Required Methods§

source

fn dimensions(&self) -> Vector

Get the dimensions of the grid, as a Vector. The dimensions of must be >= 0.

source

fn root(&self) -> Location

Return the root location (ie, the top left) of the grid. All valid locations on the grid have location >= root. For most grids, this can just be Location::zero

Provided Methods§

source

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

source

fn num_rows(&self) -> Rows

Get the height of the grid in Rows.

source

fn num_columns(&self) -> Columns

Get the width of the grid, in Columns.

source

fn dimension<C: VecComponent>(&self) -> C

Get the height or width of this grid.

source

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

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: LocComponent>(&self) -> C

Return the index of the leftmost column or topmost row of this grid.

source

fn row_range(&self) -> RowRange

Get a range iterator over all the Row indexes in this grid

source

fn column_range(&self) -> ColumnRange

Get a range iterator over all the Column indexes in this grid

source

fn range<C: LocComponent>(&self) -> ComponentRange<C>

Get a range iterator over the row or column indexes

source

fn check_component<C: LocComponent>(&self, c: C) -> Result<C, RangeError<C>>

Check that a Row or 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_component(Row(10)).and_then(|row| ...).

source

fn check_row(&self, row: impl Into<Row>) -> Result<Row, RowRangeError>

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

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: LocComponent>(&self, c: C) -> bool

Returns true if a Row or Column is inside the bounds described by this grid.

source

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

Returns true if a Column is inside the bounds described by this grid.

source

fn check_location( &self, location: impl LocationLike ) -> Result<Location, BoundsError>

Check that a location is inside the bounds of this grid.

Returns the Location if successful, or an error describing the boundary error if not. This function is intended to help write more expressive code; ie, grid.check_location(loc).and_then(|loc| ...).

source

fn location_in_bounds(&self, location: impl LocationLike) -> bool

Returns true if a locaton is inside the bounds of this grid.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<G: GridBounds> GridBounds for &G

source§

impl<G: GridBounds> GridBounds for &mut G

Implementors§