Vector

Struct Vector 

Source
#[repr(C)]
pub struct Vector<T = f32> { pub dx: T, pub dy: T, }

Fieldsยง

ยงdx: Tยงdy: T

Implementationsยง

Sourceยง

impl<T: Num> Vector<T>

Source

pub fn new(dx: T, dy: T) -> Self

Source

pub fn uniform(d: T) -> Self

Source

pub fn from_dx(dx: T) -> Self

Source

pub fn from_dy(dy: T) -> Self

Source

pub fn zero() -> Self

Source

pub fn one() -> Self

Source

pub fn from_array([dx, dy]: [T; 2]) -> Self

Source

pub fn from_tuple((dx, dy): (T, T)) -> Self

Source

pub fn with_dx(self, dx: T) -> Self

Source

pub fn with_dy(self, dy: T) -> Self

Source

pub fn dot_product(self, rhs: Self) -> T

Source

pub fn magnitude_squared(self) -> T

Source

pub fn magnitude(self) -> T
where T: Float,

Source

pub fn normalize(self) -> Self
where T: Float,

Source

pub fn angle(self) -> Angle<T>
where T: Float,

Source

pub fn scaled(self, rhs: Size<T>) -> Self

Source

pub fn perpendicular(self) -> Self
where T: Neg<Output = T>,

Source

pub fn yx(self) -> Self

Source

pub fn transform(&self, transform: Transform<T>) -> Self

Source

pub fn map<U: Num>(&self, f: impl FnMut(T) -> U) -> Vector<U>

Source

pub fn map_dx(&self, f: impl FnMut(T) -> T) -> Self

Source

pub fn map_dy(&self, f: impl FnMut(T) -> T) -> Self

Source

pub fn round(self) -> Self
where T: Float,

Source

pub fn cast<U: Num>(self) -> Vector<U>

Source

pub fn to_i8(self) -> Vector<i8>

Source

pub fn to_i16(self) -> Vector<i16>

Source

pub fn to_i32(self) -> Vector<i32>

Source

pub fn to_i64(self) -> Vector<i64>

Source

pub fn to_i128(self) -> Vector<i128>

Source

pub fn to_isize(self) -> Vector<isize>

Source

pub fn to_u8(self) -> Vector<u8>

Source

pub fn to_u16(self) -> Vector<u16>

Source

pub fn to_u32(self) -> Vector<u32>

Source

pub fn to_u64(self) -> Vector<u64>

Source

pub fn to_u128(self) -> Vector<u128>

Source

pub fn to_usize(self) -> Vector<usize>

Source

pub fn to_f32(self) -> Vector<f32>

Source

pub fn to_f64(self) -> Vector<f64>

Source

pub fn to_array(self) -> [T; 2]

Source

pub fn to_tuple(self) -> (T, T)

Source

pub fn to_point(self) -> Point<T>

Source

pub fn to_size(self) -> Size<T>

Trait Implementationsยง

Sourceยง

impl<T: Num> Add<Vector<T>> for Circle<T>

Sourceยง

type Output = Circle<T>

The resulting type after applying the + operator.
Sourceยง

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

Performs the + operation. Read more
Sourceยง

impl<T: Num> Add<Vector<T>> for Point<T>

Sourceยง

type Output = Point<T>

The resulting type after applying the + operator.
Sourceยง

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

Performs the + operation. Read more
Sourceยง

impl<T: Num> Add<Vector<T>> for Rect<T>

Sourceยง

type Output = Rect<T>

The resulting type after applying the + operator.
Sourceยง

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

Performs the + operation. Read more
Sourceยง

impl<T: Num> Add<Vector<T>> for RectPosition<T>

Sourceยง

type Output = RectPosition<T>

The resulting type after applying the + operator.
Sourceยง

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

Performs the + operation. Read more
Sourceยง

impl<T: Num> Add<Vector<T>> for Size<T>

Sourceยง

type Output = Size<T>

The resulting type after applying the + operator.
Sourceยง

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

Performs the + operation. Read more
Sourceยง

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

