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>
impl<T: Float> Vector2<T>
Sourcepub fn unit_vector(direction: T) -> Self
pub fn unit_vector(direction: T) -> Self
Creates a new unit vector in a specific direction
Sourcepub fn length_squared(self) -> T
pub fn length_squared(self) -> T
Returns the magnitude/length of the vector squared
Sourcepub fn direction_to(self, other: Self) -> T
pub fn direction_to(self, other: Self) -> T
Returns direction towards another vector
Sourcepub fn distance_to(self, other: Self) -> T
pub fn distance_to(self, other: Self) -> T
Returns the distance betweens two vectors
Sourcepub fn distance_to_squared(self, other: Self) -> T
pub fn distance_to_squared(self, other: Self) -> T
Returns the distance betweens two vectors
Sourcepub fn is_any_nan(&self) -> bool
pub fn is_any_nan(&self) -> bool
Returns true
if either component is NaN
.
Sourcepub fn is_any_infinite(&self) -> bool
pub fn is_any_infinite(&self) -> bool
Returns true
if either component is positive or negative infinity.
Sourcepub fn is_all_finite(&self) -> bool
pub fn is_all_finite(&self) -> bool
Returns true
if both components are neither infinite nor NaN
.
Sourcepub fn is_all_normal(&self) -> bool
pub fn is_all_normal(&self) -> bool
Returns true
if both components are neither zero, infinite, subnormal nor NaN
.
Source§impl<T> Vector2<T>
impl<T> Vector2<T>
Sourcepub fn normal(self) -> Selfwhere
T: Neg<Output = T>,
pub fn normal(self) -> Selfwhere
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)
Trait Implementations§
Source§impl<T: AddAssign> AddAssign for Vector2<T>
impl<T: AddAssign> AddAssign for Vector2<T>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moreSource§impl<T: DivAssign + Copy> DivAssign<T> for Vector2<T>
impl<T: DivAssign + Copy> DivAssign<T> for Vector2<T>
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
Performs the
/=
operation. Read moreSource§impl<T: MulAssign + Copy> MulAssign<T> for Vector2<T>
impl<T: MulAssign + Copy> MulAssign<T> for Vector2<T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the
*=
operation. Read moreSource§impl<T: SubAssign> SubAssign for Vector2<T>
impl<T: SubAssign> SubAssign for Vector2<T>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moreimpl<T: Copy> Copy for Vector2<T>
impl<T: Eq> Eq for Vector2<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more