Struct veloren_voxygen_anim::vek::Quaternion

source ·
#[repr(simd)]
pub struct Quaternion<T> { pub x: T, pub y: T, pub z: T, pub w: T, }
Expand description

Quaternions are a convenient representation for rotations in 3D spaces.

IMPORTANT: Quaternions are only valid as rotations as long as they are normalized (i.e their magnitude is 1). Most operations assume this, instead of normalizing inputs behind your back, so be careful.

They essentially consist of a vector part (x, y, z), and scalar part (w). For unit quaternions, the vector part is the unit axis of rotation scaled by the sine of the half-angle of the rotation, and the scalar part is the cosine of the half-angle.

Fields§

§x: T§y: T§z: T§w: T

Implementations§

source§

impl<T> Quaternion<T>

source

pub fn from_xyzw(x: T, y: T, z: T, w: T) -> Quaternion<T>

Creates a new quaternion with x, y, z and w elements in order.

You are responsible for ensuring that the resulting quaternion is normalized.

source

pub fn from_scalar_and_vec3<V>(pair: (T, V)) -> Quaternion<T>
where V: Into<Vec3<T>>,

Creates a new quaternion from a scalar-and-vector pair.

You are responsible for ensuring that the resulting quaternion is normalized.

source

pub fn into_scalar_and_vec3(self) -> (T, Vec3<T>)

Converts this quaternion into a scalar-and-vector pair by destructuring.

Not to be confused with into_angle_axis().

source

pub fn zero() -> Quaternion<T>
where T: Zero,

Creates a new quaternion with all elements set to zero.

Be careful: since it has a magnitude equal to zero, it is not valid to use for most operations.

source

pub fn identity() -> Quaternion<T>
where T: Zero + One,

Creates the identity quaternion.

use std::f32::consts::PI;

let id = Quaternion::<f32>::identity();
assert_eq!(id, Default::default());
assert_relative_eq!(id, id.conjugate());
assert_relative_eq!(id, id.inverse());

let q = Quaternion::rotation_y(PI);
assert_relative_eq!(id * q, q);
assert_relative_eq!(q * id, q);
source

pub fn conjugate(self) -> Quaternion<T>
where T: Neg<Output = T>,

Gets this quaternion’s conjugate (copy with negated vector part).

On normalized quaternions, the conjugate also happens to be the inverse.

use std::f32::consts::PI;

let p = Quaternion::rotation_x(PI);
let q = Quaternion::rotation_z(PI);
assert_relative_eq!((p*q).conjugate(), q.conjugate() * p.conjugate());

// Rotation quaternions are normalized, so their conjugate is also their inverse.
assert_relative_eq!(q.conjugate(), q.inverse());
source

pub fn inverse(self) -> Quaternion<T>
where T: Neg<Output = T> + Copy + Add<Output = T> + Mul<Output = T> + Div<Output = T>,

Gets this quaternion’s inverse, i.e the one that reverses its effect.

On normalized quaternions, the inverse happens to be the conjugate.

use std::f32::consts::PI;

let rot = Quaternion::rotation_y(PI);
let inv = rot.inverse();
assert_relative_eq!(rot*inv, Quaternion::identity());
assert_relative_eq!(inv*rot, Quaternion::identity());

let p = Quaternion::rotation_x(PI);
let q = Quaternion::rotation_z(PI);
assert_relative_eq!((p*q).inverse(), q.inverse() * p.inverse());
source

pub fn dot(self, q: Quaternion<T>) -> T
where T: Copy + Add<Output = T> + Mul<Output = T>,

Gets the dot product between two quaternions.

source

pub fn normalized(self) -> Quaternion<T>
where T: Real<Output = T> + Add,

Gets a normalized copy of this quaternion.

source

pub fn magnitude_squared(self) -> T
where T: Real<Output = T> + Add,

Gets this quaternion’s magnitude, squared.

source

pub fn magnitude(self) -> T
where T: Real<Output = T> + Add,

Gets this quaternion’s magnitude.

source

pub fn rotation_from_to_3d<V>(from: V, to: V) -> Quaternion<T>
where V: Into<Vec3<T>>, T: Real<Output = T> + Add,

