Module math

Source
Expand description

Provides foundational mathematics primitives for 2D and 3D.

This module contains a comprehensive set of types and functions for linear algebra and geometry, forming the mathematical backbone of the Khora Engine. It includes vectors, matrices, quaternions, and various utility functions designed for performance and ease of use.

All angular functions in this module operate in radians by default, unless explicitly specified otherwise (e.g., degrees_to_radians).

Re-exports§

pub use self::color::LinearRgba;
pub use self::dimension::Extent1D;
pub use self::dimension::Extent2D;
pub use self::dimension::Extent3D;
pub use self::dimension::Origin2D;
pub use self::dimension::Origin3D;
pub use self::geometry::Aabb;
pub use self::matrix::Mat3;
pub use self::matrix::Mat4;
pub use self::quaternion::Quaternion;
pub use self::vector::Vec2;
pub use self::vector::Vec3;
pub use self::vector::Vec4;

Modules§

color
Defines the LinearRgba color type and associated operations.
dimension
Provides structs for representing extents (sizes) and origins (offsets) in 1D, 2D, and 3D.
geometry
Provides geometric primitive shapes for spatial calculations.
matrix
Defines the Mat3 and Mat4 types and associated operations.
quaternion
Provides a Quaternion type for representing 3D rotations.
vector
Provides 2D, 3D, and 4D vector types and their associated operations.

Constants§

DEG_TO_RAD
The factor to convert degrees to radians (PI / 180.0).
E
Euler’s number (e)
EPSILON
A small constant for floating-point comparisons.
FRAC_PI_2
π/2
FRAC_PI_3
π/3
FRAC_PI_4
π/4
FRAC_PI_6
π/6
FRAC_PI_8
π/8
LN_2
ln(2)
LN_10
ln(10)
LOG2_E
log2(e)
LOG10_E
log10(e)
PI
Archimedes’ constant (π)
RAD_TO_DEG
The factor to convert radians to degrees (180.0 / PI).
SQRT_2
sqrt(2)
TAU
The full circle constant (τ)

Functions§

approx_eq
Performs an approximate equality comparison using the module’s default EPSILON.
approx_eq_eps
Performs an approximate equality comparison between two floats with a custom tolerance.
clamp
Clamps a value to a specified minimum and maximum range.
degrees_to_radians
Converts an angle from degrees to radians.
radians_to_degrees
Converts an angle from radians to degrees.
saturate
Clamps a floating-point value to the [0.0, 1.0] range.