Struct num_quaternion::Quaternion

source ·
pub struct Quaternion<T> {
    pub a: T,
    pub b: T,
    pub c: T,
    pub d: T,
}
Expand description

Quaternions.

Fields§

§a: T

Real part of the quaternion.

§b: T

The coefficient of i.

§c: T

The coefficient of j.

§d: T

The coefficient of k.

Implementations§

source§

impl<T> Quaternion<T>

source

pub const fn new(a: T, b: T, c: T, d: T) -> Self

Create a new quaternion.

source§

impl<T> Quaternion<T>
where T: ConstZero,

source

pub const ZERO: Self = _

A constant zero Quaternion.

source§

impl<T> Quaternion<T>
where T: ConstZero + ConstOne,

source

pub const ONE: Self = _

A constant Quaternion of value 1.

source

pub const I: Self = _

A constant Quaternion of value i.

source

pub const J: Self = _

A constant Quaternion of value j.

source

pub const K: Self = _

A constant Quaternion of value k.

source§

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

source

pub fn i() -> Self

Returns the imaginary unit i.

See also Quaternion::I.

source

pub fn j() -> Self

Returns the imaginary unit j.

See also Quaternion::J.

source

pub fn k() -> Self

Returns the imaginary unit k.

See also Quaternion::K.

source§

impl<T> Quaternion<T>
where T: Clone + Mul<T, Output = T> + Add<T, Output = T>,

source

pub fn norm_sqr(&self) -> T

Returns the square of the norm (since T doesn’t necessarily have a sqrt function), i.e. a^2 + b^2 + c^2 + d^2.

source§

impl<T> Quaternion<T>
where T: Clone + Neg<Output = T>,

source

pub fn conj(&self) -> Self

Returns the conjugate quaternion. i.e. the imaginary part is negated.

source§

impl<T> Quaternion<T>
where for<'a> &'a Self: Inv<Output = Quaternion<T>>,

source

pub fn inv(&self) -> Self

Returns 1/self

source§

impl<T> Quaternion<T>
where T: Float,

source

pub fn norm(self) -> T

Calculate |self|

source§

impl<T> Quaternion<T>
where T: Num + Clone,

source

pub fn powu(&self, exp: u32) -> Self

Raises self to an unsigned integer power.

source§

impl<T> Quaternion<T>
where T: Clone + Num + Neg<Output = T>,

source

pub fn powi(&self, exp: i32) -> Self

Raises self to a signed integer power.

Trait Implementations§

source§

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

§

type Output = Quaternion<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

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

§

type Output = Quaternion<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T, S> AddAssign<S> for Quaternion<T>
where Self: Add<S, Output = Self> + Clone,

source§

fn add_assign(&mut self, other: S)

Performs the += operation. Read more
source§

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

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> ConstOne for Quaternion<T>
where T: ConstZero + ConstOne + Num + Clone,

source§

const ONE: Self = Self::ONE

The multiplicative identity element of Self, 1.
source§

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

source§

const ZERO: Self = Self::ZERO

The additive identity element of Self, 0.
source§

impl<T: Debug> Debug for Quaternion<T>

source§

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

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

impl<T: Default> Default for Quaternion<T>

source§

fn default() -> Quaternion<T>

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

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

§

type Output = Quaternion<T>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T> Div for Quaternion<T>
where T: Num + Clone + Neg<Output = T>,

§

type Output = Quaternion<T>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T, S> DivAssign<S> for Quaternion<T>
where Self: Div<S, Output = Self> + Clone,

source§

fn div_assign(&mut self, other: S)

Performs the /= operation. Read more
source§

impl<'a, T> From<&'a T> for Quaternion<T>
where T: Clone + Zero,

source§

fn from(a: &T) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Quaternion<T>
where T: Zero,

source§

fn from(a: T) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> Hash for Quaternion<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> Inv for &Quaternion<T>
where T: Clone + Neg<Output = T> + Num,

§

type Output = Quaternion<T>

The result after applying the operator.
source§

fn inv(self) -> Self::Output

Returns the multiplicative inverse of self. Read more
source§

impl<T> Inv for Quaternion<T>
where for<'a> &'a Self: Inv<Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The result after applying the operator.
source§

fn inv(self) -> Self::Output

Returns the multiplicative inverse of self. Read more
source§

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

§

type Output = Quaternion<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

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

§

type Output = Quaternion<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T, S> MulAssign<S> for Quaternion<T>
where Self: Mul<S, Output = Self> + Clone,

source§

fn mul_assign(&mut self, other: S)

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) -> Self::Output

Performs the unary - operation. Read more
source§

impl<T> One for Quaternion<T>
where T: Num + Clone,

source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
source§

fn is_one(&self) -> bool

Returns true if self is equal to the multiplicative identity. Read more
source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
source§

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

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> Sub<T> for Quaternion<T>
where T: Sub<T, Output = T>,

§

type Output = Quaternion<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

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

§

type Output = Quaternion<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T, S> SubAssign<S> for Quaternion<T>
where Self: Sub<S, Output = Self> + Clone,

source§

fn sub_assign(&mut self, other: S)

Performs the -= operation. Read more
source§

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

source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

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

source§

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

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