Creates a quaternion that would rotate a from direction to to.


let (from, to) = (Vec4::<f32>::unit_x(), Vec4::<f32>::unit_y());
let q = Quaternion::<f32>::rotation_from_to_3d(from, to);
assert_relative_eq!(q * from, to);
assert_relative_eq!(q * Vec4::unit_y(), -Vec4::unit_x());

let (from, to) = (Vec4::<f32>::unit_x(), -Vec4::<f32>::unit_x());
let q = Quaternion::<f32>::rotation_from_to_3d(from, to);
assert_relative_eq!(q * from, to);
source

pub fn rotation_3d<V>(angle_radians: T, axis: V) -> Quaternion<T>
where V: Into<Vec3<T>>, T: Real<Output = T> + Add,

Creates a quaternion from an angle and axis. The axis is not required to be normalized.

source

pub fn rotation_x(angle_radians: T) -> Quaternion<T>
where T: Real<Output = T> + Add,

Creates a quaternion from an angle for a rotation around the X axis.

source

pub fn rotation_y(angle_radians: T) -> Quaternion<T>
where T: Real<Output = T> + Add,

Creates a quaternion from an angle for a rotation around the Y axis.

source

pub fn rotation_z(angle_radians: T) -> Quaternion<T>
where T: Real<Output = T> + Add,

Creates a quaternion from an angle for a rotation around the Y axis.

source

pub fn rotated_3d<V>(self, angle_radians: T, axis: V) -> Quaternion<T>
where V: Into<Vec3<T>>, T: Real<Output = T> + Add,

Returns this quaternion rotated around the given axis with given angle. The axis is not required to be normalized.

source

pub fn rotated_x(self, angle_radians: T) -> Quaternion<T>
where T: Real<Output = T> + Add,

Returns this quaternion rotated around the X axis with given angle.

source

pub fn rotated_y(self, angle_radians: T) -> Quaternion<T>
where T: Real<Output = T> + Add,

Returns this quaternion rotated around the Y axis with given angle.

source

pub fn rotated_z(self, angle_radians: T) -> Quaternion<T>
where T: Real<Output = T> + Add,

Returns this quaternion rotated around the Z axis with given angle.

source

pub fn rotate_3d<V>(&mut self, angle_radians: T, axis: V)
where V: Into<Vec3<T>>, T: Real<Output = T> + Add,

Rotates this quaternion around the given axis with given angle. The axis is not required to be normalized.

source

pub fn rotate_x(&mut self, angle_radians: T)
where T: Real<Output = T> + Add,

Rotates this quaternion around the X axis with given angle.

source

pub fn rotate_y(&mut self, angle_radians: T)
where T: Real<Output = T> + Add,

Rotates this quaternion around the Y axis with given angle.

source

pub fn rotate_z(&mut self, angle_radians: T)
where T: Real<Output = T> + Add,

Rotates this quaternion around the Z axis with given angle.

source

pub fn into_angle_axis(self) -> (T, Vec3<T>)
where T: Real,

Convert this quaternion to angle-axis representation, assuming the quaternion is normalized.

use std::f32::consts::PI;

let q = Quaternion::rotation_x(PI/2.);
let (angle, axis) = q.into_angle_axis();
assert_relative_eq!(angle, PI/2.);
assert_relative_eq!(axis, Vec3::unit_x());

let angle = PI*4./5.;
let axis = Vec3::new(1_f32, 2., 3.);
let q = Quaternion::rotation_3d(angle, axis);
let (a, v) = q.into_angle_axis();
assert_relative_eq!(a, angle);
assert_relative_eq!(v, axis.normalized());
source

pub fn into_vec4(self) -> Vec4<T>

Converts this quaternion to a Vec4 by destructuring.

source

pub fn from_vec4(v: Vec4<T>) -> Quaternion<T>

Creates a quaternion from a Vec4 by destructuring. You are responsible for ensuring that the resulting quaternion is normalized.

source

pub fn into_vec3(self) -> Vec3<T>