Sourceยง

type Output = Vector<T>

The resulting type after applying the + operator.
Sourceยง

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Sourceยง

impl<T: Num> AddAssign<Vector<T>> for Circle<T>

Sourceยง

fn add_assign(&mut self, rhs: Vector<T>)

Performs the += operation. Read more
Sourceยง

impl<T: Num> AddAssign<Vector<T>> for Point<T>

Sourceยง

fn add_assign(&mut self, rhs: Vector<T>)

Performs the += operation. Read more
Sourceยง

impl<T: Num> AddAssign<Vector<T>> for Rect<T>

Sourceยง

fn add_assign(&mut self, rhs: Vector<T>)

Performs the += operation. Read more
Sourceยง

impl<T: Num> AddAssign<Vector<T>> for RectPosition<T>

Sourceยง

fn add_assign(&mut self, rhs: Vector<T>)

Performs the += operation. Read more
Sourceยง

impl<T: Num> AddAssign<Vector<T>> for Size<T>

Sourceยง

fn add_assign(&mut self, rhs: Vector<T>)

Performs the += operation. Read more
Sourceยง

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

Sourceยง

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Sourceยง

impl<T: Clone> Clone for Vector<T>

Sourceยง

fn clone(&self) -> Vector<T>

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<T: Debug> Debug for Vector<T>

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl<T: Default> Default for Vector<T>

Sourceยง

fn default() -> Vector<T>

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl<T: Num> Div<T> for Vector<T>

Sourceยง

type Output = Vector<T>

The resulting type after applying the / operator.
Sourceยง

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Sourceยง

impl<T: Num> Div<Vector<T>> for Point<T>

Sourceยง

type Output = Point<T>

The resulting type after applying the / operator.
Sourceยง

fn div(self, rhs: Vector<T>) -> Self::Output

Performs the / operation. Read more
Sourceยง

impl<T: Num> Div<Vector<T>> for Rect<T>

Sourceยง

type Output = Rect<T>

The resulting type after applying the / operator.
Sourceยง

fn div(self, rhs: Vector<T>) -> Self::Output

Performs the / operation. Read more
Sourceยง

impl<T: Num> Div<Vector<T>> for Size<T>

Sourceยง

type Output = Size<T>

The resulting type after applying the / operator.
Sourceยง

fn div(self, rhs: Vector<T>) -> Self::Output

Performs the / operation. Read more
Sourceยง

impl<T: Num> Div for Vector<T>

Sourceยง

type Output = Vector<T>

The resulting type after applying the / operator.
Sourceยง

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Sourceยง

impl<T: Num> DivAssign<T> for Vector<T>

Sourceยง

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Sourceยง

impl<T: Num> DivAssign<Vector<T>> for Point<T>

Sourceยง

fn div_assign(&mut self, rhs: Vector<T>)

Performs the /= operation. Read more
Sourceยง

impl<T: Num> DivAssign<Vector<T>> for Rect<T>

Sourceยง

fn div_assign(&mut self, rhs: Vector<T>)

Performs the /= operation. Read more
Sourceยง

impl<T: Num> DivAssign<Vector<T>> for Size<T>

Sourceยง

fn div_assign(&mut self, rhs: Vector<T>)

Performs the /= operation. Read more
Sourceยง

impl<T: Num> DivAssign for Vector<T>

Sourceยง

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Sourceยง

impl<T: Float> From<Cardinal> for Vector<T>

Sourceยง

fn from(cardinal: Cardinal) -> Self

Converts to this type from the input type.
Sourceยง

impl<T: Float> From<Direction> for Vector<T>

Sourceยง

fn from(direction: Direction) -> Self

Converts to this type from the input type.
Sourceยง

impl<T: Num> From<Size<T>> for Vector<T>

Sourceยง

fn from(size: Size<T>) -> Self

Converts to this type from the input type.
Sourceยง

impl<T: Num> From<Vector<T>> for Size<T>

Sourceยง

fn from(vector: Vector<T>) -> Self

