goud_engine/core/math/mod.rs
1//! FFI-safe mathematical types for the engine.
2//!
3//! This module provides `#[repr(C)]` mathematical types that are safe to pass across
4//! FFI boundaries. These types wrap functionality from cgmath but guarantee a stable,
5//! predictable memory layout for use with C#, Python, and other language bindings.
6//!
7//! # Design Decision
8//!
9//! We wrap cgmath rather than replacing it because:
10//! 1. **Internal Operations**: cgmath provides battle-tested matrix/vector operations
11//! (look_at, quaternion math, etc.) that would be error-prone to reimplement
12//! 2. **FFI Safety**: cgmath types like `Vector3<f32>` are newtypes over arrays and
13//! don't guarantee a specific memory layout suitable for FFI
14//! 3. **Type Safety**: Our wrappers ensure compile-time FFI compatibility while
15//! maintaining ergonomic conversions for internal use
16//!
17//! # Usage
18//!
19//! ```rust
20//! use goud_engine::core::math::{Vec3, Color};
21//!
22//! // Create FFI-safe types
23//! let position = Vec3::new(1.0, 2.0, 3.0);
24//! let color = Color::RED;
25//!
26//! // Convert to cgmath for internal math operations
27//! let cgmath_vec: cgmath::Vector3<f32> = position.into();
28//!
29//! // Convert back from cgmath results
30//! let result = Vec3::from(cgmath_vec);
31//! ```
32
33// Re-export cgmath types for internal use where FFI is not needed
34pub use cgmath::{Matrix3, Matrix4, Point3, Quaternion};
35
36mod color;
37mod easing;
38mod rect;
39mod tween;
40mod vec2;
41mod vec3;
42mod vec4;
43
44#[cfg(test)]
45mod tests;
46
47pub use color::Color;
48pub use easing::{
49 ease_in, ease_in_back, ease_in_out, ease_out, ease_out_bounce, linear, BezierEasing, Easing,
50 EasingFn,
51};
52pub use rect::Rect;
53pub use tween::{tween, Tweenable};
54pub use vec2::Vec2;
55pub use vec3::Vec3;
56pub use vec4::Vec4;