Skip to main content

Vec3

Struct Vec3 

Source
pub struct Vec3 {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}
Expand description

A three-dimensional vector with double-precision components.

Fields§

§x: f64

The x component.

§y: f64

The y component.

§z: f64

The z component.

Implementations§

Source§

impl Vec3

Source

pub const ZERO: Self

The zero vector.

Source

pub const X: Self

The positive x-axis unit vector.

Source

pub const Y: Self

The positive y-axis unit vector.

Source

pub const Z: Self

The positive z-axis unit vector.

Source

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

Creates a vector from Cartesian components.

Source

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

Returns the dot product with rhs.

Source

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

Returns the right-handed cross product with rhs.

Source

pub fn length_squared(self) -> f64

Returns the squared Euclidean length.

Source

pub fn length(self) -> f64

Returns the Euclidean length.

Source

pub fn normalized(self) -> Option<Self>

Returns a unit vector in the same direction, or None if the vector is zero, too small to normalize reliably, or non-finite.

Source

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

Returns the Euclidean distance to rhs.

Source

pub fn is_finite(self) -> bool

Returns whether all components are finite.

Source

pub fn component(self, index: usize) -> f64

Returns the component at index 0, 1, or 2.

§Panics

Panics when index is greater than 2.

Source

pub fn canonicalized(self) -> Self

Chooses a deterministic sign by making the largest-magnitude component non-negative.

Source

pub fn orthonormal_basis(self) -> Option<(Self, Self)>

Builds two unit vectors perpendicular to this vector and each other.

Returns None when this vector cannot be normalized.

Trait Implementations§

Source§

impl Add for Vec3

Source§

type Output = Vec3

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Vec3

Source§

fn add_assign(&mut self, r: Self)

Performs the += operation. Read more
Source§

impl Clone for Vec3

Source§

fn clone(&self) -> Vec3

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 Copy for Vec3

Source§

impl Debug for Vec3

Source§

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

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

impl Default for Vec3

Source§

fn default() -> Vec3

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

impl<'de> Deserialize<'de> for Vec3

Source§

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

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

impl Div<f64> for Vec3

Source§

type Output = Vec3

The resulting type after applying the / operator.
Source§

fn div(self, s: f64) -> Self

Performs the / operation. Read more
Source§

impl Mul<f64> for Vec3

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for Vec3

Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Vec3

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Vec3

Source§

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

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

impl StructuralPartialEq for Vec3

Source§

impl Sub for Vec3

Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Vec3

Source§

fn sub_assign(&mut self, r: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl Freeze for Vec3

§

impl RefUnwindSafe for Vec3

§

impl Send for Vec3

§

impl Sync for Vec3

§

impl Unpin for Vec3

§

impl UnsafeUnpin for Vec3

§

impl UnwindSafe for Vec3

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.