base_2 0.1.0

Exact fixed-point geometry. Float in, float out, zero drift inside.
Documentation
//! Exact transformations for `Point3` collections.
//! Rotation is applied via a precomputed matrix — single trig step, no double conversion.
//! Result snapped to nearest `Coord64`. Snap error ≤ 0.116pm.
//! All transforms applied fresh from original frozen points — error never accumulates.

use crate::api::Transform;
use crate::coord::Coord64;
use crate::point::Point3;

/// Apply a transform to a slice of frozen points, always from the original.
#[must_use]
pub fn apply_transform(points: &[Point3<i64>], t: &Transform) -> Vec<Point3<i64>> {
    let m = &t.rotation.0;

    points.iter().map(|p| {
        // scale from original frozen coords
        let x = p.x.to_f64() * t.scale_x;
        let y = p.y.to_f64() * t.scale_y;
        let z = p.z.to_f64() * t.scale_z;

        // apply rotation matrix
        let rx = m[0][0].mul_add(x, m[0][1].mul_add(y, m[0][2] * z));
        let ry = m[1][0].mul_add(x, m[1][1].mul_add(y, m[1][2] * z));
        let rz = m[2][0].mul_add(x, m[2][1].mul_add(y, m[2][2] * z));

        // translate and snap to nearest Coord64
        Point3 {
            x: Coord64::from_f64(rx + t.translate_x),
            y: Coord64::from_f64(ry + t.translate_y),
            z: Coord64::from_f64(rz + t.translate_z),
        }
    }).collect()
}