Skip to main content

Vec3

Struct Vec3 

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

A 3D vector of f32 components.

Fields§

§x: f32

X component.

§y: f32

Y component.

§z: f32

Z component.

Implementations§

Source§

impl Vec3

Source

pub const ZERO: Vec3

Zero vector.

Source

pub const ONE: Vec3

Vector whose components are all 1.0.

Source

pub const fn new(x: f32, y: f32, z: f32) -> Vec3

Creates a new vector.

Source

pub const fn as_array(&self) -> [f32; 3]

Returns the components as an array.

Source

pub const fn from_array(v: [f32; 3]) -> Vec3

Creates a vector from an array.

Source

pub fn dot(&self, rhs: &Vec3) -> f32

Dot product.

Source

pub fn norm_sq(&self) -> f32

Squared norm. Infallible, but may be inf or 0 for extreme components; use Self::norm in those cases.

Source

pub fn norm(&self) -> Result<f32, VecError>

Euclidean norm (robust for very large or very small values).

Returns VecError::NonFiniteValue if a component is NaN or infinite, or if the norm exceeds f32::MAX. The norm of the zero vector is Ok(0.0).

Source

pub fn normalize(&self) -> Result<Vec3, VecError>

Unit vector in the same direction.

Returns VecError::ZeroNorm for an exact zero vector and VecError::NonFiniteValue if a component is invalid.

Source

pub fn normalize_or_zero(&self) -> Vec3

Like Self::normalize, but returns Self::ZERO on failure.

Source

pub fn distance_sq(&self, rhs: &Vec3) -> f32

Squared distance (avoids the square root).

Source

pub fn distance(&self, rhs: &Vec3) -> Result<f32, VecError>

Distance euclidienne entre deux vecteurs.

Source

pub fn lerp(&self, rhs: &Vec3, t: f32) -> Vec3

Linear interpolation: self + t * (rhs - self).

Source

pub fn hadamard(&self, rhs: &Vec3) -> Vec3

Component-wise multiplication (Hadamard product).

Source

pub fn min(&self, rhs: &Vec3) -> Vec3

Component-wise minimum.

Source

pub fn max(&self, rhs: &Vec3) -> Vec3

Component-wise maximum.

Source

pub fn abs(&self) -> Vec3

Component-wise absolute value.

Source

pub fn checked_div(&self, s: f32) -> Result<Vec3, VecError>

Divides by a scalar without silently producing inf or NaN.

Returns VecError::DivisionByZero if s == 0.0 and VecError::NonFiniteValue if the result is not finite.

Source

pub fn project_onto(&self, rhs: &Vec3) -> Result<Vec3, VecError>

Projection de self sur rhs : (self·rhs / |rhs|²) * rhs.

Scale-independent for both inputs, avoiding overflow in intermediate dot products and squared norms. Returns VecError::ZeroNorm if rhs is zero, or VecError::NonFiniteValue for non-finite inputs or an unrepresentable result.

Source

pub fn reject_from(&self, rhs: &Vec3) -> Result<Vec3, VecError>

Component of self perpendicular to rhs: self - proj(self, rhs).

Source

pub fn reflect(&self, normal: &Vec3) -> Result<Vec3, VecError>

Reflects self across the plane or line with normal normal.

normal does not need to be a unit vector, but must be nonzero.

Source

pub fn is_finite(&self) -> bool

Returns true if all components are finite.

Source

pub fn is_approx_eq(&self, rhs: &Vec3, eps: f32) -> bool

Approximate equality: each component differs by at most eps.

Source§

impl Vec3

Source

pub const X: Vec3

Unit vector along X: [1, 0, 0].

Source

pub const Y: Vec3

Unit vector along Y: [0, 1, 0].

Source

pub const Z: Vec3

Unit vector along Z: [0, 0, 1].

Source

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

Cross product: self × rhs (right-hand rule).

Property: a × b = -(b × a).

Source

pub fn triple(&self, b: &Vec3, c: &Vec3) -> f32

Scalar triple product: self · (b × c) (signed parallelepiped volume).

Source

pub const fn truncate(&self) -> Vec2

Removes the z component.

Source

pub const fn extend(&self, w: f32) -> Vec4

Extends to Vec4 with the w component.

Trait Implementations§

Source§

impl Add for Vec3

Source§

type Output = Vec3

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vec3) -> Vec3

Performs the + operation. Read more
Source§

impl AddAssign for Vec3

Source§

fn add_assign(&mut self, rhs: Vec3)

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<(), Error>

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 Div<f32> for Vec3

Source§

type Output = Vec3

The resulting type after applying the / operator.
Source§

fn div(self, s: f32) -> Vec3

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Vec3

Source§

fn div_assign(&mut self, s: f32)

Performs the /= operation. Read more
Source§

impl From<[f32; 3]> for Vec3

Source§

fn from(v: [f32; 3]) -> Vec3

Converts to this type from the input type.
Source§

impl Mul<f32> for Vec3

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Vec3

Source§

fn mul_assign(&mut self, s: f32)

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) -> Vec3

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

Source§

impl Sub for Vec3

Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vec3) -> Vec3

Performs the - operation. Read more
Source§

impl SubAssign for Vec3

Source§

fn sub_assign(&mut self, rhs: Vec3)

Performs the -= operation. Read more
Source§

impl Sum for Vec3

Source§

fn sum<I>(iter: I) -> Vec3
where I: Iterator<Item = Vec3>,

Takes an iterator and generates Self from the elements by “summing up” the items.

Auto Trait Implementations§

§

impl Forget for Vec3

§

impl Freeze for Vec3

§

impl Move 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> 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, 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.