Raven Engine v0.1
A modern 3D Game Engine
Loading...
Searching...
No Matches
Math

Mathematical operations and algorithms. More...

Files

file  Crux/src/Crux/Math/Detail/TrigPolyImpl.inl
 Estrin-based polynomial evaluation for sine and cosine.

Classes

struct  Crux::AABB
 Axis-aligned bounding box defined by a min and max corner in 3D space. More...
struct  Crux::BoundingSphere
 Bounding sphere defined by a center point and radius. More...
struct  Crux::Frustum
 View frustum represented as six half-space planes. More...

Functions

template<typename T>
constexpr T Crux::Lerp (T a, T b, f32 t)
 Linear interpolation between a and b by factor t.
template<typename T>
constexpr T Crux::Min (T a, T b)
 Return the minimum of two values.
template<typename T>
constexpr T Crux::Max (T a, T b)
 Return the maximum of two values.
template<typename T>
constexpr T Crux::Clamp (T value, T min, T max)
 Clamp a value between a minimum and maximum.
template<typename T>
constexpr T Crux::Saturate (T value)
 Clamp a value to the [0,1] range.
template<typename T>
constexpr T Crux::Sign (T value)
 Signum function: returns -1, 0, or +1.
template<typename T>
constexpr T Crux::Abs (T value)
 Absolute value.
template<typename T>
constexpr T Crux::Floor (T value)
 Floor function for f32ing-point values.
template<typename T>
constexpr T Crux::Ceil (T value)
 Ceiling function for f32ing-point values.
template<typename T>
constexpr T Crux::Fract (T value)
 Fractional part of a value.
template<typename T>
constexpr T Crux::Square (T value)
 Square of a value.
template<typename T>
constexpr T Crux::Cube (T value)
 Cube of a value.
constexpr f32 Crux::Smoothstep (f32 edge0, f32 edge1, f32 x)
 Smoothstep interpolation between edge0 and edge1.
constexpr f32 Crux::CTInverseSqrt (f32 x)
 Fast compile-time inverse square root (single Newton step).
constexpr f32 Crux::CTSqrt (const f32 x)
 Fast compile-time square root using bit manipulation.
f32 Crux::InverseSqrt (const f32 x)
 Inverse square root using hardware rsqrt.
f32 Crux::Sqrt (const f32 x)
 Standard square root using hardware sqrt.
constexpr f32 Crux::Radians (f32 degrees)
 Convert degrees to radians.
constexpr Vector< f32, 3 > Crux::Radians (Vector< f32, 3 > vector)
 Convert a Vector3s components from degrees to radians.
constexpr f32 Crux::Degrees (f32 radians)
 Convert radians to degrees.
template<typename T>
constexpr Vector< T, 3 > Crux::Degrees (Vector< T, 3 > vector)
 Convert a Vector3s components from radians to degrees.
template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
f32 Crux::Sin (f32 radians)
 Computes the sine of an angle in radians using a fast polynomial approximation.
template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
f32 Crux::Cos (f32 radians)
 Computes the cosine of an angle in radians using a fast polynomial approximation.
template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
f32 Crux::Tan (f32 radians)
 Computes the tangent of an angle in radians using a fast polynomial approximation.

Detailed Description

Mathematical operations and algorithms.

Houses core arithmetic and math utilities.

Function Documentation

◆ Abs()

template<typename T>
T Crux::Abs ( T value)
inlineconstexpr

Absolute value.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
Non-negative absolute of value.

◆ Ceil()

template<typename T>
T Crux::Ceil ( T value)
inlineconstexpr

Ceiling function for f32ing-point values.

Template Parameters
Tf32ing-point type.
Parameters
valueInput value.
Returns
Smallest integer >= value as T.

◆ Clamp()

template<typename T>
T Crux::Clamp ( T value,
T min,
T max )
inlineconstexpr

Clamp a value between a minimum and maximum.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
minMinimum allowed.
maxMaximum allowed.
Returns
Clamped value in [min, max].

◆ Cos()

template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
f32 Crux::Cos ( f32 radians)
inline

Computes the cosine of an angle in radians using a fast polynomial approximation.

Performs a branchless range-reduction into [-pi/4, pi/4], shifts the quadrant index for the pi/2 phase offset (cos(x)=sin(x+pi/2)), evaluates a minimax polynomial of degree determined by the PrecisionMode template (Standard=7), and applies the correct sign.

Template Parameters
PrecisionModeSelects the polynomial degree:
  • Fast (degree 5)
  • Standard (degree 7, default)
  • High (degree 9) It is recommended to use Standard for most applications.
Parameters
radiansAngle in radians.
Returns
Approximation of cos(radians).
Note
This uses the internal Detail::ReduceAngle and Detail::PolyCos<PrecisionMode> routines.
See also
Detail::ReduceAngle, Detail::PolyCos

◆ CTInverseSqrt()

f32 Crux::CTInverseSqrt ( f32 x)
inlineconstexpr

Fast compile-time inverse square root (single Newton step).

Note
This is an approximation and may not be accurate for all values. Prefer using the provided Hardware InverseSqrt function. Only use if you need the value at Compile-Time
Warning
Entering 0.0f will result in a really large number.
Parameters
xInput value.
Returns
Approximate 1/sqrt(x).

◆ CTSqrt()

f32 Crux::CTSqrt ( const f32 x)
inlineconstexpr

Fast compile-time square root using bit manipulation.

Note
This is an approximation and may not be accurate for all values. Prefer using the provided Hardware Sqrt function. Only use if you need the value at Compile-Time
Warning
Entering a negative value will result in inf.
Parameters
xInput value.
Returns
Approximate sqrt(x).

