[][src]Struct gridd::Offset

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

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

Fields

col_offset: i32row_offset: i32

Methods

impl Offset[src]

pub const NORTH: Offset[src]

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

pub const EAST: Offset[src]

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

pub const SOUTH: Offset[src]

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

pub const WEST: Offset[src]

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

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

Create a new Offset from the sum of cardinal vectors.

Examples

use gridd::Offset;

assert_eq!(
    Offset::cardinal_sum(1, 0, -1, 0),
    Offset::NORTH - Offset::SOUTH
);

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

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

Get the coordinate pointed to by an Offset from a given Coord.

Returns None when either Coord component would be negative.

Examples

use gridd::{Coord, Offset};

let coord: Coord = (3, 5);

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

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

Trait Implementations

impl Eq for Offset[src]

impl Default for Offset[src]

impl Clone for Offset[src]

impl PartialOrd<Offset> for Offset[src]

impl Ord for Offset[src]

impl PartialEq<Offset> for Offset[src]

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

impl Copy for Offset[src]

impl Hash for Offset[src]

impl Add<Offset> for Offset[src]

type Output = Self

The resulting type after applying the + operator.

impl Sub<Offset> for Offset[src]

type Output = Self

The resulting type after applying the - operator.

impl Mul<i32> for Offset[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<Offset> for i32[src]

type Output = Offset

The resulting type after applying the * operator.

impl Debug for Offset[src]

Auto Trait Implementations

impl Unpin for Offset

impl Sync for Offset

impl Send for Offset

impl UnwindSafe for Offset

impl RefUnwindSafe for Offset

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]