Skip to main content

Crate embedded_vector

Crate embedded_vector 

Source
Expand description

§embedded-vector

2D, 3D, and 4D f32 vectors for no_std embedded systems.

No standard-library dependency, no unsafe, no allocation, and no panics. Uses embedded_f32_sqrt for square-root calculations.

§Quick start

use embedded_vector::{Vec3, Vec4};

let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(4.0, 5.0, 6.0);

assert_eq!(a + b, Vec3::new(5.0, 7.0, 9.0));
assert_eq!(a.dot(&b), 32.0);
assert_eq!(a.cross(&b), Vec3::new(-3.0, 6.0, -3.0));

let n = a.norm().unwrap();              // √14 ≈ 3.742
let u = a.normalize().unwrap();         // Unit vector
assert!((u.norm().unwrap() - 1.0).abs() < 1e-5);

// Homogeneous coordinates
let p = Vec4::from_vec3(a, 2.0);
assert_eq!(p.perspective_divide().unwrap(), Vec3::new(0.5, 1.0, 1.5));

§Numerical robustness

norm, normalize, and distance handle vectors with very large (1e30) or very small (1e-30) components: the calculation scales the values when x² + y² + … would overflow or underflow to zero.

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.