Skip to main content

Module vector

Module vector 

Source
Expand description

2D, 3D, and 4D f32 vectors for no_std embedded systems, powered by embedded-vector.

Provides Vec2, Vec3, and Vec4 with operator overloads, dot/cross/triple products, projections/reflections, homogeneous perspective_divide, and numerically robust norm and normalize without heap allocation or std.

§Behavior & Notes

Operation / InputBehavior
Vec2::new / Vec3::new / Vec4::newBuilds 2D, 3D, or 4D f32 vectors (ZERO, ONE, Default)
norm()Euclidean norm (Result<f32, VecError>); Ok(0.0) for zero vector
normalize()Unit vector (Result<Self, VecError>); returns Err(VecError::ZeroNorm) on zero vector
normalize_or_zero()Returns unit vector or Self::ZERO without error
checked_div(s)Scalar division returning Err(VecError::DivisionByZero) or Err(VecError::NonFiniteValue)
perspective_divide()Converts homogeneous Vec4 to Vec3 (Err(VecError::DivisionByZero) if w == 0.0)
Extreme values (1e30 / 1e-30)norm, normalize, distance, and project_onto handle scaling robustly

Structs§

Vec2
A 2D vector of f32 components.
Vec3
A 3D vector of f32 components.
Vec4
A 4D vector of f32 components.

Enums§

VecError
Errors returned by vector operations.

Functions§

cross_vec3
Computes the cross product of two Vec3 values (a × b).
norm_vec3
Computes the Euclidean norm of a Vec3.
normalize_vec3
Normalizes a Vec3 into a unit vector, or returns Err(VecError::ZeroNorm) if zero.