Skip to main content

euv_engine/math/
struct.rs

1use crate::*;
2
3/// A zero-sized namespace struct providing static math utility methods.
4///
5/// This struct follows the same pattern as `App`, serving as a namespace for
6/// free-standing mathematical functions such as `clamp`, `lerp`, angle conversions,
7/// and interpolation helpers.
8#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, Ord, PartialEq, PartialOrd)]
9pub struct Numeric;
10
11/// A 2D vector with `x` and `y` components represented as `f64`.
12#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq, PartialOrd)]
13pub struct Vector2D {
14    /// The horizontal component of the vector.
15    #[get(type(copy))]
16    pub(crate) x: f64,
17    /// The vertical component of the vector.
18    #[get(type(copy))]
19    pub(crate) y: f64,
20}
21
22/// An axis-aligned rectangle defined by its top-left corner and dimensions.
23#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq, PartialOrd)]
24pub struct Rect {
25    /// The x coordinate of the top-left corner.
26    #[get(type(copy))]
27    pub(crate) x: f64,
28    /// The y coordinate of the top-left corner.
29    #[get(type(copy))]
30    pub(crate) y: f64,
31    /// The width of the rectangle.
32    #[get(type(copy))]
33    pub(crate) width: f64,
34    /// The height of the rectangle.
35    #[get(type(copy))]
36    pub(crate) height: f64,
37}
38
39/// A circle defined by its center point and radius.
40#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq, PartialOrd)]
41pub struct Circle {
42    /// The center point of the circle.
43    #[get(type(copy))]
44    pub(crate) center: Vector2D,
45    /// The radius of the circle.
46    #[get(type(copy))]
47    pub(crate) radius: f64,
48}
49
50/// A 2D transform composed of position, rotation (in radians), and scale.
51#[derive(Clone, Copy, Data, Debug, New, PartialEq, PartialOrd)]
52pub struct Transform2D {
53    /// The position offset of the transform.
54    #[get(type(copy))]
55    pub(crate) position: Vector2D,
56    /// The rotation angle in radians.
57    #[get(type(copy))]
58    pub(crate) rotation: f64,
59    /// The scale factors for each axis.
60    #[get(type(copy))]
61    pub(crate) scale: Vector2D,
62}
63
64/// A color represented by red, green, blue, and alpha channels in the range 0.0 to 1.0.
65#[derive(Clone, Copy, Data, Debug, New, PartialEq, PartialOrd)]
66pub struct Color {
67    /// The red channel value in the range 0.0 to 1.0.
68    #[get(type(copy))]
69    pub(crate) red: f64,
70    /// The green channel value in the range 0.0 to 1.0.
71    #[get(type(copy))]
72    pub(crate) green: f64,
73    /// The blue channel value in the range 0.0 to 1.0.
74    #[get(type(copy))]
75    pub(crate) blue: f64,
76    /// The alpha (opacity) channel value in the range 0.0 to 1.0.
77    #[get(type(copy))]
78    pub(crate) alpha: f64,
79}
80
81/// A 3D vector with `x`, `y`, and `z` components represented as `f64`.
82#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq, PartialOrd)]
83pub struct Vector3D {
84    /// The horizontal component of the vector.
85    #[get(type(copy))]
86    pub(crate) x: f64,
87    /// The vertical component of the vector.
88    #[get(type(copy))]
89    pub(crate) y: f64,
90    /// The depth component of the vector.
91    #[get(type(copy))]
92    pub(crate) z: f64,
93}
94
95/// A quaternion representing a 3D rotation with `x`, `y`, `z`, and `w` components.
96#[derive(Clone, Copy, Data, Debug, New, PartialEq, PartialOrd)]
97pub struct Quaternion {
98    /// The x component of the quaternion.
99    #[get(type(copy))]
100    pub(crate) x: f64,
101    /// The y component of the quaternion.
102    #[get(type(copy))]
103    pub(crate) y: f64,
104    /// The z component of the quaternion.
105    #[get(type(copy))]
106    pub(crate) z: f64,
107    /// The w (scalar) component of the quaternion.
108    #[get(type(copy))]
109    pub(crate) w: f64,
110}
111
112/// A 4x4 matrix stored in column-major order, used for 3D transformations.
113#[derive(Clone, Copy, Data, Debug, New, PartialEq, PartialOrd)]
114pub struct Matrix4x4 {
115    /// The 16 elements of the matrix in column-major order.
116    #[get(type(copy))]
117    pub(crate) elements: [f64; 16],
118}
119
120/// A 3D transform composed of position, rotation (as a quaternion), and scale.
121#[derive(Clone, Copy, Data, Debug, New, PartialEq, PartialOrd)]
122pub struct Transform3D {
123    /// The position offset of the transform.
124    #[get(type(copy))]
125    pub(crate) position: Vector3D,
126    /// The rotation as a quaternion.
127    #[get(type(copy))]
128    pub(crate) rotation: Quaternion,
129    /// The scale factors for each axis.
130    #[get(type(copy))]
131    pub(crate) scale: Vector3D,
132}
133
134/// A 3D axis-aligned bounding box defined by its minimum and maximum corners.
135#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq, PartialOrd)]
136pub struct AABB3D {
137    /// The minimum corner (smallest x, y, z).
138    #[get(type(copy))]
139    pub(crate) min: Vector3D,
140    /// The maximum corner (largest x, y, z).
141    #[get(type(copy))]
142    pub(crate) max: Vector3D,
143}
144
145/// A 3D sphere defined by its center point and radius.
146#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq, PartialOrd)]
147pub struct Sphere {
148    /// The center point of the sphere.
149    #[get(type(copy))]
150    pub(crate) center: Vector3D,
151    /// The radius of the sphere.
152    #[get(type(copy))]
153    pub(crate) radius: f64,
154}
155
156/// A 3D plane defined by a normal vector and a distance from the origin.
157#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq, PartialOrd)]
158pub struct Plane {
159    /// The normal vector of the plane (should be normalized).
160    #[get(type(copy))]
161    pub(crate) normal: Vector3D,
162    /// The signed distance from the origin along the normal.
163    #[get(type(copy))]
164    pub(crate) distance: f64,
165}
166
167/// A 3D ray defined by an origin point and a direction vector.
168#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq, PartialOrd)]
169pub struct Ray3D {
170    /// The origin point of the ray.
171    #[get(type(copy))]
172    pub(crate) origin: Vector3D,
173    /// The direction vector of the ray (should be normalized).
174    #[get(type(copy))]
175    pub(crate) direction: Vector3D,
176}