Converts to this type from the input type.
Sourceยง

impl<T: Hash> Hash for Vector<T>

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: Num> Mul<T> for Vector<T>

Sourceยง

type Output = Vector<T>

The resulting type after applying the * operator.
Sourceยง

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Sourceยง

impl<T: Num> Mul<Vector<T>> for Point<T>

Sourceยง

type Output = Point<T>

The resulting type after applying the * operator.
Sourceยง

fn mul(self, rhs: Vector<T>) -> Self::Output

Performs the * operation. Read more
Sourceยง

impl<T: Num> Mul<Vector<T>> for Rect<T>

Sourceยง

type Output = Rect<T>

The resulting type after applying the * operator.
Sourceยง

fn mul(self, rhs: Vector<T>) -> Self::Output

Performs the * operation. Read more
Sourceยง

impl<T: Num> Mul<Vector<T>> for Size<T>

Sourceยง

type Output = Size<T>

The resulting type after applying the * operator.
Sourceยง

fn mul(self, rhs: Vector<T>) -> Self::Output

Performs the * operation. Read more
Sourceยง

impl<T: Num> Mul for Vector<T>

Sourceยง

type Output = Vector<T>

The resulting type after applying the * operator.
Sourceยง

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Sourceยง

impl<T: Num> MulAssign<T> for Vector<T>

Sourceยง

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Sourceยง

impl<T: Num> MulAssign<Vector<T>> for Point<T>

Sourceยง

fn mul_assign(&mut self, rhs: Vector<T>)

Performs the *= operation. Read more
Sourceยง

impl<T: Num> MulAssign<Vector<T>> for Rect<T>

Sourceยง

fn mul_assign(&mut self, rhs: Vector<T>)

Performs the *= operation. Read more
Sourceยง

impl<T: Num> MulAssign<Vector<T>> for Size<T>

Sourceยง

fn mul_assign(&mut self, rhs: Vector<T>)

Performs the *= operation. Read more
Sourceยง

impl<T: Num> MulAssign for Vector<T>

Sourceยง

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Sourceยง

impl<T: Neg<Output = T> + Num> Neg for Vector<T>

Sourceยง

type Output = Vector<T>

The resulting type after applying the - operator.
Sourceยง

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Sourceยง

impl<T: Ord> Ord for Vector<T>

Sourceยง

