[][src]Struct gridly::vector::Vector

pub struct Vector {
    pub rows: Rows,
    pub columns: Columns,
}

A measurement of distance between two Locations

A Vector is the measurement of distance between two Locations. It supports arithmetic operations with itself, as well as anything which can be converted into a Vector. Currently, Rows, Columns, and Direction all have this property, as well as (Rows, Columns), (Columns, Rows), and (isize, isize) (which is treated as (Rows, Columns)).

Fields

rows: Rowscolumns: Columns

Implementations

impl Vector[src]

#[must_use]pub fn new(rows: impl Into<Rows>, columns: impl Into<Columns>) -> Self[src]

Create a new Vector with the given rows and columns.

Example

use gridly::vector::*;

assert_eq!(
    Vector::new(3, 4),
    Vector {
        rows: Rows(3),
        columns: Columns(4),
    },
);

#[must_use]pub const fn zero() -> Vector[src]

Create a zero Vector

Example

use gridly::vector::*;

assert_eq!(Vector::zero(), Vector::new(0, 0));

#[must_use]pub const fn upward(size: isize) -> Vector[src]

Create an upward pointing vector of the given size

use gridly::prelude::*;

assert_eq!(Vector::upward(5), Vector::new(-5, 0))

#[must_use]pub const fn downward(size: isize) -> Vector[src]

Create a downward pointing vector of the given size

use gridly::prelude::*;

assert_eq!(Vector::downward(5), Vector::new(5, 0))

#[must_use]pub const fn leftward(size: isize) -> Vector[src]

Create a leftward pointing vector of the given size

use gridly::prelude::*;

assert_eq!(Vector::leftward(5), Vector::new(0, -5))

#[must_use]pub const fn rightward(size: isize) -> Vector[src]

Create a rightward pointing vector of the given size

use gridly::prelude::*;

assert_eq!(Vector::rightward(5), Vector::new(0, 5))

#[must_use]pub fn in_direction(direction: Direction, length: isize) -> Vector[src]

Create a vector of the given size in the given direction

use gridly::prelude::*;

assert_eq!(Vector::in_direction(Up, 10), Vector::new(-10, 0));

Trait Implementations

impl<T: VectorLike> Add<T> for Vector[src]

type Output = Vector

The resulting type after applying the + operator.

impl<T: VectorLike> AddAssign<T> for Vector[src]

impl Clone for Vector[src]

impl Copy for Vector[src]

impl Debug for Vector[src]

impl Default for Vector[src]

impl Eq for Vector[src]

impl Hash for Vector[src]

impl<T: Copy> Mul<T> for Vector where
    isize: Mul<T, Output = isize>, 
[src]

Multiply a vector's components by a constant factor

type Output = Vector

The resulting type after applying the * operator.

impl<T: Copy> MulAssign<T> for Vector where
    isize: MulAssign<T>, 
[src]

Multiply a vector's components by a constant factor in-place

impl Neg for Vector[src]

type Output = Vector

The resulting type after applying the - operator.

impl<T: VectorLike> PartialEq<T> for Vector[src]

impl<T: VectorLike> PartialOrd<T> for Vector[src]

impl StructuralEq for Vector[src]

impl<T: VectorLike> Sub<T> for Vector[src]

type Output = Vector

The resulting type after applying the - operator.

impl<T: VectorLike> SubAssign<T> for Vector[src]

impl<T: VectorLike> Sum<T> for Vector[src]

impl VectorLike for Vector[src]

Auto Trait Implementations

impl RefUnwindSafe for Vector

impl Send for Vector

impl Sync for Vector

impl Unpin for Vector

impl UnwindSafe for Vector

Blanket Implementations

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

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.