Skip to main content

Module math

Module math 

Source
Expand description

FFI-safe mathematical types for the engine.

This module provides #[repr(C)] mathematical types that are safe to pass across FFI boundaries. These types wrap functionality from cgmath but guarantee a stable, predictable memory layout for use with C#, Python, and other language bindings.

§Design Decision

We wrap cgmath rather than replacing it because:

  1. Internal Operations: cgmath provides battle-tested matrix/vector operations (look_at, quaternion math, etc.) that would be error-prone to reimplement
  2. FFI Safety: cgmath types like Vector3<f32> are newtypes over arrays and don’t guarantee a specific memory layout suitable for FFI
  3. Type Safety: Our wrappers ensure compile-time FFI compatibility while maintaining ergonomic conversions for internal use

§Usage

use goud_engine::core::math::{Vec3, Color};

// Create FFI-safe types
let position = Vec3::new(1.0, 2.0, 3.0);
let color = Color::RED;

// Convert to cgmath for internal math operations
let cgmath_vec: cgmath::Vector3<f32> = position.into();

// Convert back from cgmath results
let result = Vec3::from(cgmath_vec);

Structs§

BezierEasing
Cubic Bezier easing with two control points.
Color
An RGBA color with FFI-safe memory layout.
Matrix3
A 3 x 3, column major matrix
Matrix4
A 4 x 4, column major matrix
Point3
A point in 3-dimensional space.
Quaternion
A quaternion in scalar/vector form.
Rect
A 2D rectangle with FFI-safe memory layout.
Vec2
A 2D vector with FFI-safe memory layout.
Vec3
A 3D vector with FFI-safe memory layout.
Vec4
A 4D vector with FFI-safe memory layout.

Enums§

Easing
Enumeration of built-in easing types plus custom cubic Bezier.

Traits§

Tweenable
A type that can be interpolated between two values.

Functions§

ease_in
Quadratic ease-in (slow start).
ease_in_back
Ease-in with overshoot (back easing).
ease_in_out
Quadratic ease-in-out (slow start and end).
ease_out
Quadratic ease-out (slow end).
ease_out_bounce
Bounce ease-out.
linear
Linear easing (identity).
tween
Convenience function to tween a single f32 value with an easing function.

Type Aliases§

EasingFn
Type alias for easing functions: maps normalized time t in [0, 1] to a curved value.