pub trait FloatVector<T: FloatScalar>: Vector<T> {
// Required methods
fn length(&self) -> T;
fn normalize(&self) -> Self;
fn distance(l: &Self, r: &Self) -> T;
// Provided methods
fn length_squared(&self) -> T { ... }
fn try_normalize(&self, epsilon: T) -> Option<Self> { ... }
fn normalize_or_zero(&self, epsilon: T) -> Self { ... }
fn normalize_with_inv_len(&self, inv_len: T) -> Self { ... }
fn try_normalize_with_inv_len(
&self,
len_sq: T,
inv_len: T,
epsilon: T,
) -> Option<Self> { ... }
}Expand description
Trait for vectors with floating-point components.
Extends the base Vector trait with operations that require
floating-point arithmetic, such as length calculation and normalization.
Required Methods§
Sourcefn length(&self) -> T
fn length(&self) -> T
Computes the Euclidean length (magnitude) of the vector.
For vector v:
||v|| = √(v₁² + v₂² + ... + vₙ²)Provided Methods§
Sourcefn length_squared(&self) -> T
fn length_squared(&self) -> T
Computes the squared length (avoids a square root).
||v||² = v · vSourcefn try_normalize(&self, epsilon: T) -> Option<Self>
fn try_normalize(&self, epsilon: T) -> Option<Self>
Returns a normalized vector or None when the length is too small.
Sourcefn normalize_or_zero(&self, epsilon: T) -> Self
fn normalize_or_zero(&self, epsilon: T) -> Self
Returns a normalized vector or the zero vector when too small.
Sourcefn normalize_with_inv_len(&self, inv_len: T) -> Self
fn normalize_with_inv_len(&self, inv_len: T) -> Self
Normalizes using a precomputed inverse length (e.g., from rsqrt).
Sourcefn try_normalize_with_inv_len(
&self,
len_sq: T,
inv_len: T,
epsilon: T,
) -> Option<Self>
fn try_normalize_with_inv_len( &self, len_sq: T, inv_len: T, epsilon: T, ) -> Option<Self>
Normalizes with precomputed length squared and inverse length.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".