Trait gridly::location::LocationLike
source · pub trait LocationLike: Sized {
Show 17 methods
// Required methods
fn row(&self) -> Row;
fn column(&self) -> Column;
// Provided methods
fn as_location(&self) -> Location { ... }
fn get_component<T: Component>(&self) -> T { ... }
fn above(&self, distance: impl Into<Rows>) -> Location { ... }
fn below(&self, distance: impl Into<Rows>) -> Location { ... }
fn left(&self, distance: impl Into<Columns>) -> Location { ... }
fn right(&self, distance: impl Into<Columns>) -> Location { ... }
fn add(&self, distance: impl VectorLike) -> Location { ... }
fn relative(&self, direction: Direction, distance: isize) -> Location { ... }
fn step(&self, direction: Direction) -> Location { ... }
fn transpose(&self) -> Location { ... }
fn order_by<Major: Component>(self) -> Ordered<Self, Major> { ... }
fn row_ordered(self) -> RowOrdered<Self> { ... }
fn column_ordered(self) -> ColumnOrdered<Self> { ... }
fn span_over<C: VecComponent>(
self,
distance: C
) -> LocationRange<<C::Point as Component>::Converse> ⓘ { ... }
fn range_to<C: Component>(self, end: C) -> LocationRange<C::Converse> ⓘ { ... }
}
Expand description
Required Methods§
Provided Methods§
sourcefn as_location(&self) -> Location
fn as_location(&self) -> Location
Convert this object into a Location
struct.
sourcefn get_component<T: Component>(&self) -> T
fn get_component<T: Component>(&self) -> T
Get either the row or column of a location. This method is useful in code that is generic over the Row or Column.
sourcefn above(&self, distance: impl Into<Rows>) -> Location
fn above(&self, distance: impl Into<Rows>) -> Location
Return the location that is distance
rows above this one
use gridly::prelude::*;
use gridly::shorthand::*;
assert_eq!(L(3, 4).above(2), L(1, 4));
sourcefn below(&self, distance: impl Into<Rows>) -> Location
fn below(&self, distance: impl Into<Rows>) -> Location
Return the location that is distance
rows below this one
use gridly::prelude::*;
use gridly::shorthand::*;
assert_eq!(L(3, 4).below(2), L(5, 4));
sourcefn left(&self, distance: impl Into<Columns>) -> Location
fn left(&self, distance: impl Into<Columns>) -> Location
Return the location that is distance
columns to the left of this one
use gridly::prelude::*;
use gridly::shorthand::*;
assert_eq!(L(3, 4).left(2), L(3, 2));
sourcefn right(&self, distance: impl Into<Columns>) -> Location
fn right(&self, distance: impl Into<Columns>) -> Location
Return the location that is distance
columns to the right of this one
use gridly::prelude::*;
use gridly::shorthand::*;
assert_eq!(L(3, 4).right(2), L(3, 6));
sourcefn add(&self, distance: impl VectorLike) -> Location
fn add(&self, distance: impl VectorLike) -> Location
Return the location that is distance
away from this one.
sourcefn relative(&self, direction: Direction, distance: isize) -> Location
fn relative(&self, direction: Direction, distance: isize) -> Location
Return the location that is distance
away in the given direction
use gridly::prelude::*;
use gridly::shorthand::*;
assert_eq!(Location::zero().relative(Up, 4), L(-4, 0));
assert_eq!(Location::zero().relative(Down, 5), L(5, 0));
assert_eq!(Location::zero().relative(Left, 3), L(0, -3));
assert_eq!(Location::zero().relative(Right, 1), L(0, 1));
sourcefn step(&self, direction: Direction) -> Location
fn step(&self, direction: Direction) -> Location
Return the location that is 1 away in the given direction
use gridly::prelude::*;
use gridly::shorthand::*;
let base = Location::new(2, 4);
assert_eq!(base.step(Up), L(1, 4));
assert_eq!(base.step(Down), L(3, 4));
assert_eq!(base.step(Left), L(2, 3));
assert_eq!(base.step(Right), L(2, 5));
sourcefn transpose(&self) -> Location
fn transpose(&self) -> Location
Swap the row and colimn of this Location
Example:
use gridly::prelude::*;
use gridly::shorthand::*;
assert_eq!(L(5, 8).transpose(), L(8, 5));
sourcefn order_by<Major: Component>(self) -> Ordered<Self, Major>
fn order_by<Major: Component>(self) -> Ordered<Self, Major>
Generically get strictly ordered version of this Location
. The Major
is the ordering; for example, order_by::<Row>
will create a row-ordered
Location
. See row_ordered
or
column_ordered
for an example.
sourcefn row_ordered(self) -> RowOrdered<Self>
fn row_ordered(self) -> RowOrdered<Self>
Get a strictly row-ordered version of this Location
; that is, a
location which is ordered by comparing the row
, then the column
.
Example:
use gridly::prelude::*;
use gridly::shorthand::*;
let l0 = L(0, 0).row_ordered();
let l1 = L(0, 1).row_ordered();
let l2 = L(1, 0).row_ordered();
let l3 = L(1, 1).row_ordered();
assert!(l0 < l1 && l0 < l2 && l0 < l3);
assert!(l1 < l2 && l1 < l3);
assert!(l2 < l3);
sourcefn column_ordered(self) -> ColumnOrdered<Self>
fn column_ordered(self) -> ColumnOrdered<Self>
Get a strictly row-ordered version of this Location
; that is, a
location which is ordered by comparing the row
, then the column
.
Example:
use gridly::prelude::*;
use gridly::shorthand::*;
let l0 = L(0, 0).column_ordered();
let l1 = L(1, 0).column_ordered();
let l2 = L(0, 1).column_ordered();
let l3 = L(1, 1).column_ordered();
assert!(l0 < l1 && l0 < l2 && l0 < l3);
assert!(l1 < l2 && l1 < l3);
assert!(l2 < l3);
sourcefn span_over<C: VecComponent>(
self,
distance: C
) -> LocationRange<<C::Point as Component>::Converse> ⓘ
fn span_over<C: VecComponent>( self, distance: C ) -> LocationRange<<C::Point as Component>::Converse> ⓘ
Create a range, starting at this location, with the given length
use gridly::prelude::*;
use gridly::shorthand::*;
let location = L(1, 2);
let range = location.span_over(Rows(3));
assert_eq!(range, LocationRange::bounded(Column(2), Row(1), Row(4)));
sourcefn range_to<C: Component>(self, end: C) -> LocationRange<C::Converse> ⓘ
fn range_to<C: Component>(self, end: C) -> LocationRange<C::Converse> ⓘ
Create a range, starting at this component, ending at the given component
use gridly::prelude::*;
use gridly::shorthand::*;
let location = L(1, 2);
let range = location.range_to(Column(6));
assert_eq!(range, LocationRange::bounded(Row(1), Column(2), Column(6)));