Struct gridly::prelude::Vector

source ·
pub struct Vector {
    pub rows: Rows,
    pub columns: Columns,
}
Expand description

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: Rows§columns: Columns

Implementations§

source§

impl Vector

source

pub fn new(rows: impl Into<Rows>, columns: impl Into<Columns>) -> Self

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),
    },
);
source

pub const fn zero() -> Vector

Create a zero Vector

Example
use gridly::vector::*;

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

pub const fn upward(size: isize) -> Vector

Create an upward pointing vector of the given size

use gridly::prelude::*;

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

pub const fn downward(size: isize) -> Vector

Create a downward pointing vector of the given size

use gridly::prelude::*;

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

pub const fn leftward(size: isize) -> Vector

Create a leftward pointing vector of the given size

use gridly::prelude::*;

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

pub const fn rightward(size: isize) -> Vector

Create a rightward pointing vector of the given size

use gridly::prelude::*;

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

pub fn in_direction(direction: Direction, length: isize) -> Vector

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§

source§

impl<T: VectorLike> Add<T> for Vector

§

type Output = Vector

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Vector

Performs the + operation. Read more
source§

impl<T: VectorLike> AddAssign<T> for Vector

source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
source§

impl Clone for Vector

source§

fn clone(&self) -> Vector

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Vector

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Vector

source§

fn default() -> Vector

Returns the “default value” for a type. Read more
source§

impl Hash for Vector

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

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

Multiply a vector’s components by a constant factor

§

type Output = Vector

The resulting type after applying the * operator.
source§

fn mul(self, factor: T) -> Vector

Performs the * operation. Read more
source§

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

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

source§

fn mul_assign(&mut self, factor: T)

Performs the *= operation. Read more
source§

impl Neg for Vector

§

type Output = Vector

The resulting type after applying the - operator.
source§

fn neg(self) -> Vector

Performs the unary - operation. Read more
source§

impl<T: VectorLike> PartialEq<T> for Vector

source§

fn eq(&self, rhs: &T) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: VectorLike> PartialOrd<T> for Vector

source§

fn partial_cmp(&self, rhs: &T) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: VectorLike> Sub<T> for Vector

§

type Output = Vector

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Vector

Performs the - operation. Read more
source§

impl<T: VectorLike> SubAssign<T> for Vector

source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
source§

impl<T: VectorLike> Sum<T> for Vector

source§

fn sum<I: Iterator<Item = T>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl VectorLike for Vector

source§

fn rows(&self) -> Rows

source§

fn columns(&self) -> Columns

source§

fn as_vector(&self) -> Vector

source§

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. Read more
source§

fn checked_manhattan_length(&self) -> Option<isize>

Return the manhattan length of the vector, or None if there are any overflows. Read more
source§

fn clockwise(&self) -> Vector

Return a new vector, rotated 90 degrees clockwise. Read more
source§

fn anticlockwise(&self) -> Vector

Return a new vector, rotated 90 degrees counterclockwise. Read more
source§

fn reverse(&self) -> Vector

Return a new vector, facing the opposite direction of this one Read more
source§

fn rotate(&self, rotation: Rotation) -> Vector

Return a new vector, rotated by a given rotation Read more
source§

fn get_component<T: Component>(&self) -> T

Generically get either the Rows or Columns of a vector Read more
source§

fn transpose(&self) -> Vector

Swap the rows and columns of this Vector Read more
source§

fn direction(&self) -> Option<Direction>

If the vector is pointing in an orthogonal direction, return that direction Read more
source§

impl Copy for Vector

source§

impl Eq for Vector

source§

impl StructuralEq for Vector

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.