Vector2

Struct Vector2 

Source
pub struct Vector2<T> {
    pub x: T,
    pub y: T,
}

Fields§

§x: T§y: T

Implementations§

Source§

impl<T> Vector2<T>

Source

pub const fn new(x: T, y: T) -> Vector2<T>

Make a new vector

Source

pub fn cast_to<R: From<T>>(self) -> Vector2<R>

Cast a vector from type T to type R

Source

pub fn map<R, M: FnMut(T) -> R>(self, f: M) -> Vector2<R>

Source§

impl<T: Add<Output = T> + Mul<Output = T> + Copy> Vector2<T>

Source

pub fn square_magnitude(&self) -> T

Returns the value of (x * x) + (y * y). Integer types don’t implement sqrt so we can’t implement magnitude.

Source§

impl<T: Mul<Output = T> + Add<Output = T> + Sub<Output = T> + Copy + PartialOrd> Vector2<T>

Source

pub fn square_distance(&self, from: &Vector2<T>) -> T

Returns the value of (x_2 - x_1)^2 + (y_2 - y_1)^2. Integer types don’t implement sqrt so we can’t implement distance.

Source§

impl Vector2<f32>

Source

pub fn magnitude(&self) -> f32

Source

pub fn distance(&self, other: &Vector2<f32>) -> f32

Source§

impl Vector2<f64>

Source

pub fn magnitude(&self) -> f64

Source

pub fn distance(&self, other: &Vector2<f64>) -> f64

Trait Implementations§

Source§

impl<T> Add for Vector2<T>
where T: Add<Output = T>,

Source§

type Output = Vector2<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: Clone> Clone for Vector2<T>

Source§

fn clone(&self) -> Vector2<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 Vector2<T>

Source§

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

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

impl<T: Default> Default for Vector2<T>

Source§

fn default() -> Self

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

impl<T: Display> Display for Vector2<T>

Source§

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

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

impl<T> Div<T> for Vector2<T>
where T: Div<Output = T> + Copy,

Source§

type Output = Vector2<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T> From<(T, T)> for Vector2<T>

Source§

fn from(value: (T, T)) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Vector2<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> Mul<T> for Vector2<T>
where T: Mul<Output = T> + Copy,

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<f32>> for f32

Source§

type Output = Vector2<f32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<f64>> for f64

Source§

type Output = Vector2<f64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<i128>> for i128

Source§

type Output = Vector2<i128>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<i16>> for i16

Source§

type Output = Vector2<i16>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<i32>> for i32

Source§

type Output = Vector2<i32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<i64>> for i64

Source§

type Output = Vector2<i64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<i8>> for i8

Source§

type Output = Vector2<i8>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<isize>> for isize

Source§

type Output = Vector2<isize>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<u128>> for u128

Source§

type Output = Vector2<u128>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<u16>> for u16

Source§

type Output = Vector2<u16>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<u32>> for u32

Source§

type Output = Vector2<u32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<u64>> for u64

Source§

type Output = Vector2<u64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<u8>> for u8

Source§

type Output = Vector2<u8>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<usize>> for usize

Source§

type Output = Vector2<usize>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Ord> Ord for Vector2<T>

Source§

fn cmp(&self, other: &Vector2<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 Vector2<T>

Source§

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

Source§

fn partial_cmp(&self, other: &Vector2<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> Sub for Vector2<T>
where T: Sub<Output = T>,

Source§

type Output = Vector2<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Vector2ToDouble for Vector2<f32>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<f64>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<i128>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<i16>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<i32>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<i64>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<i8>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<isize>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<u128>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<u16>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<u32>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<u64>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<u8>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToDouble for Vector2<usize>

Convert a Vector<$m> to its f64 (double) representation.

§Panics

Panics whenever converting $m to f64 by writing $m as f64 would fail.

Source§

fn to_double(self) -> Vector2<f64>

Convert a Vector to its f64 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<f32>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<f64>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<i128>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<i16>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<i32>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<i64>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<i8>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<isize>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<u128>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<u16>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<u32>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<u64>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<u8>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl Vector2ToFloat for Vector2<usize>

Source§

fn to_float(self) -> Vector2<f32>

Convert a Vector to its f32 (float) representation. Read more
Source§

impl<T: Copy> Copy for Vector2<T>

Source§

impl<T: Eq> Eq for Vector2<T>

Source§

impl<T> StructuralPartialEq for Vector2<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Vector2<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, 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.