fn cmp(&self, other: &Vector<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 ยท Sourceยง

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 ยท Sourceยง

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 ยท Sourceยง

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Sourceยง

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

Sourceยง

fn eq(&self, other: &Vector<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: PartialOrd> PartialOrd for Vector<T>

Sourceยง

fn partial_cmp(&self, other: &Vector<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: Num> Rem<T> for Vector<T>

Sourceยง

type Output = Vector<T>

The resulting type after applying the % operator.
Sourceยง

fn rem(self, rhs: T) -> Self::Output

Performs the % operation. Read more
Sourceยง

impl<T: Num> Rem<Vector<T>> for Point<T>

Sourceยง

type Output = Point<T>

The resulting type after applying the % operator.
Sourceยง

fn rem(self, rhs: Vector<T>) -> Self::Output

Performs the % operation. Read more
Sourceยง

impl<T: Num> Rem<Vector<T>> for Rect<T>

Sourceยง

type Output = Rect<T>

The resulting type after applying the % operator.
Sourceยง

fn rem(self, rhs: Vector<T>) -> Self::Output

Performs the % operation. Read more
Sourceยง

impl<T: Num> Rem<Vector<T>> for Size<T>

Sourceยง

type Output = Size<T>

The resulting type after applying the % operator.
Sourceยง

fn rem(self, rhs: Vector<T>) -> Self::Output

Performs the % operation. Read more
Sourceยง

impl<T: Num> Rem for Vector<T>

Sourceยง

type Output = Vector<T>

The resulting type after applying the % operator.
Sourceยง

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
Sourceยง

impl<T: Num> RemAssign<T> for Vector<T>

Sourceยง

fn rem_assign(&mut self, rhs: T)

Performs the %= operation. Read more
Sourceยง

impl<T: Num> RemAssign<Vector<T>> for Point<T>

Sourceยง

fn rem_assign(&mut self, rhs: Vector<T>)

Performs the %= operation. Read more
Sourceยง

impl<T: Num> RemAssign<Vector<T>> for Rect<T>

Sourceยง

fn rem_assign(&mut self, rhs: Vector<T>)

Performs the %= operation. Read more
Sourceยง

impl<T: Num> RemAssign<Vector<T>> for Size<T>

Sourceยง

fn rem_assign(&mut self, rhs: Vector<T>)

Performs the %= operation. Read more
Sourceยง

impl<T: Num> RemAssign for Vector<T>

Sourceยง

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
Sourceยง

impl<T: Num> Sub<Vector<T>> for Circle<T>

Sourceยง

type Output = Circle<T>

The resulting type after applying the - operator.
Sourceยง

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

Performs the - operation. Read more
Sourceยง

impl<T: Num> Sub<Vector<T>> for Point<T>

Sourceยง

type Output = Point<T>

The resulting type after applying the - operator.
Sourceยง

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

Performs the - operation. Read more
Sourceยง

impl<T: Num> Sub<Vector<T>> for Rect<T>

Sourceยง

type Output = Rect<T>

The resulting type after applying the - operator.
Sourceยง

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

Performs the - operation. Read more
Sourceยง

impl<T: Num> Sub<Vector<T>> for RectPosition<T>

Sourceยง

type Output = RectPosition<T>

The resulting type after applying the - operator.
Sourceยง

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

Performs the - operation. Read more
Sourceยง

impl<T: Num> Sub<Vector<T>> for Size<T>

Sourceยง

type Output = Size<T>

The resulting type after applying the - operator.
Sourceยง

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

Performs the - operation. Read more
Sourceยง

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

Sourceยง

type Output = Vector<T>

The resulting type after applying the - operator.
Sourceยง

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Sourceยง

impl<T: Num> SubAssign<Vector<T>> for Circle<T>

Sourceยง

fn sub_assign(&mut self, rhs: Vector<T>)

Performs the -= operation. Read more
Sourceยง

impl<T: Num> SubAssign<Vector<T>> for Point<T>

Sourceยง

fn sub_assign(&mut self, rhs: Vector<T>)

Performs the -= operation. Read more
Sourceยง

impl<T: Num> SubAssign<Vector<T>> for Rect<T>

Sourceยง

fn sub_assign(&mut self, rhs: Vector<T>)

Performs the -= operation. Read more
Sourceยง

impl<T: Num> SubAssign<Vector<T>> for RectPosition<T>

Sourceยง

fn sub_assign(&mut self, rhs: Vector<T>)

Performs the -= operation. Read more
Sourceยง

impl<T: Num> SubAssign<Vector<T>> for Size<T>

Sourceยง

fn sub_assign(&mut self, rhs: Vector<T>)

Performs the -= operation. Read more
Sourceยง

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

Sourceยง

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Sourceยง

impl<T: Copy> Copy for Vector<T>

Sourceยง

impl<T: Eq> Eq for Vector<T>

Sourceยง

impl<T> StructuralPartialEq for Vector<T>

Auto Trait Implementationsยง

ยง

impl<T> Freeze for Vector<T>
where T: Freeze,

ยง

impl<T> RefUnwindSafe for Vector<T>
where T: RefUnwindSafe,

ยง

impl<T> Send for Vector<T>
where T: Send,

ยง

impl<T> Sync for Vector<T>
where T: Sync,

ยง

impl<T> Unpin for Vector<T>
where T: Unpin,

ยง

impl<T> UnwindSafe for Vector<T>
where T: UnwindSafe,

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> Max for T
where T: PartialOrd,

Sourceยง

fn max(self, other: T) -> T

Sourceยง

impl<T> Min for T
where T: PartialOrd,

Sourceยง

fn min(self, other: T) -> T

Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Sourceยง

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

Sourceยง

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,