Skip to main content

Crate cadcore_math

Crate cadcore_math 

Source
Expand description

§cadcore-math

Fundamental numeric primitives for the cadcore CAD kernel.

This crate has zero external dependencies — everything is built on std and const-generic arithmetic.

§Design rules

  • All lengths are in millimetres unless noted otherwise.
  • All angles are in radians unless noted otherwise.
  • Point3 and Vec3 are distinct types — the compiler will not let you confuse a location with a direction.
  • Every function is pure; no global mutable state.

§Types at a glance

TypeDescription
Point3A location in 3-D space
Vec3A free vector (direction + magnitude)
UnitVec3A Vec3 guaranteed to have length 1
Mat3Column-major 3×3 matrix (rotations, linear maps)
Frame3Right-handed orthonormal frame (origin + 3 axes)
Transform3Rigid-body transform: rotation + translation
IntervalClosed real interval [lo, hi]

§Quick example

use cadcore_math::{Point3, Vec3, UnitVec3, Frame3};

let origin = Point3::new(1.0, 2.0, 3.0);
let dir    = UnitVec3::try_from_vec(Vec3::new(0.0, 0.0, 1.0)).unwrap();
let frame  = Frame3::from_origin_z(origin, dir);

let world_pt = Point3::new(4.0, 5.0, 6.0);
let local_pt = frame.to_local_point(world_pt);
let back     = frame.to_world_point(local_pt);
assert!((world_pt - back).length() < 1e-10);

Structs§

Frame3
Right-handed orthonormal frame: origin + three unit axes.
Interval
A closed real interval [lo, hi].
Mat3
Column-major 3×3 matrix.
Point3
A location in 3-D space.
Transform3
A rigid (isometric) transformation in 3-D space.
UnitVec3
A Vec3 that is normalised to unit length at construction time.
Vec3
A free 3-D vector with f64 components.

Constants§

EPS
Machine epsilon for f64 comparisons.
PI
π
TAU

Functions§

approx_eq
Return true when two f64 values are within EPS of each other.
clamp
Clamp v into [lo, hi].
lerp
Linearly interpolate: (1-t)*a + t*b.