[−][src]Trait gridly::prelude::GridBounds
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
#[must_use]
fn dimensions(&self) -> Vector
Get the dimensions of the grid, as a Vector
. The dimensions of
must be >= 0.
#[must_use]
fn root(&self) -> Location
Provided methods
#[must_use]
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
#[must_use]
fn num_rows(&self) -> Rows
Get the height of the grid in Rows
.
#[must_use]
fn num_columns(&self) -> Columns
Get the width of the grid, in Columns
.
#[must_use]
fn dimension<C: VecComponent>(&self) -> C
Get the height or width of this grid.
#[must_use]
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.
#[must_use]
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.
#[must_use]
fn root_component<C: LocComponent>(&self) -> C
Return the index of the leftmost column or topmost row of this grid.
#[must_use]
fn row_range(&self) -> RowRange
Get a range iterator over all the Row
indexes in this grid
#[must_use]
fn column_range(&self) -> ColumnRange
Get a range iterator over all the Column
indexes in this grid
ⓘImportant traits for ComponentRange<C>#[must_use]
fn range<C: LocComponent>(&self) -> ComponentRange<C>
Get a range iterator over the row or column indexes
#[must_use]
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| ...)
.
#[must_use]
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| ...)
.
#[must_use]
fn check_column(
&self,
column: impl Into<Column>
) -> Result<Column, ColumnRangeError>
&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| ...)
.
#[must_use]
fn component_in_bounds<C: LocComponent>(&self, c: C) -> bool
#[must_use]
fn row_in_bounds(&self, row: impl Into<Row>) -> bool
Returns true if a Row
is inside the bounds described
by this grid.
#[must_use]
fn column_in_bounds(&self, column: impl Into<Column>) -> bool
Returns true if a Column
is inside the bounds described
by this grid.
#[must_use]
fn check_location(
&self,
location: impl LocationLike
) -> Result<Location, BoundsError>
&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| ...)
.
#[must_use]
fn location_in_bounds(&self, location: impl LocationLike) -> bool
Returns true if a locaton is inside the bounds of this grid.