Struct Vector2

Source
pub struct Vector2<T>(pub T, pub T);
Expand description

Representation of a mathematical vector e.g. a position or velocity

Tuple Fields§

§0: T§1: T

Implementations§

Source§

impl<T: Float> Vector2<T>

Source

pub fn unit_vector(direction: T) -> Self

Creates a new unit vector in a specific direction

Source

pub fn normalise(self) -> Self

Normalises the vector

Source

pub fn length(self) -> T

Returns the magnitude/length of the vector

Source

pub fn length_squared(self) -> T

Returns the magnitude/length of the vector squared

Source

pub fn direction(self) -> T

Returns direction the vector is pointing

Source

pub fn direction_to(self, other: Self) -> T

Returns direction towards another vector

Source

pub fn distance_to(self, other: Self) -> T

Returns the distance betweens two vectors

Source

pub fn distance_to_squared(self, other: Self) -> T

Returns the distance betweens two vectors

Source

pub fn is_any_nan(&self) -> bool

Returns true if either component is NaN.

Source

pub fn is_any_infinite(&self) -> bool

Returns true if either component is positive or negative infinity.

Source

pub fn is_all_finite(&self) -> bool

Returns true if both components are neither infinite nor NaN.

Source

pub fn is_all_normal(&self) -> bool

Returns true if both components are neither zero, infinite, subnormal nor NaN.

Source§

impl<T> Vector2<T>

Source

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

Returns the normal vector (aka. hat vector) of this vector i.e. a perpendicular vector

Not to be confused with normalise which returns a unit vector

Defined as (-y, x)

Source

pub fn dot(self, other: Self) -> <<T as Mul>::Output as Add>::Output
where T: Mul, <T as Mul>::Output: Add,

Returns the dot product of two vectors

Source

pub fn det(self, other: Self) -> <<T as Mul>::Output as Sub>::Output
where T: Mul, <T as Mul>::Output: Sub,

Returns the determinant of two vectors

Trait Implementations§

Source§

impl<T: Add> Add for Vector2<T>

Source§

type Output = Vector2<<T as Add>::Output>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: AddAssign> AddAssign for Vector2<T>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

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

Source§

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

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<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() -> Vector2<T>

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

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

Source§

type Output = Vector2<<T as Div>::Output>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div<Vector2<f32>> for f32

Source§

type Output = Vector2<f32>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vector2<f32>) -> Vector2<f32>

Performs the / operation. Read more
Source§

impl Div<Vector2<f64>> for f64

Source§

type Output = Vector2<f64>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vector2<f64>) -> Vector2<f64>

Performs the / operation. Read more
Source§

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

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T: Copy> From<[T; 2]> for Vector2<T>

Source§

fn from(array: [T; 2]) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<T> Into<[T; 2]> for Vector2<T>

Source§

fn into(self) -> [T; 2]

Converts this type into the (usually inferred) input type.
Source§

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

Source§

fn into(self) -> (T, T)

Converts this type into the (usually inferred) input type.
Source§

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

Source§

type Output = Vector2<<T as Mul>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: 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>) -> Vector2<f32>

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>) -> Vector2<f64>

Performs the * operation. Read more
Source§

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

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T: Neg> Neg for Vector2<T>

Source§

type Output = Vector2<<T as Neg>::Output>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. 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: Sub> Sub for Vector2<T>

Source§

type Output = Vector2<<T as Sub>::Output>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: SubAssign> SubAssign for Vector2<T>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. 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> 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.