[−][src]Trait gridly::prelude::VectorLike
VectorLike
is implemented for types that can be used as a vector. They
can participate in vector arithmetic, comparison, and other vector oprations.
Required methods
#[must_use]fn rows(&self) -> Rows
#[must_use]fn columns(&self) -> Columns
#[must_use]fn as_vector(&self) -> Vector
Provided methods
#[must_use]fn manhattan_length(&self) -> isize
Return the manhattan length of the vector. The manhattan length of a vector is the sum of the absolute values of its components.
Example
use gridly::vector::*; let vec = Vector::new(-8, 3); assert_eq!(vec.manhattan_length(), 11);
#[must_use]fn checked_manhattan_length(&self) -> Option<isize>
Return the manhattan length of the vector, or None
if there are
any overflows.
Example
use std::isize; use gridly::vector::*; let vec = Vector::new(isize::MIN, 0); assert_eq!(vec.checked_manhattan_length(), None); let vec = Vector::new(isize::MAX, isize::MAX); assert_eq!(vec.checked_manhattan_length(), None); let vec = Vector::new(-54, 30); assert_eq!(vec.checked_manhattan_length(), Some(84));
#[must_use]fn clockwise(&self) -> Vector
Return a new vector, rotated 90 degrees clockwise.
Example
use gridly::vector::*; let vec = Vector::new(3, 8); assert_eq!(vec.clockwise(), Vector::new(8, -3));
#[must_use]fn anticlockwise(&self) -> Vector
Return a new vector, rotated 90 degrees counterclockwise.
Example
use gridly::vector::*; let vec = Vector::new(-2, -4); assert_eq!(vec.anticlockwise(), Vector::new(4, -2));
#[must_use]fn reverse(&self) -> Vector
Return a new vector, facing the opposite direction of this one
Example
use gridly::vector::*; let vec = Vector::new(4, -5); assert_eq!(vec.reverse(), Vector::new(-4, 5));
#[must_use]fn rotate(&self, rotation: Rotation) -> Vector
Return a new vector, rotated by a given rotation
Example
use gridly::vector::*; use gridly::rotation::{Clockwise, Anticlockwise}; let vec = Vector::new(-5, 3); assert_eq!(vec.rotate(Clockwise), vec.clockwise()); assert_eq!(vec.rotate(Anticlockwise), vec.anticlockwise());
#[must_use]fn get_component<T: Component>(&self) -> T
Generically get either the Rows
or Columns
of a vector
Example
use gridly::vector::*; let vec = Vector::new(-3, 4); let rows: Rows = vec.get_component(); let columns: Columns = vec.get_component(); assert_eq!(rows, Rows(-3)); assert_eq!(columns, Columns(4));
#[must_use]fn transpose(&self) -> Vector
Swap the rows and columns of this Vector
Example
use gridly::vector::*; let vec = Vector::new(2, 8); assert_eq!(vec.transpose(), Vector::new(8, 2));
#[must_use]fn direction(&self) -> Option<Direction>
If the vector is pointing in an orthogonal direction, return that direction
Example
use gridly::vector::*; use gridly::direction::*; assert_eq!(Vector::new(3, 0).direction(), Some(Down)); assert_eq!(Vector::new(0, 2).direction(), Some(Right)); assert_eq!(Vector::new(-10, 0).direction(), Some(Up)); assert_eq!(Vector::new(0, -1).direction(), Some(Left)); assert_eq!(Vector::zero().direction(), None); assert_eq!(Vector::new(3, 4).direction(), None);
Implementations on Foreign Types
impl VectorLike for (Rows, Columns)
[src]
#[must_use]fn rows(&self) -> Rows
[src]
#[must_use]fn columns(&self) -> Columns
[src]
#[must_use]fn as_vector(&self) -> Vector
[src]
impl VectorLike for (Columns, Rows)
[src]
#[must_use]fn columns(&self) -> Columns
[src]
#[must_use]fn rows(&self) -> Rows
[src]
#[must_use]fn as_vector(&self) -> Vector
[src]
impl VectorLike for (isize, isize)
[src]
#[must_use]fn rows(&self) -> Rows
[src]
#[must_use]fn columns(&self) -> Columns
[src]
#[must_use]fn as_vector(&self) -> Vector
[src]
impl<T: VectorLike, '_> VectorLike for &'_ T
[src]
#[must_use]fn rows(&self) -> Rows
[src]
#[must_use]fn columns(&self) -> Columns
[src]
#[must_use]fn as_vector(&self) -> Vector
[src]
#[must_use]fn manhattan_length(&self) -> isize
[src]
#[must_use]fn checked_manhattan_length(&self) -> Option<isize>
[src]
#[must_use]fn clockwise(&self) -> Vector
[src]
#[must_use]fn anticlockwise(&self) -> Vector
[src]
#[must_use]fn reverse(&self) -> Vector
[src]
#[must_use]fn rotate(&self, rotation: Rotation) -> Vector
[src]
#[must_use]fn get_component<C: Component>(&self) -> C
[src]
#[must_use]fn transpose(&self) -> Vector
[src]
#[must_use]fn direction(&self) -> Option<Direction>
[src]
Implementors
impl VectorLike for Direction
[src]
A Direction
acts like a unit vector in the given direction. This allows
it to be used in things like Vector arithmetic.
Example:
use gridly::prelude::*; assert_eq!(Vector::new(1, 1) + Up, Vector::new(0, 1)); assert_eq!(Location::new(3, 4) - Left, Location::new(3, 5));