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§
sourcefn dimensions(&self) -> Vector
fn dimensions(&self) -> Vector
Get the dimensions of the grid, as a Vector
. The dimensions of
must be >= 0.
Provided Methods§
sourcefn 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.column
sourcefn num_columns(&self) -> Columns
fn num_columns(&self) -> Columns
Get the width of the grid, in Columns
.
sourcefn dimension<C: VecComponent>(&self) -> C
fn dimension<C: VecComponent>(&self) -> C
Get the height or width of this grid.
sourcefn 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.
sourcefn 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.
sourcefn root_component<C: LocComponent>(&self) -> C
fn root_component<C: LocComponent>(&self) -> C
Return the index of the leftmost column or topmost row of this grid.
sourcefn column_range(&self) -> ColumnRange
fn column_range(&self) -> ColumnRange
Get a range iterator over all the Column
indexes in this grid
sourcefn range<C: LocComponent>(&self) -> ComponentRange<C> ⓘ
fn range<C: LocComponent>(&self) -> ComponentRange<C> ⓘ
Get a range iterator over the row or column indexes
sourcefn check_component<C: LocComponent>(&self, c: C) -> Result<C, RangeError<C>>
fn check_component<C: LocComponent>(&self, c: C) -> Result<C, RangeError<C>>
sourcefn check_row(&self, row: impl Into<Row>) -> Result<Row, RowRangeError>
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| ...)
.
sourcefn check_column(
&self,
column: impl Into<Column>
) -> Result<Column, ColumnRangeError>
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| ...)
.
sourcefn component_in_bounds<C: LocComponent>(&self, c: C) -> bool
fn component_in_bounds<C: LocComponent>(&self, c: C) -> bool
sourcefn 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.
sourcefn 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.
sourcefn 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.
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| ...)
.
sourcefn 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.