Dir

Struct Dir 

Source
pub struct Dir<T: Scalar, const N: usize, S: Space>(/* private fields */);
Expand description

A direction in N-dimensional space, represented by a unit vector.

The API of this type is fairly limited to ensure it always contains a unit vector.

Implementations§

Source§

impl<T: Scalar, const N: usize, S: Space> Dir<T, N, S>

Source

pub fn from_vec(v: Vector<T, N, S>) -> Self
where T: Float,

Returns the direction of the given vector. If v is the null vector, this function panics.

Source

pub fn from_unit_vec_unchecked(v: Vector<T, N, S>) -> Self

Returns the wrapped input vector, assuming it is normalized.

Source

pub fn to_unit_vec(&self) -> Vector<T, N, S>

Returns the unit vector that represents this direction.

Source

pub fn to_point(&self) -> Point<T, N, S>

Returns the point corresponding to this unit vector (a point on the unit sphere).

Source

pub fn in_space<Target: Space>(self) -> Dir<T, N, Target>

Reinterprets this direction as being in the space Target instead of S. Before calling this, make sure this operation makes semantic sense and don’t just use it to get rid of compiler errors.

Source

pub fn to_f32(self) -> Dir<f32, N, S>
where T: NumCast,

Casts self to using f32 as scalar.

Source

pub fn to_f64(self) -> Dir<f64, N, S>
where T: NumCast,

Casts self to using f64 as scalar.

Source

pub fn as_bytes(&self) -> &[u8]

Returns a byte slice of the unit vector representing this direction. Useful to pass to graphics APIs.

Source

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

Returns the components of this unit vector as arary.

Source§

impl<T: Scalar, S: Space> Dir<T, 2, S>

Source

pub fn new(x: T, y: T) -> Self
where T: Float,

Creates a Dir by normalizing the vector specified by the given coordinates.

Source

pub const fn new_unchecked(x: T, y: T) -> Self

Creates a Dir without checking that the given values form a unit vector.

Source

pub fn unit_x() -> Self

Returns (1, 0, 0).

Source

pub fn unit_y() -> Self

Returns (0, 1, 0).

Source

pub fn x(&self) -> T

Returns the x coordinate.

Source

pub fn y(&self) -> T

Returns the y coordinate.

Source§

impl<T: Scalar, S: Space> Dir<T, 3, S>

Source

pub fn new(x: T, y: T, z: T) -> Self
where T: Float,

Creates a Dir by normalizing the vector specified by the given coordinates.

Source

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

Creates a Dir without checking that the given values form a unit vector.

Source

pub fn unit_x() -> Self

Returns (1, 0, 0).

Source

pub fn unit_y() -> Self

Returns (0, 1, 0).

Source

pub fn unit_z() -> Self

Returns (0, 0, 1).

Source

pub fn x(&self) -> T

Returns the x coordinate.

Source

pub fn y(&self) -> T

Returns the y coordinate.

Source

pub fn z(&self) -> T

Returns the z coordinate.

Trait Implementations§

Source§

impl<T: Scalar, const N: usize, S: Space> Clone for Dir<T, N, S>

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: Scalar, const N: usize, S: Space> Div<T> for Dir<T, N, S>

Source§

type Output = Vector<T, N, S>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T: Float, S: Space> From<Dir<T, 3, S>> for SphericalDir<T, S>

Source§

fn from(src: Dir3<T, S>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar, const N: usize, S: Space> From<Dir<T, N, S>> for [T; N]

Source§

fn from(src: Dir<T, N, S>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float, const N: usize, S: Space> From<Dir<T, N, S>> for Vector<T, N, S>

Source§

fn from(src: Dir<T, N, S>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float, const N: usize, S: Space> From<Vector<T, N, S>> for Dir<T, N, S>

If the null vector is passed, this function panics.

Source§

fn from(v: Vector<T, N, S>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar + Hash, const N: usize, S: Space> Hash for Dir<T, N, S>

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, const N: usize, S: Space> Index<usize> for Dir<T, N, S>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: Scalar, const C: usize, const R: usize, Src: Space, Dst: Space> Mul<Dir<T, C, Src>> for &Matrix<T, C, R, Src, Dst>

Source§

type Output = Vector<T, R, Dst>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<T, C, Src>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<f32, N, S>> for f32

Source§

type Output = Vector<f32, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<f32, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<f64, N, S>> for f64

Source§

type Output = Vector<f64, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<f64, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<i128, N, S>> for i128

Source§

type Output = Vector<i128, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<i128, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<i16, N, S>> for i16

Source§

type Output = Vector<i16, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<i16, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<i32, N, S>> for i32

Source§

type Output = Vector<i32, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<i32, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<i64, N, S>> for i64

Source§

type Output = Vector<i64, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<i64, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<i8, N, S>> for i8

Source§

type Output = Vector<i8, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<i8, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<u128, N, S>> for u128

Source§

type Output = Vector<u128, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<u128, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<u16, N, S>> for u16

Source§

type Output = Vector<u16, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<u16, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<u32, N, S>> for u32

Source§

type Output = Vector<u32, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<u32, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<u64, N, S>> for u64

Source§

type Output = Vector<u64, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<u64, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, S: Space> Mul<Dir<u8, N, S>> for u8

Source§

type Output = Vector<u8, N, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dir<u8, N, S>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Scalar, const N: usize, S: Space> Mul<T> for Dir<T, N, S>

Source§

type Output = Vector<T, N, S>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Scalar + Neg, const N: usize, S: Space> Neg for Dir<T, N, S>
where <T as Neg>::Output: Scalar,

Source§

type Output = Dir<<T as Neg>::Output, N, S>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: Scalar, const N: usize, S: Space> PartialEq for Dir<T, N, S>

Source§

fn eq(&self, other: &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: Scalar + Zeroable, const N: usize, S: Space> Zeroable for Dir<T, N, S>

Source§

fn zeroed() -> Self

Source§

impl<T: Scalar, const N: usize, S: Space> Copy for Dir<T, N, S>

Source§

impl<T: Scalar + Pod, const N: usize, S: Space> Pod for Dir<T, N, S>

Auto Trait Implementations§

§

impl<T, const N: usize, S> Freeze for Dir<T, N, S>
where T: Freeze,

§

impl<T, const N: usize, S> RefUnwindSafe for Dir<T, N, S>

§

impl<T, const N: usize, S> Send for Dir<T, N, S>
where T: Send, S: Send,

§

impl<T, const N: usize, S> Sync for Dir<T, N, S>
where T: Sync, S: Sync,

§

impl<T, const N: usize, S> Unpin for Dir<T, N, S>
where T: Unpin, S: Unpin,

§

impl<T, const N: usize, S> UnwindSafe for Dir<T, N, S>
where T: UnwindSafe, S: 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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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> 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, 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> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,