Converts this quaternion to a Vec3 by destructuring, dropping the w element.

source§

impl<T> Quaternion<T>
where T: Mul<Output = T> + Sub<Output = T> + Copy + MulAdd<Output = T> + One,

source

pub fn lerp_precise_unnormalized( from: Quaternion<T>, to: Quaternion<T>, factor: T, ) -> Quaternion<T>
where T: Clamp + Zero,

Performs linear interpolation without normalizing the result, using an implementation that supposedly yields a more precise result.

This is probably not what you’re looking for. For an implementation that normalizes the result (which is more commonly wanted), see the Lerp implementation.

source

pub fn lerp_unclamped_precise_unnormalized( from: Quaternion<T>, to: Quaternion<T>, factor: T, ) -> Quaternion<T>

Performs linear interpolation without normalizing the result and without implicitly constraining factor to be between 0 and 1, using an implementation that supposedly yields a more precise result.

This is probably not what you’re looking for. For an implementation that normalizes the result (which is more commonly wanted), see the Lerp implementation.

source§

impl<T> Quaternion<T>
where T: Sub<Output = T> + MulAdd<Output = T> + Copy,

source

pub fn lerp_unnormalized( from: Quaternion<T>, to: Quaternion<T>, factor: T, ) -> Quaternion<T>
where T: Clamp + Zero + One,

Performs linear interpolation without normalizing the result.

This is probably not what you’re looking for. For an implementation that normalizes the result (which is more commonly wanted), see the Lerp implementation.

source

pub fn lerp_unclamped_unnormalized( from: Quaternion<T>, to: Quaternion<T>, factor: T, ) -> Quaternion<T>

Performs linear interpolation without normalizing the result and without implicitly constraining factor to be between 0 and 1.

This is probably not what you’re looking for. For an implementation that normalizes the result (which is more commonly wanted), see the Lerp implementation.

source§

impl<T> Quaternion<T>
where T: Add<Output = T> + Lerp<T, Output = T> + Real,

source

pub fn slerp_unclamped( from: Quaternion<T>, to: Quaternion<T>, factor: T, ) -> Quaternion<T>

Performs spherical linear interpolation without implictly constraining factor to be between 0 and 1.

use std::f32::consts::PI;

let from = Quaternion::rotation_z(0_f32);
let to = Quaternion::rotation_z(PI*9./10.);

let angles = 32;
for i in 0..angles {
    let factor = (i as f32) / (angles as f32);
    let expected = Quaternion::rotation_z(factor * PI*9./10.);
    let slerp = Quaternion::slerp(from, to, factor);
    assert_relative_eq!(slerp, expected);
}
source

pub fn slerp(from: Quaternion<T>, to: Quaternion<T>, factor: T) -> Quaternion<T>
where T: Clamp,

Perform spherical linear interpolation, constraining factor to be between 0 and 1.

Trait Implementations§

source§

impl<T> AbsDiffEq for Quaternion<T>
where T: AbsDiffEq, <T as AbsDiffEq>::Epsilon: Copy,

§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
source§

fn default_epsilon() -> <T as AbsDiffEq>::Epsilon

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

fn abs_diff_eq( &self, other: &Quaternion<T>, epsilon: <Quaternion<T> as AbsDiffEq>::Epsilon, ) -> bool

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

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

The inverse of [AbsDiffEq::abs_diff_eq].
source§

impl<T> Add for Quaternion<T>
where T: Add<Output = T>,

§

type Output = Quaternion<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Quaternion<T>) -> <Quaternion<T> as Add>::Output

Performs the + operation. Read more
source§

impl<T> Clone for Quaternion<T>
where T: Clone,

source§

fn clone(&self) -> Quaternion<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 for Quaternion<T>
where T: Debug,

source§

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

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

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

The default value for a quaternion is the identity.

assert_eq!(Quaternion::<f32>::identity(), Quaternion::default());
source§

fn default() -> Quaternion<T>

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

impl<'de, T> Deserialize<'de> for Quaternion<T>
where T: Deserialize<'de>,

source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Quaternion<T>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl<T> Div<T> for Quaternion<T>
where T: Copy + Div<Output = T>,

