nalgebra::base

Type Alias UnitVector5

Source
pub type UnitVector5<T> = Unit<Matrix<T, U5, U1, ArrayStorage<T, 5, 1>>>;
Expand description

A stack-allocated, 5-dimensional unit vector.

Aliased Type§

struct UnitVector5<T> { /* private fields */ }

Implementations

Source§

impl<T: RealField, D: Dim, S: Storage<T, D>> Unit<Vector<T, D, S>>

§Interpolation between two unit vectors

Source

pub fn slerp<S2: Storage<T, D>>( &self, rhs: &Unit<Vector<T, D, S2>>, t: T, ) -> Unit<OVector<T, D>>

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);
Source

pub fn try_slerp<S2: Storage<T, D>>( &self, rhs: &Unit<Vector<T, D, S2>>, t: T, epsilon: T, ) -> Option<Unit<OVector<T, D>>>

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).

Source§

impl<T: Normed> Unit<T>

§Construction with normalization

Source

pub fn new_normalize(value: T) -> Self

Normalize the given vector and return it wrapped on a Unit structure.

Source

pub fn try_new(value: T, min_norm: T::Norm) -> Option<Self>
where T::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.

Source

pub fn new_and_get(value: T) -> (Self, T::Norm)

Normalize the given vector and return it wrapped on a Unit structure and its norm.

Source

pub fn try_new_and_get(value: T, min_norm: T::Norm) -> Option<(Self, T::Norm)>
where T::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.

Source

pub fn renormalize(&mut self) -> T::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.

Source

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>

§Data extraction and construction without normalization

Source

pub const fn new_unchecked(value: T) -> Self

Wraps the given value, assuming it is already normalized.

Source

pub fn from_ref_unchecked(value: &T) -> &Self

Wraps the given reference, assuming it is already normalized.

Source

pub fn into_inner(self) -> T

Retrieves the underlying value.

Source

pub fn unwrap(self) -> T

👎Deprecated: use .into_inner() instead

Retrieves the underlying value. Deprecated: use Unit::into_inner instead.

Source

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.

Trait Implementations

Source§

impl<T, R: Dim, C: Dim, S> AbsDiffEq for Unit<Matrix<T, R, C, S>>
where T: Scalar + AbsDiffEq, S: RawStorage<T, R, C>, T::Epsilon: Clone,

Source§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
Source§

impl<T> AsRef<T> for Unit<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone> Clone for Unit<T>

Source§

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

Source§

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

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

impl<T> Deref for Unit<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit<T>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T, R: Dim, C: Dim> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 16]> for Unit<OMatrix<T, R, C>>

Source§

fn from(arr: [Unit<OMatrix<T::Element, R, C>>; 16]) -> Self

Converts to this type from the input type.
Source§

impl<T, R: Dim, C: Dim> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 2]> for Unit<OMatrix<T, R, C>>

Source§

fn from(arr: [Unit<OMatrix<T::Element, R, C>>; 2]) -> Self

Converts to this type from the input type.
Source§

impl<T, R: Dim, C: Dim> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 4]> for Unit<OMatrix<T, R, C>>

Source§

fn from(arr: [Unit<OMatrix<T::Element, R, C>>; 4]) -> Self

Converts to this type from the input type.
Source§

impl<T, R: Dim, C: Dim> From<[Unit<Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>>; 8]> for Unit<OMatrix<T, R, C>>

Source§

fn from(arr: [Unit<OMatrix<T::Element, R, C>>; 8]) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Unit<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: Scalar + ClosedNeg, R: Dim, C: Dim> Neg for Unit<OMatrix<T, R, C>>
where DefaultAllocator: Allocator<T, R, C>,

Source§

type Output = Unit<Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T, R, C, S> PartialEq for Unit<Matrix<T, R, C, S>>
where T: Scalar + PartialEq, R: Dim, C: Dim, S: RawStorage<T, R, C>,

Source§

fn eq(&self, rhs: &Self) -> 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, R: Dim, C: Dim, S> RelativeEq for Unit<Matrix<T, R, C, S>>
where T: Scalar + RelativeEq, S: Storage<T, R, C>, T::Epsilon: Clone,

Source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
Source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of RelativeEq::relative_eq.
Source§

impl<T: Serialize> Serialize for Unit<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T, R: Dim, C: Dim, S> UlpsEq for Unit<Matrix<T, R, C, S>>
where T: Scalar + UlpsEq, S: RawStorage<T, R, C>, T::Epsilon: Clone,

Source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
Source§

fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
Source§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of UlpsEq::ulps_eq.
Source§

impl<T: Copy> Copy for Unit<T>

Source§

impl<T, R, C, S> Eq for Unit<Matrix<T, R, C, S>>
where T: Scalar + Eq, R: Dim, C: Dim, S: RawStorage<T, R, C>,