Skip to main content

Vec3

Struct Vec3 

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

Three-dimensional floating-point vector for 3D positions, directions, normals, and RGB radiance.

Implementations§

Source§

impl Vec3

Vector arithmetic, normalization, dot/cross products, and reflection helpers for Vec3.

Source

pub const fn zero() -> Self

Zero vector (0, 0, 0).

§Returns
  • Self - Zero vector.
Source

pub const fn splat(v: f32) -> Self

Uniform vector (v, v, v).

§Arguments
  • f32 - Scalar value replicated across all axes.
§Returns
  • Self - Splat vector.
Source

pub fn scale(self, s: f32) -> Self

Scales self by scalar s.

§Arguments
  • Self - Source vector.
  • f32 - Scalar multiplier.
§Returns
  • Self - Scaled vector.
Source

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

Computes the dot product self · rhs.

§Arguments
  • Self - Left vector.
  • Self - Right vector.
§Returns
  • f32 - Scalar dot product.
Source

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

Computes the 3D cross product self × rhs.

§Arguments
  • Self - Left vector.
  • Self - Right vector.
§Returns
  • Self - Orthogonal cross product vector.
Source

pub fn length_sq(self) -> f32

Computes squared Euclidean length.

§Arguments
  • Self - Source vector.
§Returns
  • f32 - Squared magnitude.
Source

pub fn length(self) -> f32

Computes Euclidean length.

§Arguments
  • Self - Source vector.
§Returns
  • f32 - Magnitude.
Source

pub fn normalize(self) -> Self

Returns a unit-length vector pointing along self, or (0, 1, 0) if degenerate.

§Arguments
  • Self - Source vector.
§Returns
  • Self - Normalized unit vector.
Source

pub fn lerp(self, other: Self, t: f32) -> Self

Linearly interpolates between self and other by t.

§Arguments
  • Self - Start vector.
  • Self - End vector.
  • f32 - Interpolation factor.
§Returns
  • Self - Interpolated vector.
Source

pub fn reflect(self, normal: Self) -> Self

Reflects incident vector self across unit surface normal normal.

§Arguments
  • Self - Incident vector.
  • Self - Unit surface normal.
§Returns
  • Self - Reflected direction vector.
Source

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

Returns component-wise minimum of self and rhs.

§Arguments
  • Self - Left vector.
  • Self - Right vector.
§Returns
  • Self - Component-wise minimum.
Source

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

Returns component-wise maximum of self and rhs.

§Arguments
  • Self - Left vector.
  • Self - Right vector.
§Returns
  • Self - Component-wise maximum.
Source

pub fn from_color(c: Color) -> Self

Converts an sRGB Color into linear RGB Vec3 radiance in [0.0, 1.0].

§Arguments
  • Color - Source RGBA color.
§Returns
  • Self - Normalized linear RGB vector.
Source

pub fn to_aces_rgba8(self) -> [u8; 4]

Applies ACES filmic tone mapping and converts linear radiance to RGBA8 [r, g, b, 255].

§Arguments
  • Self - Linear HDR RGB radiance.
§Returns
  • [u8; 4] - Tone-mapped RGBA8 pixel bytes.
Source

pub fn aces_rgba8_luma_4x( r: [f32; 4], g: [f32; 4], b: [f32; 4], ) -> ([[u8; 4]; 4], [u8; 4])

Vectorized 4-pixel ACES filmic tone mapper returning RGBA8 pixels and Rec.601 luma bytes.

§Arguments
  • [f32; 4] - Four linear HDR red channel values.
  • [f32; 4] - Four linear HDR green channel values.
  • [f32; 4] - Four linear HDR blue channel values.
§Returns
  • ([[u8; 4]; 4], [u8; 4]) - Tone-mapped RGBA8 pixels and corresponding Rec.601 luma values.
Source§

impl Vec3

Source

pub fn get_x(&self) -> f32

Source

pub fn get_mut_x(&mut self) -> &mut f32

Source

pub fn set_x(&mut self, val: f32) -> &mut Self

Source

pub fn get_y(&self) -> f32

Source

pub fn get_mut_y(&mut self) -> &mut f32

Source

pub fn set_y(&mut self, val: f32) -> &mut Self

Source

pub fn get_z(&self) -> f32

Source

pub fn get_mut_z(&mut self) -> &mut f32

Source

pub fn set_z(&mut self, val: f32) -> &mut Self

Source§

impl Vec3

Source

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

Trait Implementations§

Source§

impl Add for Vec3

Component-wise vector addition for Vec3.

Source§

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

Adds two vectors component-wise.

§Arguments
  • Self - Left vector.
  • Self - Right vector.
§Returns
  • Self - Component-wise sum.
Source§

type Output = Vec3

The resulting type after applying the + operator.
Source§

impl Clone for Vec3

Source§

fn clone(&self) -> Self

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() -> Self

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

impl Mul for Vec3

Component-wise Hadamard vector multiplication for Vec3.

Source§

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

Multiplies two vectors component-wise.

§Arguments
  • Self - Left vector.
  • Self - Right vector.
§Returns
  • Self - Component-wise product.
Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

impl PartialEq for Vec3

Source§

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

Component-wise vector subtraction for Vec3.

Source§

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

Subtracts rhs from self.

§Arguments
  • Self - Left vector.
  • Self - Right vector.
§Returns
  • Self - Component-wise difference.
Source§

type Output = Vec3

The resulting type after applying the - operator.

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