§

type Output = Quaternion<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> <Quaternion<T> as Div<T>>::Output

Performs the / operation. Read more
§

impl From<Ori> for Quaternion<f32>

§

fn from(_: Ori) -> Quaternion<f32>

Converts to this type from the input type.
source§

impl<T> From<Quaternion<T>> for Mat4<T>
where T: One<Output = T> + Mul + Add<Output = T> + Copy + Sub<Output = T> + Zero,

Rotation matrices can be obtained from quaternions. This implementation only works properly if the quaternion is normalized.

use std::f32::consts::PI;

let angles = 32;
for i in 0..angles {
    let theta = PI * 2. * (i as f32) / (angles as f32);

    assert_relative_eq!(Mat4::rotation_x(theta), Mat4::from(Quaternion::rotation_x(theta)), epsilon = 0.000001);
    assert_relative_eq!(Mat4::rotation_y(theta), Mat4::from(Quaternion::rotation_y(theta)), epsilon = 0.000001);
    assert_relative_eq!(Mat4::rotation_z(theta), Mat4::from(Quaternion::rotation_z(theta)), epsilon = 0.000001);

    assert_relative_eq!(Mat4::rotation_x(theta), Mat4::rotation_3d(theta, Vec4::unit_x()));
    assert_relative_eq!(Mat4::rotation_y(theta), Mat4::rotation_3d(theta, Vec4::unit_y()));
    assert_relative_eq!(Mat4::rotation_z(theta), Mat4::rotation_3d(theta, Vec4::unit_z()));

    // See what rotating unit vectors do for most angles between 0 and 2*PI.
    // It's helpful to picture this as a right-handed coordinate system.

    let v = Vec4::unit_y();
    let m = Mat4::rotation_x(theta);
    assert_relative_eq!(m * v, Vec4::new(0., theta.cos(), theta.sin(), 0.));

    let v = Vec4::unit_z();
    let m = Mat4::rotation_y(theta);
    assert_relative_eq!(m * v, Vec4::new(theta.sin(), 0., theta.cos(), 0.));

    let v = Vec4::unit_x();
    let m = Mat4::rotation_z(theta);
    assert_relative_eq!(m * v, Vec4::new(theta.cos(), theta.sin(), 0., 0.));
}
source§

fn from(q: Quaternion<T>) -> Mat4<T>

Converts to this type from the input type.
source§

impl<T> From<Quaternion<T>> for Quaternion<T>

source§

fn from(q: Quaternion<T>) -> Quaternion<T>

Converts to this type from the input type.
source§

impl<T> From<Quaternion<T>> for Vec3<T>

A Vec3 can be created directly from a quaternion’s x, y and z elements.

source§

fn from(v: Quaternion<T>) -> Vec3<T>

Converts to this type from the input type.
source§

impl<T> From<Quaternion<T>> for Vec3<T>

A Vec3 can be created directly from a quaternion’s x, y and z elements.

source§

fn from(v: Quaternion<T>) -> Vec3<T>

Converts to this type from the input type.
source§

impl<T> From<Quaternion<T>> for Vec4<T>

A Vec4 can be created directly from a quaternion’s x, y, z and w elements.

source§

fn from(v: Quaternion<T>) -> Vec4<T>

Converts to this type from the input type.
source§

impl<T> From<Vec4<T>> for Quaternion<T>

A quaternion can be created directly from a Vec4’s x, y, z and w elements. You are responsible for ensuring that the resulting quaternion is normalized.

source§

fn from(v: Vec4<T>) -> Quaternion<T>

Converts to this type from the input type.
source§

impl<T> From<Vec4<T>> for Quaternion<T>

A quaternion can be created directly from a Vec4’s x, y, z and w elements. You are responsible for ensuring that the resulting quaternion is normalized.

source§

fn from(v: Vec4<T>) -> Quaternion<T>

Converts to this type from the input type.
source§

impl<T> Hash for Quaternion<T>
where T: Hash,

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

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> Into<Quaternion<T>> for Quaternion<T>

source§

