Type Alias oxygengine_physics_2d::prelude::nalgebra::UnitVector2
source · pub type UnitVector2<T> = Unit<Matrix<T, Const<nalgebra::::base::dimension::U2::{constant#0}>, Const<1>, ArrayStorage<T, 2, 1>>>;
Expand description
A stack-allocated, 2-dimensional unit vector.
Aliased Type§
struct UnitVector2<T> { /* private fields */ }
Implementations§
source§impl<T> Unit<T>where
T: Normed,
impl<T> Unit<T>where T: Normed,
sourcepub fn new_normalize(value: T) -> Unit<T>
pub fn new_normalize(value: T) -> Unit<T>
Normalize the given vector and return it wrapped on a Unit
structure.
sourcepub fn try_new(value: T, min_norm: <T as Normed>::Norm) -> Option<Unit<T>>where
<T as Normed>::Norm: RealField,
pub fn try_new(value: T, min_norm: <T as Normed>::Norm) -> Option<Unit<T>>where <T as Normed>::Norm: RealField,
Attempts to normalize the given vector and return it wrapped on a Unit
structure.
Returns None
if the norm was smaller or equal to min_norm
.
sourcepub fn new_and_get(value: T) -> (Unit<T>, <T as Normed>::Norm)
pub fn new_and_get(value: T) -> (Unit<T>, <T as Normed>::Norm)
Normalize the given vector and return it wrapped on a Unit
structure and its norm.
sourcepub fn try_new_and_get(
value: T,
min_norm: <T as Normed>::Norm
) -> Option<(Unit<T>, <T as Normed>::Norm)>where
<T as Normed>::Norm: RealField,
pub fn try_new_and_get( value: T, min_norm: <T as Normed>::Norm ) -> Option<(Unit<T>, <T as Normed>::Norm)>where <T as Normed>::Norm: RealField,
Normalize the given vector and return it wrapped on a Unit
structure and its norm.
Returns None
if the norm was smaller or equal to min_norm
.
sourcepub fn renormalize(&mut self) -> <T as Normed>::Norm
pub fn renormalize(&mut self) -> <T as Normed>::Norm
Normalizes this vector again. This is useful when repeated computations might cause a drift in the norm because of float inaccuracies.
Returns the norm before re-normalization. See .renormalize_fast
for a faster alternative
that may be slightly less accurate if self
drifted significantly from having a unit length.
sourcepub fn renormalize_fast(&mut self)
pub fn renormalize_fast(&mut self)
Normalizes this vector again using a first-order Taylor approximation. This is useful when repeated computations might cause a drift in the norm because of float inaccuracies.
source§impl<T> Unit<T>
impl<T> Unit<T>
sourcepub const fn new_unchecked(value: T) -> Unit<T>
pub const fn new_unchecked(value: T) -> Unit<T>
Wraps the given value, assuming it is already normalized.
sourcepub fn from_ref_unchecked(value: &T) -> &Unit<T>
pub fn from_ref_unchecked(value: &T) -> &Unit<T>
Wraps the given reference, assuming it is already normalized.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Retrieves the underlying value.
sourcepub fn unwrap(self) -> T
👎Deprecated: use .into_inner()
instead
pub fn unwrap(self) -> T
.into_inner()
insteadRetrieves the underlying value.
Deprecated: use Unit::into_inner
instead.
sourcepub fn as_mut_unchecked(&mut self) -> &mut T
pub fn as_mut_unchecked(&mut self) -> &mut T
Returns a mutable reference to the underlying value. This is _unchecked
because modifying
the underlying value in such a way that it no longer has unit length may lead to unexpected
results.
source§impl<T, D, S> Unit<Matrix<T, D, Const<1>, S>>where
T: RealField,
D: Dim,
S: Storage<T, D, Const<1>>,
impl<T, D, S> Unit<Matrix<T, D, Const<1>, S>>where T: RealField, D: Dim, S: Storage<T, D, Const<1>>,
sourcepub fn slerp<S2>(
&self,
rhs: &Unit<Matrix<T, D, Const<1>, S2>>,
t: T
) -> Unit<Matrix<T, D, Const<1>, <DefaultAllocator as Allocator<T, D, Const<1>>>::Buffer>>where
S2: Storage<T, D, Const<1>>,
DefaultAllocator: Allocator<T, D, Const<1>>,
pub fn slerp<S2>( &self, rhs: &Unit<Matrix<T, D, Const<1>, S2>>, t: T ) -> Unit<Matrix<T, D, Const<1>, <DefaultAllocator as Allocator<T, D, Const<1>>>::Buffer>>where S2: Storage<T, D, Const<1>>, DefaultAllocator: Allocator<T, D, Const<1>>,
Computes the spherical linear interpolation between two unit vectors.
Examples:
let v1 = Unit::new_normalize(Vector2::new(1.0, 2.0));
let v2 = Unit::new_normalize(Vector2::new(2.0, -3.0));
let v = v1.slerp(&v2, 1.0);
assert_eq!(v, v2);
sourcepub fn try_slerp<S2>(
&self,
rhs: &Unit<Matrix<T, D, Const<1>, S2>>,
t: T,
epsilon: T
) -> Option<Unit<Matrix<T, D, Const<1>, <DefaultAllocator as Allocator<T, D, Const<1>>>::Buffer>>>where
S2: Storage<T, D, Const<1>>,
DefaultAllocator: Allocator<T, D, Const<1>>,
pub fn try_slerp<S2>( &self, rhs: &Unit<Matrix<T, D, Const<1>, S2>>, t: T, epsilon: T ) -> Option<Unit<Matrix<T, D, Const<1>, <DefaultAllocator as Allocator<T, D, Const<1>>>::Buffer>>>where S2: Storage<T, D, Const<1>>, DefaultAllocator: Allocator<T, D, Const<1>>,
Computes the spherical linear interpolation between two unit vectors.
Returns None
if the two vectors are almost collinear and with opposite direction
(in this case, there is an infinity of possible results).
Trait Implementations§
source§impl<T, R, C, S> AbsDiffEq<Unit<Matrix<T, R, C, S>>> for Unit<Matrix<T, R, C, S>>where
R: Dim,
C: Dim,
T: Scalar + AbsDiffEq<T>,
S: RawStorage<T, R, C>,
<T as AbsDiffEq<T>>::Epsilon: Clone,
impl<T, R, C, S> AbsDiffEq<Unit<Matrix<T, R, C, S>>> for Unit<Matrix<T, R, C, S>>where R: Dim, C: Dim, T: Scalar + AbsDiffEq<T>, S: RawStorage<T, R, C>, <T as AbsDiffEq<T>>::Epsilon: Clone,
source§fn default_epsilon(
) -> <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon
fn default_epsilon( ) -> <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon
source§fn abs_diff_eq(
&self,
other: &Unit<Matrix<T, R, C, S>>,
epsilon: <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon
) -> bool
fn abs_diff_eq( &self, other: &Unit<Matrix<T, R, C, S>>, epsilon: <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon ) -> bool
§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq
].source§impl<'de, T> Deserialize<'de> for Unit<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Unit<T>where T: Deserialize<'de>,
source§fn deserialize<D>(
deserializer: D
) -> Result<Unit<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<Unit<T>, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
source§impl<T, R, C> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 16]> for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where
T: Scalar + PrimitiveSimdValue + From<[<T as SimdValue>::Element; 16]>,
R: Dim,
C: Dim,
<T as SimdValue>::Element: Scalar,
DefaultAllocator: Allocator<T, R, C> + Allocator<<T as SimdValue>::Element, R, C>,
impl<T, R, C> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 16]> for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where T: Scalar + PrimitiveSimdValue + From<[<T as SimdValue>::Element; 16]>, R: Dim, C: Dim, <T as SimdValue>::Element: Scalar, DefaultAllocator: Allocator<T, R, C> + Allocator<<T as SimdValue>::Element, R, C>,
source§impl<T, R, C> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 2]> for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where
T: Scalar + PrimitiveSimdValue + From<[<T as SimdValue>::Element; 2]>,
R: Dim,
C: Dim,
<T as SimdValue>::Element: Scalar,
DefaultAllocator: Allocator<T, R, C> + Allocator<<T as SimdValue>::Element, R, C>,
impl<T, R, C> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 2]> for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where T: Scalar + PrimitiveSimdValue + From<[<T as SimdValue>::Element; 2]>, R: Dim, C: Dim, <T as SimdValue>::Element: Scalar, DefaultAllocator: Allocator<T, R, C> + Allocator<<T as SimdValue>::Element, R, C>,
source§impl<T, R, C> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 4]> for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where
T: Scalar + PrimitiveSimdValue + From<[<T as SimdValue>::Element; 4]>,
R: Dim,
C: Dim,
<T as SimdValue>::Element: Scalar,
DefaultAllocator: Allocator<T, R, C> + Allocator<<T as SimdValue>::Element, R, C>,
impl<T, R, C> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 4]> for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where T: Scalar + PrimitiveSimdValue + From<[<T as SimdValue>::Element; 4]>, R: Dim, C: Dim, <T as SimdValue>::Element: Scalar, DefaultAllocator: Allocator<T, R, C> + Allocator<<T as SimdValue>::Element, R, C>,
source§impl<T, R, C> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 8]> for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where
T: Scalar + PrimitiveSimdValue + From<[<T as SimdValue>::Element; 8]>,
R: Dim,
C: Dim,
<T as SimdValue>::Element: Scalar,
DefaultAllocator: Allocator<T, R, C> + Allocator<<T as SimdValue>::Element, R, C>,
impl<T, R, C> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 8]> for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where T: Scalar + PrimitiveSimdValue + From<[<T as SimdValue>::Element; 8]>, R: Dim, C: Dim, <T as SimdValue>::Element: Scalar, DefaultAllocator: Allocator<T, R, C> + Allocator<<T as SimdValue>::Element, R, C>,
source§impl<T, R, C> Neg for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where
T: Scalar + ClosedNeg,
R: Dim,
C: Dim,
DefaultAllocator: Allocator<T, R, C>,
impl<T, R, C> Neg for Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>where T: Scalar + ClosedNeg, R: Dim, C: Dim, DefaultAllocator: Allocator<T, R, C>,
source§impl<T, R, C, S> PartialEq<Unit<Matrix<T, R, C, S>>> for Unit<Matrix<T, R, C, S>>where
T: Scalar + PartialEq<T>,
R: Dim,
C: Dim,
S: RawStorage<T, R, C>,
impl<T, R, C, S> PartialEq<Unit<Matrix<T, R, C, S>>> for Unit<Matrix<T, R, C, S>>where T: Scalar + PartialEq<T>, R: Dim, C: Dim, S: RawStorage<T, R, C>,
source§impl<T, R, C, S> RelativeEq<Unit<Matrix<T, R, C, S>>> for Unit<Matrix<T, R, C, S>>where
R: Dim,
C: Dim,
T: Scalar + RelativeEq<T>,
S: Storage<T, R, C>,
<T as AbsDiffEq<T>>::Epsilon: Clone,
impl<T, R, C, S> RelativeEq<Unit<Matrix<T, R, C, S>>> for Unit<Matrix<T, R, C, S>>where R: Dim, C: Dim, T: Scalar + RelativeEq<T>, S: Storage<T, R, C>, <T as AbsDiffEq<T>>::Epsilon: Clone,
source§fn default_max_relative(
) -> <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon
fn default_max_relative( ) -> <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon
source§fn relative_eq(
&self,
other: &Unit<Matrix<T, R, C, S>>,
epsilon: <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon,
max_relative: <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon
) -> bool
fn relative_eq( &self, other: &Unit<Matrix<T, R, C, S>>, epsilon: <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon, max_relative: <Unit<Matrix<T, R, C, S>> as AbsDiffEq<Unit<Matrix<T, R, C, S>>>>::Epsilon ) -> bool
§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool
RelativeEq::relative_eq
].