Struct gridly::location::Location

source ·
pub struct Location {
    pub row: Row,
    pub column: Column,
}
Expand description

A location on a grid. A location is the primary indexing type for a Grid, and represents a single cell on that grid. It is comprised of a Row and a Column. Increasing row count downward and increasing columns count rightward.

Locations support arithmetic operations with Vectors. They can also be subtracted from each other to produce Vectors measuring the distance between them.

Fields§

§row: Row§column: Column

Implementations§

source§

impl Location

source

pub fn new(row: impl Into<Row>, column: impl Into<Column>) -> Self

Create a new location out of a row and a column

source

pub const fn zero() -> Self

Create a new location at (0, 0).

Trait Implementations§

source§

impl<T: VectorLike> Add<T> for Location

§

type Output = Location

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Location

Performs the + operation. Read more
source§

impl<T: VectorLike> AddAssign<T> for Location

source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
source§

impl Clone for Location

source§

fn clone(&self) -> Location

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Location

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Location

source§

fn default() -> Location

Returns the “default value” for a type. Read more
source§

impl Hash for Location

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl LocationLike for Location

source§

fn row(&self) -> Row

Get the row of this location.
source§

fn column(&self) -> Column

Get the column of this location.
source§

fn as_location(&self) -> Location

Convert this object into a Location struct.
source§

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.
source§

fn above(&self, distance: impl Into<Rows>) -> Location

Return the location that is distance rows above this one Read more
source§

fn below(&self, distance: impl Into<Rows>) -> Location

Return the location that is distance rows below this one Read more
source§

fn left(&self, distance: impl Into<Columns>) -> Location

Return the location that is distance columns to the left of this one Read more
source§

fn right(&self, distance: impl Into<Columns>) -> Location

Return the location that is distance columns to the right of this one Read more
source§

fn add(&self, distance: impl VectorLike) -> Location

Return the location that is distance away from this one.
source§

fn relative(&self, direction: Direction, distance: isize) -> Location

Return the location that is distance away in the given direction Read more
source§

fn step(&self, direction: Direction) -> Location

Return the location that is 1 away in the given direction Read more
source§

fn transpose(&self) -> Location

Swap the row and colimn of this Location Read more
source§

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.
source§

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. Read more
source§

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. Read more
source§

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 Read more
source§

fn range_to<C: Component>(self, end: C) -> LocationRange<C::Converse>

Create a range, starting at this component, ending at the given component Read more
source§

impl<T: LocationLike> PartialEq<T> for Location

source§

fn eq(&self, rhs: &T) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: LocationLike> PartialOrd<T> for Location

Locations have a partial ordering. loc1 is considered greater than loc2 iff its row or its column are greater than those in loc2. This chart shows an example:

<<<??
<<<??
<<=>>
??>>>
??>>>

Cells marked > are considered greater than the center location (marked =), and cells marked ‘<’ are less than the center location. Cells marked ? do not have an ordering with the center location.

For a strict ordering between all possible locations, see the Ordered wrapper struct, which allows for row-major or column-major orderings.

source§

fn partial_cmp(&self, rhs: &T) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<(Column, Row)> for Location

§

type Output = Vector

The resulting type after applying the - operator.
source§

fn sub(self, (column, row): (Column, Row)) -> Vector

Performs the - operation. Read more
source§

impl Sub<(Row, Column)> for Location

§

type Output = Vector

The resulting type after applying the - operator.
source§

fn sub(self, (row, column): (Row, Column)) -> Vector

Performs the - operation. Read more
source§

impl<T: VectorLike> Sub<T> for Location

§

type Output = Location

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Location

Performs the - operation. Read more
source§

impl Sub for Location

§

type Output = Vector

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Location) -> Vector

Performs the - operation. Read more
source§

impl<T: VectorLike> SubAssign<T> for Location

source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
source§

impl Copy for Location

source§

impl Eq for Location

source§

impl StructuralEq for Location

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.