fn into(self) -> Quaternion<T>

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

impl<'a, T, Factor> Lerp<Factor> for &'a Quaternion<T>
where T: Lerp<Factor, Output = T> + Add<Output = T> + Real, Factor: Copy,

The Lerp implementation for quaternion is the “Normalized LERP”.

§

type Output = Quaternion<T>

The resulting type after performing the LERP operation.
source§

fn lerp_unclamped_precise( from: &'a Quaternion<T>, to: &'a Quaternion<T>, factor: Factor, ) -> Quaternion<T>

Returns the linear interpolation of from to to with factor unconstrained, using a possibly slower but more precise operation. Read more
source§

fn lerp_unclamped( from: &'a Quaternion<T>, to: &'a Quaternion<T>, factor: Factor, ) -> Quaternion<T>

Returns the linear interpolation of from to to with factor unconstrained, using the supposedly fastest but less precise implementation. Read more
source§

fn lerp_unclamped_inclusive_range( range: RangeInclusive<Self>, factor: Factor, ) -> Self::Output

Version of lerp_unclamped() that used a single RangeInclusive parameter instead of two values.
source§

fn lerp_unclamped_precise_inclusive_range( range: RangeInclusive<Self>, factor: Factor, ) -> Self::Output

Version of lerp_unclamped_precise() that used a single RangeInclusive parameter instead of two values.
source§

impl<T, Factor> Lerp<Factor> for Quaternion<T>
where T: Lerp<Factor, Output = T> + Add<Output = T> + Real, Factor: Copy,

The Lerp implementation for quaternion is the “Normalized LERP”.

§

type Output = Quaternion<T>

The resulting type after performing the LERP operation.
source§

fn lerp_unclamped_precise( from: Quaternion<T>, to: Quaternion<T>, factor: Factor, ) -> Quaternion<T>

Returns the linear interpolation of from to to with factor unconstrained, using a possibly slower but more precise operation. Read more
source§

fn lerp_unclamped( from: Quaternion<T>, to: Quaternion<T>, factor: Factor, ) -> Quaternion<T>

Returns the linear interpolation of from to to with factor unconstrained, using the supposedly fastest but less precise implementation. Read more
source§

fn lerp_unclamped_inclusive_range( range: RangeInclusive<Self>, factor: Factor, ) -> Self::Output

Version of lerp_unclamped() that used a single RangeInclusive parameter instead of two values.
source§

fn lerp_unclamped_precise_inclusive_range( range: RangeInclusive<Self>, factor: Factor, ) -> Self::Output

Version of lerp_unclamped_precise() that used a single RangeInclusive parameter instead of two values.
source§

impl<T> Mul<T> for Quaternion<T>
where T: Mul<Output = T> + Copy,

§

type Output = Quaternion<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> <Quaternion<T> as Mul<T>>::Output

Performs the * operation. Read more
source§

impl<T> Mul<Vec3<T>> for Quaternion<T>
where T: Real<Output = T> + Add,

3D vectors can be rotated by being premultiplied by a quaternion, assuming the quaternion is normalized.

§

type Output = Vec3<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Vec3<T>) -> <Quaternion<T> as Mul<Vec3<T>>>::Output

Performs the * operation. Read more
source§

impl<T> Mul<Vec3<T>> for Quaternion<T>
where T: Real<Output = T> + Add,

3D vectors can be rotated by being premultiplied by a quaternion, assuming the quaternion is normalized.

§

type Output = Vec3<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Vec3<T>) -> <Quaternion<T> as Mul<Vec3<T>>>::Output

Performs the * operation. Read more
source§

impl<T> Mul<Vec4<T>> for Quaternion<T>
where T: Real<Output = T> + Add,

3D vectors can be rotated by being premultiplied by a quaternion, assuming the quaternion is normalized. On Vec4s, the w element is preserved, so you can safely rotate points and directions.

use std::f32::consts::PI;

let v = Vec4::unit_x();

let q = Quaternion::<f32>::identity();
assert_relative_eq!(q * v, v);

let q = Quaternion::rotation_z(PI);
assert_relative_eq!(q * v, -v);

