| name | rendiation-algebra |
| description | Reference for the rendiation math library (math/algebra). Covers Vec2/Vec3/Vec4, Mat2/Mat3/Mat4, Quat, the Scalar trait (Float + FloatConst + ScalarConstEval), generic float-constant construction via scalar_transmute/eval, InnerProductSpace (length2/dot), VectorSpace, and SpaceEntity. Use when writing generic math code over T: Scalar, working with vectors/matrices, or needing to create float literals in generic contexts.
|
| metadata | {"version":"1.0","updated":"2026-05-18"} |
The math/algebra crate is the foundational math library. Import everything with:
use rendiation_algebra::*;
Scalar trait
Scalar is a trait alias that bundles all numeric capabilities needed for generic math code:
pub trait Scalar = Float
+ AsPrimitive<i64>
+ FloatConst
+ ScalarConstEval
+ Copy
+ std::fmt::Debug
+ AddAssign<Self> + SubAssign<Self> + DivAssign<Self> + MulAssign<Self>
+ Send + Sync + Default
+ 'static;
This means T: Scalar is only implemented for f32 and f64. It provides:
T::zero(), T::one() — from num_traits::Zero/One
T::abs(), T::sqrt() — from Float
- Arithmetic ops (
+, -, *, /, +=, -=, *=, /=) — from Float + *Assign traits
- Comparison (
<, >, ==) — from PartialOrd (via Float)
T::from(small_int) — from NumCast (e.g. T::from(3).expect(...))
Generic float constants via ScalarConstEval
ScalarConstEval provides compile-time float-to-generic conversion via f32 bit patterns:
pub trait ScalarConstEval: Sized {
fn eval<const N: u32>() -> Self;
fn half() -> Self;
fn two() -> Self;
fn three() -> Self;
}
impl<T: From<f32>> ScalarConstEval for T { ... }
The helper scalar_transmute converts a float literal to a u32 bit pattern for use in const generics:
pub const fn scalar_transmute(value: f32) -> u32 { value.to_bits() }
Usage pattern — to write 1e-7 in generic code:
let threshold: T = T::eval::<{ scalar_transmute(1e-7) }>();
Common constants: T::half() (0.5), T::two() (2.0), T::one(), T::zero().
Vector types
All generated by impl_vector! macro. Available: Vec2<T>, Vec3<T>, Vec4<T>.
Constructors:
let v = Vec3::new(x, y, z);
let v = Vec4::new(x, y, z, w);
Key traits (all require T: Scalar for full functionality):
Vector arithmetic works element-wise: a + b, a - b, a * scalar, a / scalar, scalar * a.
Matrix types
Mat2<T>, Mat3<T>, Mat4<T> — square matrices. Mat4::identity() for identity.
Quaternion
Quat<T> — quaternion for rotations.
f32/f64 conversion
Methods on every vector/matrix/quat type:
v.into_f64()
v.into_f32()
SpaceEntity
For types that can be transformed by matrices:
pub trait SpaceEntity<T: Scalar, const D: usize> {
type Matrix: SquareMatrixDimension<D>;
fn apply_matrix(&mut self, mat: Self::Matrix) -> &mut Self;
}
Key files