[][src]Struct gridd::Vector

pub struct Vector {
    pub col_offset: i32,
    pub row_offset: i32,
}

A two-dimensional vector used to relate grid elements spatially.

Fields

col_offset: i32row_offset: i32

Methods

impl Vector[src]

pub const NORTH: Vector[src]

Northern unit vector: (col: +0, row: -1).

pub const EAST: Vector[src]

Eastern unit vector: (col: +1, row: +0).

pub const SOUTH: Vector[src]

Southern unit vector: (col: +0, row: +1).

pub const WEST: Vector[src]

Western unit vector: (col: -1, row: +0).

pub fn rcoord(&self, (col, row): Coord) -> Option<Coord>[src]

Get the coordinate pointed to by a Vector from a given Coord.

Returns None when either Coord component would be negative.

Examples

use gridd::{Coord, Vector};

let coord: Coord = (3, 5);

let v1 = Vector::from((-3, 2));
assert_eq!(Some((0, 7)), v1.rcoord(coord));

let v2 = Vector::from((-4, 5));
assert_eq!(None, v2.rcoord(coord));

pub fn cardinal_sum(n: i32, e: i32, s: i32, w: i32) -> Self[src]

Create a new Vector from the sum of cardinal vectors.

Examples

use gridd::Vector;

assert_eq!(
    Vector::cardinal_sum(1, 0, 1, 0),
    Vector::NORTH + Vector::SOUTH
);

assert_eq!(
    Vector::cardinal_sum(0, 2, 0, 3),
    2 * Vector::EAST + 3 * Vector::WEST
);

Trait Implementations

impl Eq for Vector[src]

impl Default for Vector[src]

impl Clone for Vector[src]

impl PartialOrd<Vector> for Vector[src]

impl Ord for Vector[src]

impl PartialEq<Vector> for Vector[src]

impl From<(i32, i32)> for Vector[src]

impl Copy for Vector[src]

impl Hash for Vector[src]

impl Add<Vector> for Vector[src]

type Output = Self

The resulting type after applying the + operator.

impl Sub<Vector> for Vector[src]

type Output = Self

The resulting type after applying the - operator.

impl Mul<i32> for Vector[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<Vector> for i32[src]

type Output = Vector

The resulting type after applying the * operator.

impl Debug for Vector[src]

Auto Trait Implementations

impl Unpin for Vector

impl Sync for Vector

impl Send for Vector

impl UnwindSafe for Vector

impl RefUnwindSafe for Vector

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]