Skip to main content

axiolid_core/
primitives.rs

1//! Coordinate, direction, transform, and analytic support types.
2
3use crate::Scalar;
4
5/// Double-precision two-dimensional vector.
6pub type Vec2 = glam::DVec2;
7/// Double-precision three-dimensional vector.
8pub type Vec3 = glam::DVec3;
9/// A semantic alias used when a value is a two-dimensional position.
10pub type Point2 = Vec2;
11/// A semantic alias used when a value is a three-dimensional position.
12pub type Point3 = Vec3;
13/// Double-precision 3x3 matrix.
14pub type Mat3 = glam::DMat3;
15/// Double-precision 2D affine transform.
16pub type Transform2 = glam::DAffine2;
17/// Double-precision affine transform.
18pub type Transform3 = glam::DAffine3;
19/// Backward-compatible name for [`Transform3`].
20pub type Mat4 = Transform3;
21
22/// Right-handed 2D local frame. Algorithms validate orthonormality explicitly.
23#[derive(Debug, Clone, Copy, PartialEq)]
24pub struct Frame2 {
25    /// Local origin.
26    pub origin: Point2,
27    /// Local x axis.
28    pub x: Vec2,
29    /// Local y axis.
30    pub y: Vec2,
31}
32
33/// Right-handed 3D local frame. Dirty imported frames remain representable.
34#[derive(Debug, Clone, Copy, PartialEq)]
35pub struct Frame3 {
36    /// Local origin.
37    pub origin: Point3,
38    /// Local x axis.
39    pub x: Vec3,
40    /// Local y axis.
41    pub y: Vec3,
42    /// Local z axis.
43    pub z: Vec3,
44}
45
46/// A finite parameter interval. The endpoint order carries orientation.
47#[derive(Debug, Clone, Copy, PartialEq)]
48pub struct Interval {
49    /// Start parameter.
50    pub start: Scalar,
51    /// End parameter.
52    pub end: Scalar,
53}
54
55impl Interval {
56    /// Unit parameter interval.
57    pub const UNIT: Self = Self {
58        start: 0.0,
59        end: 1.0,
60    };
61
62    /// Construct an oriented interval without sorting its endpoints.
63    pub const fn new(start: Scalar, end: Scalar) -> Self {
64        Self { start, end }
65    }
66
67    /// Absolute parameter span.
68    pub fn length(self) -> Scalar {
69        (self.end - self.start).abs()
70    }
71}
72
73/// A plane represented by an origin and unit-normal candidate.
74///
75/// Adapters may construct dirty input. Algorithms validate normalization using
76/// the operation's tolerance instead of hiding a global epsilon here.
77#[derive(Debug, Clone, Copy, PartialEq)]
78pub struct Plane3 {
79    /// Point on the plane.
80    pub origin: Point3,
81    /// Expected outward normal.
82    pub normal: Vec3,
83}
84
85/// A parametric three-dimensional ray.
86#[derive(Debug, Clone, Copy, PartialEq)]
87pub struct Ray3 {
88    /// Ray start.
89    pub origin: Point3,
90    /// Ray direction. It need not be normalized at the storage boundary.
91    pub direction: Vec3,
92}