Direction

Struct Direction 

Source
pub struct Direction { /* private fields */ }
Expand description

Direction is a vector quantity that represents a change in Position.

Position and Direction are two sides of the same coin. We can also think of any position as a change of position from the origin (Position::ZERO) to the target location.

Implementations§

Source§

impl Direction

§Methods

Source

pub fn new(x: Magnitude, y: Magnitude, z: Magnitude) -> Self

New Direction.

Source

pub fn to_array(&self) -> [Magnitude; 3]

Source

pub fn x(&self) -> Magnitude

Source

pub fn y(&self) -> Magnitude

Source

pub fn z(&self) -> Magnitude

Source

pub fn magnitude(&self) -> Magnitude

Returns the Magnitude of the current Direction.

$$ d = |\bm{a}| = \sqrt{x^2 + y^2 + z^2} $$

Source

pub fn magnitude_squared(&self) -> Magnitude

Returns the square of the Magnitude of the current Direction.

This is faster than getting the Magnitude since we avoid having to calculate the square root of the sum of the vector components. This can be useful if we just need to compare magnitudes.

$$ d^2 = |\bm{a}|^2 = x^2 + y^2 + z^2 $$

Source

pub fn normalize(&self) -> Direction

Returns the normalized vector, as a unit vector.

That is the Direction with a Magnitude of 1.

$$ \bm{n} = \widehat{\bm{a}} = \frac{1}{d}\thinspace\bm{a} = \frac{\bm{a}}{|\bm{a}|} $$

Source

pub fn cross(&self, other: Self) -> Self

Returns the cross product.

Also known as the vector product. It allows to point in a Direction orthogonal to both vectors.

$$ \bm{a}\times\bm{b} = \begin{bmatrix} a_x \cr a_y \cr a_z \end{bmatrix} \times \begin{bmatrix} b_x \cr b_y \cr b_z \end{bmatrix} = \begin{bmatrix} a_y b_z - a_z b_y \cr a_z b_x - a_x b_z \cr a_x b_y - a_y b_x \end{bmatrix} $$

Source

pub fn dot(&self, other: Self) -> Magnitude

Returns the dot product.

Also known as the scalar product. It allows us to calculate the Magnitude of one vector in the direction of another.

$$ \bm{a}\cdot\bm{b} = \begin{bmatrix} a_x \cr a_y \cr a_z \end{bmatrix} \cdot \begin{bmatrix} b_x \cr b_y \cr b_z \end{bmatrix} = a_x b_x + a_y b_y + a_z b_z $$

Source

pub fn vector(&self) -> DVec3

Returns the underlying vector type.

Source§

impl Direction

§Constants

Source

pub const ZERO: Self

All zeros.

Source

pub const ONE: Self

All ones.

Trait Implementations§

Source§

impl Add for Direction

Source§

type Output = Direction

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Direction

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl Clone for Direction

Source§

fn clone(&self) -> Direction

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 Debug for Direction

Source§

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

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

impl Default for Direction

Source§

fn default() -> Direction

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

impl Display for Direction

Source§

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

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

impl Div<f64> for Direction

Source§

type Output = Direction

The resulting type after applying the / operator.
Source§

fn div(self, other: Magnitude) -> Self

Performs the / operation. Read more
Source§

impl DivAssign<f64> for Direction

Source§

fn div_assign(&mut self, other: Magnitude)

Performs the /= operation. Read more
Source§

impl Mul<f64> for Direction

Source§

type Output = Direction

The resulting type after applying the * operator.
Source§

fn mul(self, other: Magnitude) -> Self

Performs the * operation. Read more
Source§

impl MulAssign<f64> for Direction

Source§

fn mul_assign(&mut self, other: Magnitude)

Performs the *= operation. Read more
Source§

impl PartialEq for Direction

Source§

fn eq(&self, other: &Direction) -> 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 Sub for Direction

Source§

type Output = Direction

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl SubAssign for Direction

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl Copy for Direction

Source§

impl StructuralPartialEq for Direction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Also for T

Source§

fn also_mut<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Applies a function which takes the parameter by exclusive reference, and then returns the (possibly) modified owned value. Read more
Source§

fn also_ref<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Applies a function which takes the parameter by shared reference, and then returns the (possibly) modified owned value. Read more
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, Res> Apply<Res> for T
where T: ?Sized,

Source§

fn apply<F>(self, f: F) -> Res
where F: FnOnce(Self) -> Res, Self: Sized,

Apply a function which takes the parameter by value.
Source§

fn apply_ref<F>(&self, f: F) -> Res
where F: FnOnce(&Self) -> Res,

Apply a function which takes the parameter by shared reference.
Source§

fn apply_mut<F>(&mut self, f: F) -> Res
where F: FnOnce(&mut Self) -> Res,

Apply a function which takes the parameter by exclusive reference.
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.