#[repr(C)]pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
}Fields§
§x: f32§y: f32§z: f32Implementations§
Source§impl Vec3
impl Vec3
pub const ZERO: Self
pub const ONE: Self
pub const NEG_ONE: Self
pub const NAN: Self
pub const INFINITY: Self
pub const NEG_INFINITY: Self
pub const fn new(x: f32, y: f32, z: f32) -> Self
pub const fn splat(value: f32) -> Self
pub const fn from_array(values: [f32; 3]) -> Self
pub const fn to_array(self) -> [f32; 3]
pub fn from_slice(values: &[f32]) -> Self
pub fn write_to_slice(self, values: &mut [f32])
pub fn is_finite(self) -> bool
pub fn is_nan(self) -> bool
pub fn dot(self, rhs: Self) -> f32
pub fn length_squared(self) -> f32
pub fn length_recip(self) -> f32
pub fn distance(self, other: Self) -> f32
pub fn distance_squared(self, other: Self) -> f32
Sourcepub fn try_normalize(self) -> Option<Self>
pub fn try_normalize(self) -> Option<Self>
Normalizes every finite nonzero vector, including subnormal inputs.
Returns None for zero or any non-finite component. Wider
intermediates also support vectors whose length exceeds f32::MAX.
The unit vector’s components are rounded to f32.
use ferravex_math::Vec3 as Vector;
let tiny = Vector::X * f32::from_bits(1);
assert_eq!(tiny.try_normalize(), Some(Vector::X));
assert!(Vector::splat(f32::MAX).try_normalize().unwrap().is_normalized());
assert_eq!(Vector::ZERO.try_normalize(), None);Sourcepub fn try_normalize_with_min_length(self, min_length: f32) -> Option<Self>
pub fn try_normalize_with_min_length(self, min_length: f32) -> Option<Self>
Normalizes only when the length is strictly greater than min_length.
This lets callers reject near-zero directions using a threshold in
their own units. Returns None for a negative or non-finite threshold,
a non-finite vector, or a length at or below the threshold. A zero
threshold is equivalent to Self::try_normalize. Length comparisons
use wider intermediates, including for subnormal and huge vectors.
use ferravex_math::Vec3 as Vector;
let direction = Vector::X * 0.001;
assert_eq!(direction.try_normalize_with_min_length(0.01), None);
assert_eq!(direction.try_normalize_with_min_length(0.0001), Some(Vector::X));
assert_eq!(Vector::X.try_normalize_with_min_length(f32::NAN), None);pub fn normalize(self) -> Self
pub fn normalize_or_zero(self) -> Self
pub fn normalize_or(self, fallback: Self) -> Self
pub fn is_normalized(self) -> bool
pub fn min(self, rhs: Self) -> Self
pub fn max(self, rhs: Self) -> Self
pub fn min_element(self) -> f32
pub fn max_element(self) -> f32
pub fn element_sum(self) -> f32
pub fn element_product(self) -> f32
pub fn abs(self) -> Self
pub fn signum(self) -> Self
pub fn floor(self) -> Self
pub fn ceil(self) -> Self
pub fn round(self) -> Self
pub fn trunc(self) -> Self
pub fn fract(self) -> Self
pub fn recip(self) -> Self
pub fn sqrt(self) -> Self
pub fn powf(self, exponent: f32) -> Self
pub fn exp(self) -> Self
pub fn clamp(self, min: Self, max: Self) -> Self
pub fn clamp_length(self, min: f32, max: f32) -> Self
pub fn clamp_length_max(self, max: f32) -> Self
pub fn clamp_length_min(self, min: f32) -> Self
Sourcepub fn try_clamp_length(self, min: f32, max: f32) -> Option<Self>
pub fn try_clamp_length(self, min: f32, max: f32) -> Option<Self>
Tries to clamp a finite vector’s length to the inclusive range [min, max].
Returns None if a component or bound is non-finite, if the bounds
do not satisfy 0 <= min <= max, or if a zero vector would need to
grow to a positive minimum (it has no direction). Invalid inputs do
not panic. A vector already in range is returned bit-for-bit unchanged.
Length comparisons and scaling use f64 intermediates to avoid
overflow and underflow for finite f32 inputs. Successful results
have finite components. Rescaled components are rounded to f32, so
the resulting length can fall slightly outside the requested range.
At subnormal bounds, relative error can be large and components can
round to zero; length and direction are subject to that quantization.
use ferravex_math::Vec3 as Vector;
assert_eq!((Vector::X * 4.0).try_clamp_length(1.0, 2.0), Some(Vector::X * 2.0));
assert_eq!(Vector::ZERO.try_clamp_length(1.0, 2.0), None);
assert_eq!(Vector::X.try_clamp_length(2.0, 1.0), None);
assert_eq!(Vector::INFINITY.try_clamp_length(0.0, 2.0), None);Sourcepub fn try_clamp_length_max(self, max: f32) -> Option<Self>
pub fn try_clamp_length_max(self, max: f32) -> Option<Self>
Tries to limit a finite vector’s length to a finite, nonnegative max.
Equivalent to Self::try_clamp_length with a zero minimum, including
its rounding limits. Returns None for non-finite components or an
invalid bound. Zero vectors are valid; a zero bound maps any finite
nonzero vector to zero. Vectors within the limit are unchanged.
use ferravex_math::Vec3 as Vector;
let limited = Vector::splat(f32::MAX).try_clamp_length_max(1.0).unwrap();
assert!(limited.is_normalized());
assert_eq!(Vector::ZERO.try_clamp_length_max(1.0), Some(Vector::ZERO));
assert_eq!(Vector::X.try_clamp_length_max(-1.0), None);Sourcepub fn try_clamp_length_min(self, min: f32) -> Option<Self>
pub fn try_clamp_length_min(self, min: f32) -> Option<Self>
Tries to raise a finite vector’s length to a finite, nonnegative min.
Returns None for non-finite components, an invalid bound, or a zero
vector with a positive minimum. A vector already at least min long
is returned bit-for-bit unchanged, even if its length exceeds
f32::MAX. Scaling has the rounding limits of Self::try_clamp_length.
use ferravex_math::Vec3 as Vector;
let tiny = -Vector::X * f32::from_bits(1);
assert_eq!(tiny.try_clamp_length_min(2.0), Some(-Vector::X * 2.0));
assert_eq!(Vector::ZERO.try_clamp_length_min(2.0), None);
let huge = Vector::splat(f32::MAX);
assert_eq!(huge.try_clamp_length_min(1.0), Some(huge));pub fn lerp(self, rhs: Self, t: f32) -> Self
pub fn mul_add(self, multiplier: Self, add: Self) -> Self
pub fn abs_diff_eq(self, rhs: Self, tolerance: f32) -> bool
pub fn cmpeq(self, rhs: Self) -> BVec3
pub fn cmpne(self, rhs: Self) -> BVec3
pub fn cmplt(self, rhs: Self) -> BVec3
pub fn cmple(self, rhs: Self) -> BVec3
pub fn cmpgt(self, rhs: Self) -> BVec3
pub fn cmpge(self, rhs: Self) -> BVec3
pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self
pub fn project_onto(self, other: Self) -> Self
pub fn reject_from(self, other: Self) -> Self
pub fn project_onto_normalized(self, normal: Self) -> Self
pub fn reject_from_normalized(self, normal: Self) -> Self
Sourcepub fn reflect(self, normal: Self) -> Self
pub fn reflect(self, normal: Self) -> Self
Reflects an incident vector about a unit surface normal.
pub fn move_towards(self, rhs: Self, max_distance: f32) -> Self
Source§impl Vec3
impl Vec3
pub const X: Self
pub const Y: Self
pub const Z: Self
pub const NEG_X: Self
pub const NEG_Y: Self
pub const NEG_Z: Self
pub const AXES: [Self; 3]
pub const fn extend(self, w: f32) -> Vec4
pub const fn truncate(self) -> Vec2
pub fn cross(self, rhs: Self) -> Self
pub fn angle_between(self, rhs: Self) -> f32
pub fn any_orthogonal_vector(self) -> Self
pub fn any_orthonormal_vector(self) -> Self
pub const fn xy(self) -> Vec2
pub const fn xz(self) -> Vec2
pub const fn yz(self) -> Vec2
pub const fn yx(self) -> Vec2
pub const fn zx(self) -> Vec2
pub const fn zy(self) -> Vec2
pub const fn xyz(self) -> Self
pub const fn xzy(self) -> Self
pub const fn yxz(self) -> Self
pub const fn yzx(self) -> Self
pub const fn zxy(self) -> Self
pub const fn zyx(self) -> Self
Trait Implementations§
Source§impl AddAssign<f32> for Vec3
impl AddAssign<f32> for Vec3
Source§fn add_assign(&mut self, rhs: f32)
fn add_assign(&mut self, rhs: f32)
+= operation. Read moreSource§impl AddAssign for Vec3
impl AddAssign for Vec3
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl DivAssign<f32> for Vec3
impl DivAssign<f32> for Vec3
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl DivAssign for Vec3
impl DivAssign for Vec3
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl MulAssign<f32> for Vec3
impl MulAssign<f32> for Vec3
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl MulAssign for Vec3
impl MulAssign for Vec3
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl SubAssign<f32> for Vec3
impl SubAssign<f32> for Vec3
Source§fn sub_assign(&mut self, rhs: f32)
fn sub_assign(&mut self, rhs: f32)
-= operation. Read moreSource§impl SubAssign for Vec3
impl SubAssign for Vec3
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more