pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
}Expand description
A 3D vector of f32 components.
Fields§
§x: f32X component.
y: f32Y component.
z: f32Z component.
Implementations§
Source§impl Vec3
impl Vec3
Sourcepub const fn from_array(v: [f32; 3]) -> Self
pub const fn from_array(v: [f32; 3]) -> Self
Creates a vector from an array.
Sourcepub fn norm_sq(&self) -> f32
pub fn norm_sq(&self) -> f32
Squared norm. Infallible, but may be inf or 0 for extreme
components; use Self::norm in those cases.
Sourcepub fn norm(&self) -> Result<f32, VecError>
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).
Sourcepub fn normalize(&self) -> Result<Self, VecError>
pub fn normalize(&self) -> Result<Self, VecError>
Unit vector in the same direction.
Returns VecError::ZeroNorm for an exact zero vector and
VecError::NonFiniteValue if a component is invalid.
Sourcepub fn normalize_or_zero(&self) -> Self
pub fn normalize_or_zero(&self) -> Self
Like Self::normalize, but returns Self::ZERO on failure.
Sourcepub fn distance_sq(&self, rhs: &Self) -> f32
pub fn distance_sq(&self, rhs: &Self) -> f32
Squared distance (avoids the square root).
Sourcepub fn distance(&self, rhs: &Self) -> Result<f32, VecError>
pub fn distance(&self, rhs: &Self) -> Result<f32, VecError>
Distance euclidienne entre deux vecteurs.
Sourcepub fn checked_div(&self, s: f32) -> Result<Self, VecError>
pub fn checked_div(&self, s: f32) -> Result<Self, 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.
Sourcepub fn project_onto(&self, rhs: &Self) -> Result<Self, VecError>
pub fn project_onto(&self, rhs: &Self) -> Result<Self, 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.
Sourcepub fn reject_from(&self, rhs: &Self) -> Result<Self, VecError>
pub fn reject_from(&self, rhs: &Self) -> Result<Self, VecError>
Component of self perpendicular to rhs: self - proj(self, rhs).
Sourcepub fn reflect(&self, normal: &Self) -> Result<Self, VecError>
pub fn reflect(&self, normal: &Self) -> Result<Self, VecError>
Reflects self across the plane or line with normal normal.
normal does not need to be a unit vector, but must be nonzero.
Sourcepub fn is_approx_eq(&self, rhs: &Self, eps: f32) -> bool
pub fn is_approx_eq(&self, rhs: &Self, eps: f32) -> bool
Approximate equality: each component differs by at most eps.
Trait Implementations§
Source§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 moreimpl Copy for Vec3
Source§impl DivAssign<f32> for Vec3
impl DivAssign<f32> for Vec3
Source§fn div_assign(&mut self, s: f32)
fn div_assign(&mut self, s: f32)
/= operation. Read moreSource§impl MulAssign<f32> for Vec3
impl MulAssign<f32> for Vec3
Source§fn mul_assign(&mut self, s: f32)
fn mul_assign(&mut self, s: f32)
*= operation. Read more