◆ Cube()

template<typename T>
T Crux::Cube ( T value)
inlineconstexpr

Cube of a value.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
value * value * value.

◆ Degrees() [1/2]

f32 Crux::Degrees ( f32 radians)
inlineconstexpr

Convert radians to degrees.

Parameters
radiansAngle in radians.
Returns
Angle in degrees.

◆ Degrees() [2/2]

template<typename T>
Vector< T, 3 > Crux::Degrees ( Vector< T, 3 > vector)
inlineconstexpr

Convert a Vector3s components from radians to degrees.

Parameters
vectorThe Vector to convert
Returns
A vector with all its components turned from radians to degrees

◆ Floor()

template<typename T>
T Crux::Floor ( T value)
inlineconstexpr

Floor function for f32ing-point values.

Template Parameters
Tf32ing-point type.
Parameters
valueInput value.
Returns
Largest integer <= value as T.

◆ Fract()

template<typename T>
T Crux::Fract ( T value)
inlineconstexpr

Fractional part of a value.

Template Parameters
Tf32ing-point type.
Parameters
valueInput value.
Returns
value - floor(value).

◆ InverseSqrt()

f32 Crux::InverseSqrt ( const f32 x)
inline

Inverse square root using hardware rsqrt.

Warning
Entering 0.0f will result in infinity.
Parameters
xInput value.
Returns
1.0f / sqrt(x).

◆ Lerp()

template<typename T>
T Crux::Lerp ( T a,
T b,
f32 t )
inlineconstexpr

Linear interpolation between a and b by factor t.

Template Parameters
TArithmetic type of endpoints.
Parameters
aStart value.
bEnd value.
tInterpolation factor in [0,1].
Returns
Interpolated value.

◆ Max()

template<typename T>
T Crux::Max ( T a,
T b )
inlineconstexpr

Return the maximum of two values.

Template Parameters
TArithmetic type.
Parameters
aFirst value.
bSecond value.
Returns
Larger of a and b.

◆ Min()

template<typename T>
T Crux::Min ( T a,
T b )
inlineconstexpr

Return the minimum of two values.

Template Parameters
TArithmetic type.
Parameters
aFirst value.
bSecond value.
Returns
Smaller of a and b.

◆ Radians() [1/2]

f32 Crux::Radians ( f32 degrees)
inlineconstexpr

Convert degrees to radians.

Parameters
degreesAngle in degrees.
Returns
Angle in radians.

◆ Radians() [2/2]

Vector< f32, 3 > Crux::Radians ( Vector< f32, 3 > vector)
inlineconstexpr

Convert a Vector3s components from degrees to radians.

Parameters
vectorThe Vector to convert
Returns
A vector with all its components turned from degress to radians

◆ Saturate()

template<typename T>
T Crux::Saturate ( T value)
inlineconstexpr

Clamp a value to the [0,1] range.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
Saturated value in [0,1].

◆ Sign()

template<typename T>
T Crux::Sign ( T value)
inlineconstexpr

Signum function: returns -1, 0, or +1.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
+1 if value > 0, -1 if value < 0, 0 if value == 0.

◆ Sin()

template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
f32 Crux::Sin ( f32 radians)
inline

Computes the sine of an angle in radians using a fast polynomial approximation.

Performs a branchless range-reduction into [-pi/4, pi/4], evaluates a minimax polynomial of degree determined by the PrecisionMode template (Standard=7), and applies the correct sign based on the original quadrant.

Template Parameters
PrecisionModeSelects the polynomial degree:
  • Fast (degree 5)
  • Standard (degree 7, default)
  • High (degree 9)

It is recommended to use Standard for most applications.

Parameters
radiansAngle in radians.
Returns
Approximation of sin(radians).
Note
This uses the internal Detail::ReduceAngle and Detail::PolySin<PrecisionMode> routines.
See also
Detail::ReduceAngle, Detail::PolySin

◆ Smoothstep()

f32 Crux::Smoothstep ( f32 edge0,
f32 edge1,
f32 x )
inlineconstexpr

Smoothstep interpolation between edge0 and edge1.

Parameters
edge0Lower edge of interpolation.
edge1Upper edge of interpolation.
xValue to interpolate.
Returns
Interpolated result in [0,1].

◆ Sqrt()

f32 Crux::Sqrt ( const f32 x)
inline

Standard square root using hardware sqrt.

Warning
Entering a negative value will result in -nan.
Parameters
xInput value.
Returns
sqrt(x).

◆ Square()

template<typename T>
T Crux::Square ( T value)
inlineconstexpr

Square of a value.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
value * value.

◆ Tan()

template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
f32 Crux::Tan ( f32 radians)
inline

Computes the tangent of an angle in radians using a fast polynomial approximation.

Performs a branchless range-reduction into [-pi/4, pi/4], evaluates minimax polynomials for both sine and cosine of degree determined by the PrecisionMode template (Standard=7), applies quadrant-based transformations, and computes the ratio sin/cos.

This implementation is optimized to share the range reduction and polynomial evaluation between the sine and cosine components, making it more efficient than calling Sin and Cos separately.

Template Parameters
PrecisionModeSelects the polynomial degree:
  • Fast (degree 5)
  • Standard (degree 7, default)
  • High (degree 9) It is recommended to use Standard for most applications.
Parameters
radiansAngle in radians.
Returns
Approximation of tan(radians).
Note
This uses the internal Detail::ReduceAngle, Detail::PolySin<PrecisionMode>, and Detail::PolyCos<PrecisionMode> routines.
The result is undefined at odd multiples of pi/2 where cos(radians) = 0.
See also
Detail::ReduceAngle, Detail::PolySin, Detail::PolyCos