[−][src]Enum gridly::prelude::Direction
The four cardinal directions (up, down, left, right). Direction
implements a number of simple helper methods. It also implements
VectorLike
, which allows it to be used in contexts where a Vector
can be used as a unit vector in the given direction (for example, with
Vector arithmetic).
Variants
The negative row direction
The positive row direction
The negative column direction
The positive column direction
Methods
impl Direction
[src]
#[must_use]
pub fn from_name(name: &str) -> Option<Self>
[src]
Parse a direction name into a direction. Currently supported names are (case insensitive):
Up
: Up, North, U, NDown
: Down, South, D, SLeft
: Left, West, L, WRight
: Right, East, R, E
Example
use gridly::prelude::*; assert_eq!(Direction::from_name("up"), Some(Up)); assert_eq!(Direction::from_name("West"), Some(Left)); assert_eq!(Direction::from_name("Foo"), None);
#[must_use]
pub fn sized_vec(self, length: isize) -> Vector
[src]
Return a vector with the given length in this direction
Example:
use gridly::prelude::*; assert_eq!(Up.sized_vec(2), Vector::new(-2, 0)); assert_eq!(Down.sized_vec(3), Vector::new(3, 0)); assert_eq!(Left.sized_vec(1), Vector::new(0, -1)); assert_eq!(Right.sized_vec(5), Vector::new(0, 5));
#[must_use]
pub fn unit_vec(self) -> Vector
[src]
Return the unit vector in the given direction.
Example:
use gridly::prelude::*; assert_eq!(Up.unit_vec(), Vector::new(-1, 0)); assert_eq!(Down.unit_vec(), Vector::new(1, 0)); assert_eq!(Left.unit_vec(), Vector::new(0, -1)); assert_eq!(Right.unit_vec(), Vector::new(0, 1));
#[must_use]
pub fn is_vertical(self) -> bool
[src]
True if this is Up
or Down
Example:
use gridly::direction::*; assert!(Up.is_vertical()); assert!(Down.is_vertical()); assert!(!Left.is_vertical()); assert!(!Right.is_vertical());
#[must_use]
pub fn is_horizontal(self) -> bool
[src]
True if this is Left
or Right
Example:
use gridly::direction::*; assert!(!Up.is_horizontal()); assert!(!Down.is_horizontal()); assert!(Left.is_horizontal()); assert!(Right.is_horizontal());
#[must_use]
pub fn reverse(self) -> Direction
[src]
Reverse this direction (Up
→ Down
, etc)
use gridly::direction::*; assert_eq!(Up.reverse(), Down); assert_eq!(Down.reverse(), Up); assert_eq!(Left.reverse(), Right); assert_eq!(Right.reverse(), Left);
#[must_use]
pub fn clockwise(self) -> Direction
[src]
Rotate this direction clockwise
Example:
use gridly::direction::*; assert_eq!(Up.clockwise(), Right); assert_eq!(Down.clockwise(), Left); assert_eq!(Left.clockwise(), Up); assert_eq!(Right.clockwise(), Down);
#[must_use]
pub fn anticlockwise(self) -> Direction
[src]
Rotate this direction counterclockwise
Example:
use gridly::direction::*; assert_eq!(Up.anticlockwise(), Left); assert_eq!(Down.anticlockwise(), Right); assert_eq!(Left.anticlockwise(), Down); assert_eq!(Right.anticlockwise(), Up);
Trait Implementations
impl<T: VectorLike> Add<T> for Direction
[src]
Adding a Vector
to a Direction
is equivelent to adding it to a
unit vector in the given direction. Note that, because Direction
itself implements VectorLike
, this means you can add together a sequence
of directions to get a Vector.
Example:
use gridly::vector::Vector; use gridly::direction::*; let base = Vector::new(3, 4); assert_eq!(Up + base, Vector::new(2, 4)); assert_eq!(Down + base, Vector::new(4, 4)); assert_eq!(Right + base, Vector::new(3, 5)); assert_eq!(Left + base, Vector::new(3, 3)); assert_eq!(Up + Right + Up + Up, Vector::new(-3, 1));
type Output = Vector
The resulting type after applying the +
operator.
#[must_use]
fn add(self, rhs: T) -> Vector
[src]
impl Clone for Direction
[src]
impl Copy for Direction
[src]
impl Debug for Direction
[src]
impl Eq for Direction
[src]
impl Hash for Direction
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Mul<isize> for Direction
[src]
Multiplying a Direction
by an isize
produces a Vector of the given
length in the given direction
Example:
use gridly::direction::*; use gridly::vector::Vector; assert_eq!(Up * 5, Vector::new(-5, 0)); assert_eq!(Down * 3, Vector::new(3, 0)); assert_eq!(Left * 2, Vector::new(0, -2)); assert_eq!(Right * 4, Vector::new(0, 4));
type Output = Vector
The resulting type after applying the *
operator.
#[must_use]
fn mul(self, amount: isize) -> Vector
[src]
impl Neg for Direction
[src]
Negating a Direction
reverses it
Example:
use gridly::direction::*; assert_eq!(-Up, Down); assert_eq!(-Down, Up); assert_eq!(-Left, Right); assert_eq!(-Right, Left);
type Output = Direction
The resulting type after applying the -
operator.
#[must_use]
fn neg(self) -> Direction
[src]
impl PartialEq<Direction> for Direction
[src]
impl StructuralEq for Direction
[src]
impl StructuralPartialEq for Direction
[src]
impl<T: VectorLike> Sub<T> for Direction
[src]
Subtracting a Vector
from a Direction
is equivelent to subtracing
it from a unit vector in the given direction
Example:
use gridly::vector::Vector; use gridly::direction::*; let base = Vector::new(3, 3); assert_eq!(Up - base, Vector::new(-4, -3)); assert_eq!(Down - base, Vector::new(-2, -3)); assert_eq!(Right - base, Vector::new(-3, -2)); assert_eq!(Left - base, Vector::new(-3, -4));
type Output = Vector
The resulting type after applying the -
operator.
#[must_use]
fn sub(self, rhs: T) -> Vector
[src]
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));
#[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 transpose(&self) -> Vector
[src]
#[must_use]
fn direction(&self) -> Option<Direction>
[src]
fn get_component<T: Component>(&self) -> T
[src]
Auto Trait Implementations
impl RefUnwindSafe for Direction
impl Send for Direction
impl Sync for Direction
impl Unpin for Direction
impl UnwindSafe for Direction
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,