Struct 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

Source§

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 duplicate 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

Source§

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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

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

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

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

Source§

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

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

Auto Trait Implementations§

§

impl Freeze for Vector

§

impl RefUnwindSafe for Vector

§

impl Send for Vector

§

impl Sync for Vector

§

impl Unpin for Vector

§

impl UnwindSafe for Vector

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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>,

Source§

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>,

Source§

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.