Skip to main content

Module math

Module math 

Source
Expand description

Basic linear algebra: 3-vectors, affine 4×4 matrices and bounding boxes.

  • Vec3 — points and directions (components indexed 0..3, see the axis convention).
  • Mat4 — affine transformations in homogeneous coordinates, acting on column vectors (p' = M·p); a * b applies b first.
  • BoundingBox — closed axis-aligned boxes, with an explicit empty value.
use csx::{BoundingBox, Mat4, Vec3};

let m = Mat4::translation(Vec3::new(1.0, 0.0, 0.0)) * Mat4::scaling(Vec3::new(2.0, 2.0, 2.0));
// Scale first, then translate.
assert_eq!(m.transform_point(Vec3::new(1.0, 1.0, 1.0)), Vec3::new(3.0, 2.0, 2.0));

let b = BoundingBox::from_points([Vec3::ZERO, Vec3::new(1.0, 2.0, 3.0)]);
assert_eq!(b.transformed(&m).max, Vec3::new(3.0, 4.0, 6.0));

Structs§

BoundingBox
An axis-aligned bounding box. An empty box has min > max on some axis (see BoundingBox::EMPTY); a box may be degenerate (zero extent) along any axis, e.g. for sheets. Containment tests are closed (boundary points are inside).
Mat4
A 4×4 matrix in row-major order, used for affine transformations of homogeneous coordinates (p' = M · [p, 1]). The translation lives in the last column. a * b is the matrix product, i.e. the transformation that applies b first and then a.
Vec3
A 3-component vector of f64, used for points and directions.