let q = Quaternion::rotation_z(PI * 0.5);
assert_relative_eq!(q * v, Vec4::unit_y());

let q = Quaternion::rotation_z(PI * 1.5);
assert_relative_eq!(q * v, -Vec4::unit_y());

let angles = 32;
for i in 0..angles {
    let theta = PI * 2. * (i as f32) / (angles as f32);

    // See what rotating unit vectors do for most angles between 0 and 2*PI.
    // It's helpful to picture this as a right-handed coordinate system.

    let v = Vec4::unit_y();
    let q = Quaternion::rotation_x(theta);
    assert_relative_eq!(q * v, Vec4::new(0., theta.cos(), theta.sin(), 0.));

    let v = Vec4::unit_z();
    let q = Quaternion::rotation_y(theta);
    assert_relative_eq!(q * v, Vec4::new(theta.sin(), 0., theta.cos(), 0.));

    let v = Vec4::unit_x();
    let q = Quaternion::rotation_z(theta);
    assert_relative_eq!(q * v, Vec4::new(theta.cos(), theta.sin(), 0., 0.));
}
§

type Output = Vec4<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Vec4<T>) -> <Quaternion<T> as Mul<Vec4<T>>>::Output

Performs the * operation. Read more
source§

impl<T> Mul<Vec4<T>> for Quaternion<T>
where T: Real<Output = T> + Add,

3D vectors can be rotated by being premultiplied by a quaternion, assuming the quaternion is normalized. On Vec4s, the w element is preserved, so you can safely rotate points and directions.

use std::f32::consts::PI;

let v = Vec4::unit_x();

let q = Quaternion::<f32>::identity();
assert_relative_eq!(q * v, v);

let q = Quaternion::rotation_z(PI);
assert_relative_eq!(q * v, -v);

let q = Quaternion::rotation_z(PI * 0.5);
assert_relative_eq!(q * v, Vec4::unit_y());

let q = Quaternion::rotation_z(PI * 1.5);
assert_relative_eq!(q * v, -Vec4::unit_y());

let angles = 32;
for i in 0..angles {
    let theta = PI * 2. * (i as f32) / (angles as f32);

    // See what rotating unit vectors do for most angles between 0 and 2*PI.
    // It's helpful to picture this as a right-handed coordinate system.

    let v = Vec4::unit_y();
    let q = Quaternion::rotation_x(theta);
    assert_relative_eq!(q * v, Vec4::new(0., theta.cos(), theta.sin(), 0.));

    let v = Vec4::unit_z();
    let q = Quaternion::rotation_y(theta);
    assert_relative_eq!(q * v, Vec4::new(theta.sin(), 0., theta.cos(), 0.));

    let v = Vec4::unit_x();
    let q = Quaternion::rotation_z(theta);
    assert_relative_eq!(q * v, Vec4::new(theta.cos(), theta.sin(), 0., 0.));
}
§

type Output = Vec4<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Vec4<T>) -> <Quaternion<T> as Mul<Vec4<T>>>::Output

Performs the * operation. Read more
source§

impl<T> Mul for Quaternion<T>
where T: Sub<Output = T> + Copy + Zero<Output = T> + Add + Mul<Output = T>,

The Mul implementation for quaternions is concatenation, a.k.a Grassman product.

use std::f32::consts::PI;

let v = Vec4::unit_x();
let p = Quaternion::rotation_y(PI/2.);
let q = Quaternion::rotation_z(PI/2.);
assert_relative_eq!((p*q)*v, p*(q*v));
assert_relative_eq!(p*q*v, Vec4::unit_y());
assert_relative_eq!(q*p*v, -Vec4::unit_z());
§

type Output = Quaternion<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Quaternion<T>) -> <Quaternion<T> as Mul>::Output

Performs the * operation. Read more
source§

impl<T> Neg for Quaternion<T>
where T: Neg<Output = T>,

§

type Output = Quaternion<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> <Quaternion<T> as Neg>::Output

Performs the unary - operation. Read more
source§

impl<T> PartialEq for Quaternion<T>
where T: PartialEq,

source§

