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 / Input | Behavior |
|---|---|
Vec2::new / Vec3::new / Vec4::new | Builds 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
f32components. - Vec3
- A 3D vector of
f32components. - Vec4
- A 4D vector of
f32components.
Enums§
- VecError
- Errors returned by vector operations.
Functions§
- cross_
vec3 - Computes the cross product of two
Vec3values (a × b). - norm_
vec3 - Computes the Euclidean norm of a
Vec3. - normalize_
vec3 - Normalizes a
Vec3into a unit vector, or returnsErr(VecError::ZeroNorm)if zero.