FloatVector

Trait FloatVector 

Source
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§

Source

fn length(&self) -> T

Computes the Euclidean length (magnitude) of the vector.

For vector v:

||v|| = √(v₁² + v₂² + ... + vₙ²)
Source

fn normalize(&self) -> Self

Returns a unit vector in the same direction.

For vector v:

v̂ = v / ||v||
§Note

Returns NaN or Inf components if the vector has zero length.

Source

fn distance(l: &Self, r: &Self) -> T

Computes the Euclidean distance between two vectors.

For vectors v and w:

d(v, w) = ||v - w||

Provided Methods§

Source

fn length_squared(&self) -> T

Computes the squared length (avoids a square root).

||v||² = v · v
Source

fn try_normalize(&self, epsilon: T) -> Option<Self>

Returns a normalized vector or None when the length is too small.

Source

fn normalize_or_zero(&self, epsilon: T) -> Self

Returns a normalized vector or the zero vector when too small.

Source

fn normalize_with_inv_len(&self, inv_len: T) -> Self

Normalizes using a precomputed inverse length (e.g., from rsqrt).

Source

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", so this trait is not object safe.

Implementors§