pub struct Vector {
pub rows: Rows,
pub columns: Columns,
}
Expand description
A measurement of distance between two Location
s
A Vector
is the measurement of distance between two
Location
s. 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
impl Vector
sourcepub fn new(rows: impl Into<Rows>, columns: impl Into<Columns>) -> Self
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),
},
);
sourcepub const fn upward(size: isize) -> Vector
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))
sourcepub const fn downward(size: isize) -> Vector
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))
sourcepub const fn leftward(size: isize) -> Vector
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))
sourcepub const fn rightward(size: isize) -> Vector
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))
sourcepub fn in_direction(direction: Direction, length: isize) -> Vector
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
impl<T: VectorLike> Add<T> for Vector
source§impl<T: VectorLike> AddAssign<T> for Vector
impl<T: VectorLike> AddAssign<T> for Vector
source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moresource§impl<T: Copy> MulAssign<T> for Vector
impl<T: Copy> MulAssign<T> for Vector
Multiply a vector’s components by a constant factor in-place
source§fn mul_assign(&mut self, factor: T)
fn mul_assign(&mut self, factor: T)
*=
operation. Read moresource§impl<T: VectorLike> PartialEq<T> for Vector
impl<T: VectorLike> PartialEq<T> for Vector
source§impl<T: VectorLike> PartialOrd<T> for Vector
impl<T: VectorLike> PartialOrd<T> for Vector
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<T: VectorLike> Sub<T> for Vector
impl<T: VectorLike> Sub<T> for Vector
source§impl<T: VectorLike> SubAssign<T> for Vector
impl<T: VectorLike> SubAssign<T> for Vector
source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read moresource§impl<T: VectorLike> Sum<T> for Vector
impl<T: VectorLike> Sum<T> for Vector
source§impl VectorLike for Vector
impl VectorLike for Vector
fn rows(&self) -> Rows
fn columns(&self) -> Columns
fn as_vector(&self) -> Vector
source§fn manhattan_length(&self) -> isize
fn manhattan_length(&self) -> isize
source§fn checked_manhattan_length(&self) -> Option<isize>
fn checked_manhattan_length(&self) -> Option<isize>
None
if there are
any overflows. Read more