Skip to main content

Quaternion

Struct Quaternion 

Source
pub struct Quaternion<T, A: Alignment>(/* private fields */)
where
    T: Scalar;
Expand description

A quaternion representing an orientation.

Note: Quaternion is currently missing most of its functionality.

This quaternion is intended to be of unit length but may denormalize due to floating point “error creep” which can occur when successive quaternion operations are applied.

Quaternion is the generic form of:

Quaternion is generic over:

§Guarantees

Quaternion<T, A> is a transparent wrapper around Vector<4, T, A>, and thus inherits its guarantees.

Implementations§

Source§

impl<T, A: Alignment> Quaternion<T, A>
where T: Scalar,

Source

pub const fn new(x: T, y: T, z: T, w: T) -> Self

Creates a rotation quaternion.

This is currently the only way to initialize a quaternion. In the future there will be mathamatical constructors that are recommended over this one.

§Unchecked

This function does not check if the input is normalized. It is up to the user to provide normalized input or to normalize the resulting quaternion.

Source

pub const fn from_array(array: [T; 4]) -> Self

Creates a rotation quaternion from an array.

§Unchecked

This function does not check if the input is normalized. It is up to the user to provide normalized input or to normalize the resulting quaternion.

Source

pub const fn from_vec(vec: Vector<4, T, A>) -> Self

Creates a rotation quaternion from a 4-dimensional vector.

§Unchecked

This function does not check if the input is normalized. It is up to the user to provide normalized input or to normalize the resulting quaternion.

Source

pub const fn to_alignment<A2: Alignment>(self) -> Quaternion<T, A2>

Converts the quaternion to the specified alignment.

See Alignment for more information.

Source

pub const fn align(self) -> Quaternion<T, Aligned>

Converts the quaternion to Aligned alignment.

See Alignment for more information.

Source

pub const fn unalign(self) -> Quaternion<T, Unaligned>

Converts the quaternion to Unaligned alignment.

See Alignment for more information.

Source

pub const fn to_array(self) -> [T; 4]

Converts the quaternion to an array.

Source

pub const fn as_array_ref(&self) -> &[T; 4]

Returns a reference to the quaternion’s components.

Source

pub const fn as_array_mut(&mut self) -> &mut [T; 4]

Returns a mutable reference to the quaternion’s components.

Source

pub const fn to_vec(self) -> Vector<4, T, A>

Converts the quaternion to a 4-dimensional vector.

Source

pub const fn as_vec_ref(&self) -> &Vector<4, T, A>

Returns a reference to the quaternion as a 4-dimensional vector.

Source

pub const fn as_vec_mut(&mut self) -> &mut Vector<4, T, A>

Returns a mutable reference to the quaternion as a 4-dimensional vector.

Source§

impl<T, A: Alignment> Quaternion<T, A>
where T: Scalar + Zero,

Source

pub const ZERO: Self

All 0.0.

Source§

impl<T, A: Alignment> Quaternion<T, A>
where T: Scalar + Zero + One,

Source

pub const IDENTITY: Self

The identity quaternion. Corresponds to no rotation.

Source§

impl<T, A: Alignment> Quaternion<T, A>
where T: Scalar + Nan,

Source

pub const NAN: Self

All NaNs (Not a Number).

Trait Implementations§

Source§

impl<T, A: Alignment> Add for Quaternion<T, A>
where T: Scalar + Add<Output = T>,

Source§

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

Adds two quaternions.

The sum is not guaranteed to be normalized.

Note that addition is not the same as combining the rotations represented by the two quaternions! That corresponds to multiplication (not implemented yet).

Source§

type Output = Quaternion<T, A>

The resulting type after applying the + operator.
Source§

impl<T, A: Alignment> AddAssign for Quaternion<T, A>
where T: Scalar + Add<Output = T>,

Source§

fn add_assign(&mut self, rhs: Self)

Adds the quaternion rhs to self.

The sum is not guaranteed to be normalized.

Note that addition is not the same as combining the rotations represented by the two quaternions! That corresponds to multiplication (not implemented yet).

Source§

impl<T, A: Alignment> Clone for Quaternion<T, A>
where T: Scalar,

Source§

fn clone(&self) -> Self

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, A: Alignment> Debug for Quaternion<T, A>
where T: Scalar + Debug,

Source§

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

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

impl<T, A: Alignment> Default for Quaternion<T, A>
where T: Scalar + Zero + One,

Source§

fn default() -> Self

Returns Quaternion::IDENTITY.

Source§

impl<T, A: Alignment> Deref for Quaternion<T, A>
where T: Scalar,

Source§

type Target = Xyzw<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T, A: Alignment> DerefMut for Quaternion<T, A>
where T: Scalar,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T, A: Alignment> Display for Quaternion<T, A>
where T: Scalar + Display,

Source§

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

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

impl<T, A: Alignment> Hash for Quaternion<T, A>
where T: Scalar + Hash,

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, A: Alignment> Mul<T> for Quaternion<T, A>
where T: Scalar + Mul<Output = T>,

Source§

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

Multiplies a quaternion by a scalar value.

The product is not guaranteed to be normalized.

Source§

type Output = Quaternion<T, A>

The resulting type after applying the * operator.
Source§

impl<T, A: Alignment> MulAssign<T> for Quaternion<T, A>
where T: Scalar + Mul<Output = T>,

Source§

fn mul_assign(&mut self, rhs: T)

Multiplies the quaternion by a scalar value.

The product is not guaranteed to be normalized.

Source§

impl<T, A: Alignment> Neg for Quaternion<T, A>
where T: Scalar + Neg<Output = T>,

Source§

type Output = Quaternion<T, A>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T, A: Alignment> PartialEq for Quaternion<T, A>
where T: Scalar + PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &Self) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, A: Alignment> Sub for Quaternion<T, A>
where T: Scalar + Sub<Output = T>,

Source§

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

Subtracts the quaternion rhs from self.

The difference is not guaranteed to be normalized.

Source§

type Output = Quaternion<T, A>

The resulting type after applying the - operator.
Source§

impl<T, A: Alignment> SubAssign for Quaternion<T, A>
where T: Scalar + Sub<Output = T>,

Source§

fn sub_assign(&mut self, rhs: Self)

Subtracts the quaternion rhs from self.

The difference is not guaranteed to be normalized.

Source§

impl<T, A: Alignment> Copy for Quaternion<T, A>
where T: Scalar,

Source§

impl<T, A: Alignment> Eq for Quaternion<T, A>
where T: Scalar + Eq,

Auto Trait Implementations§

§

impl<T, A> Freeze for Quaternion<T, A>
where <<T as Scalar>::Repr as ScalarRepr>::VectorRepr<4, T, A>: Freeze,

§

impl<T, A> RefUnwindSafe for Quaternion<T, A>
where T: RefUnwindSafe,

§

impl<T, A> Send for Quaternion<T, A>
where T: Send,

§

impl<T, A> Sync for Quaternion<T, A>
where T: Sync,

§

impl<T, A> Unpin for Quaternion<T, A>
where T: Unpin,

§

impl<T, A> UnsafeUnpin for Quaternion<T, A>
where <<T as Scalar>::Repr as ScalarRepr>::VectorRepr<4, T, A>: UnsafeUnpin,

§

impl<T, A> UnwindSafe for Quaternion<T, A>
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.