fn eq(&self, other: &Quaternion<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> RelativeEq for Quaternion<T>
where T: RelativeEq, <T as AbsDiffEq>::Epsilon: Copy,

source§

fn default_max_relative() -> <T as AbsDiffEq>::Epsilon

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

fn relative_eq( &self, other: &Quaternion<T>, epsilon: <T as AbsDiffEq>::Epsilon, max_relative: <T as AbsDiffEq>::Epsilon, ) -> bool

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

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

The inverse of [RelativeEq::relative_eq].
source§

impl<T> Serialize for Quaternion<T>
where T: Serialize,

source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

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

impl<'a, T, Factor> Slerp<Factor> for &'a Quaternion<T>
where T: Lerp<T, Output = T> + Add<Output = T> + Real, Factor: Into<T>,

§

type Output = Quaternion<T>

The resulting type after performing the SLERP operation.
source§

fn slerp_unclamped( from: &'a Quaternion<T>, to: &'a Quaternion<T>, factor: Factor, ) -> Quaternion<T>

Performs spherical linear interpolation without implictly constraining factor to be between 0 and 1.
source§

impl<T, Factor> Slerp<Factor> for Quaternion<T>
where T: Lerp<T, Output = T> + Add<Output = T> + Real, Factor: Into<T>,

§

type Output = Quaternion<T>

The resulting type after performing the SLERP operation.
source§

fn slerp_unclamped( from: Quaternion<T>, to: Quaternion<T>, factor: Factor, ) -> Quaternion<T>

Performs spherical linear interpolation without implictly constraining factor to be between 0 and 1.
source§

impl<T> Sub for Quaternion<T>
where T: Sub<Output = T>,

§

type Output = Quaternion<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Quaternion<T>) -> <Quaternion<T> as Sub>::Output

Performs the - operation. Read more
source§

impl<T> UlpsEq for Quaternion<T>
where T: UlpsEq, <T as AbsDiffEq>::Epsilon: Copy,

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: &Quaternion<T>, epsilon: <T as AbsDiffEq>::Epsilon, max_ulps: u32, ) -> bool

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

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

The inverse of [UlpsEq::ulps_eq].
source§

impl<T> Copy for Quaternion<T>
where T: Copy,

source§

impl<T> Eq for Quaternion<T>
where T: Eq,

source§

impl<T> StructuralPartialEq for Quaternion<T>

Auto Trait Implementations§

§

impl<T> Freeze for Quaternion<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Quaternion<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
§

impl<T> CallHasher for T
where T: Hash,

§

fn get_hash<H>(&self, hasher: H) -> u64
where H: Hasher,

source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<C, M> ConvertSaveload<M> for C

§

type Data = C

(De)Serializable data representation for data type
§

type Error = Infallible

Error may occur during serialization or deserialization of component
§

fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
where F: FnMut(Entity) -> Option<M>,

Convert this data type into serializable form (Data) using entity to marker mapping function
§

fn convert_from<F>( data: <C as ConvertSaveload<M>>::Data, _: F, ) -> Result<C, <C as ConvertSaveload<M>>::Error>
where F: FnMut(M) -> Option<Entity>,

Convert this data from a deserializable form (Data) using entity to marker mapping function
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> GetSetFdFlags for T

§

fn get_fd_flags(&self) -> Result<FdFlags, Error>
where T: AsFilelike,

Query the “status” flags for the self file descriptor.
§

fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>
where T: AsFilelike,

Create a new SetFdFlags value for use with set_fd_flags. Read more
§

fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>
where T: AsFilelike,

Set the “status” flags for the self file descriptor. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Pointer = u32

§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<Context> SubContext<Context> for Context

§

fn sub_context(self) -> Context

source§

impl<T> ToOwned for T
where T: Clone,

§

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
§

impl<T> TryDefault for T
where T: Default,

§

fn try_default() -> Result<T, String>

Tries to create the default.
§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Event for T
where T: Send + Sync + 'static,

§

impl<T> Resource for T
where T: Any + Send + Sync,

§

impl<T> Storable for T
where T: Send + Sync + 'static,