[−][src]Trait gridly::prelude::VectorComponent
A Rows
or Columns
component of a Vector
This trait comprises a component of a Vector
, which may be either
Rows
or Columns
. It represents a distance in a single direction,
either vertical (Rows
) or horizontal (Columns
).
In practice, most code will call methods directly on Rows
or Columns
values. However, a lot of gridly functionality is agnostic towards
rows and columns (for instance, a view over a row in a grid is functionally
the same as a view over a column), so the Component
trait allows such
functionality to be written generically.
The key methods for Component
that allow it to work in generic contexts
are from_vector
, which gets a component from a Vector
, and combine
,
which combines a Rows
or Columns
with its converse (a Columns
or a Row
s) to create a new Vector
.
Associated Types
type Converse: Component<Converse = Self>
type Point: LocComponent<Distance = Self>
Required methods
fn from_vector(vector: impl VectorLike) -> Self
Get this compnent from a Vector
Example:
use gridly::vector::*; let vec = Vector::new(4, 5); assert_eq!(Rows::from_vector(&vec), Rows(4)); assert_eq!(Columns::from_vector(&vec), Columns(5));
fn combine(self, converse: Self::Converse) -> Vector
Create a vector from a Row and Column
Example:
use gridly::vector::*; let columns = Columns(10); let rows = Rows(2); assert_eq!(columns.combine(rows), Vector::new(2, 10));
fn value(self) -> isize
Get the integer value of this component.
Example:
use gridly::vector::*; let columns = Columns(10); let rows = Rows(2); assert_eq!(columns.value(), 10); assert_eq!(rows.value(), 2);
fn transpose(self) -> Self::Converse
use gridly::vector::*; assert_eq!(Rows(10).transpose(), Columns(10));