Skip to main content

UnitVec3

Struct UnitVec3 

Source
pub struct UnitVec3(/* private fields */);
Expand description

A Vec3 that is normalised to unit length at construction time.

Stored as a plain Vec3 internally — the invariant is only enforced at the construction boundary.

Implementations§

Source§

impl UnitVec3

Source

pub const X: Self

+X axis.

Source

pub const Y: Self

+Y axis.

Source

pub const Z: Self

+Z axis.

Source

pub fn try_from_vec(v: Vec3) -> Option<Self>

Construct from a Vec3, normalising it. Returns None for zero vectors.

Source

pub fn new_unchecked(v: Vec3) -> Self

Construct without checking — caller asserts |v| ≈ 1.

§Safety

Violating the unit-length invariant leads to incorrect geometric results, not unsound memory, so this is not unsafe in the Rust sense.

Source

pub fn as_vec(self) -> Vec3

Access the underlying Vec3.

Source

pub fn dot(self, rhs: Self) -> f64

Dot product with another unit vector.

Source

pub fn dot_vec(self, v: Vec3) -> f64

Dot product with a free Vec3.

Source

pub fn cross(self, rhs: Self) -> Vec3

Cross product — result is a plain Vec3 (may not be unit length).

Source

pub fn flip(self) -> Self

Return the opposite direction.

Source

pub fn angle_to(self, other: Self) -> f64

Angle between two unit vectors (radians, always in [0, π]).

Source

pub fn perp_basis(self) -> (Self, Self)

Build an orthonormal basis (self, u, v) where u and v span the plane perpendicular to self. u is arbitrary but consistent.

Trait Implementations§

Source§

impl Clone for UnitVec3

Source§

fn clone(&self) -> UnitVec3

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnitVec3

Source§

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

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

impl From<UnitVec3> for Vec3

Source§

fn from(u: UnitVec3) -> Vec3

Converts to this type from the input type.
Source§

impl Mul<UnitVec3> for f64

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

fn mul(self, u: UnitVec3) -> Vec3

Performs the * operation. Read more
Source§

impl Mul<f64> for UnitVec3

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

fn mul(self, s: f64) -> Vec3

Performs the * operation. Read more
Source§

impl Neg for UnitVec3

Source§

type Output = UnitVec3

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for UnitVec3

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Copy for UnitVec3

Source§

impl StructuralPartialEq for UnitVec3

Auto Trait Implementations§

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