27 #include "Portability.h" 30 #ifndef DOXYGEN_SHOULD_SKIP_THIS 38 constexpr
float Pi = 3.14159265358979323846f;
44 constexpr
float Pi2 = Pi / 2;
50 constexpr
float Pi4 = Pi / 4;
56 constexpr
float Sqrt2 = 1.41421356237309504880f;
68 constexpr
float Sqrt3 = 1.7320508075688772935f;
74 constexpr
float Epsilon = std::numeric_limits<float>::epsilon();
93 T diff = std::abs(a - b);
95 if (a == 0 || b == 0 || diff < std::numeric_limits<T>::denorm_min()) {
96 return diff < (epsilon * std::numeric_limits<T>::denorm_min());
99 T sum = std::abs(a) + std::abs(b);
100 sum = (sum < std::numeric_limits<T>::max()) ? sum : std::numeric_limits<T>::max();
102 return (diff / sum) < epsilon;
114 return degrees * Pi / 180.0f;
126 return radians * 180.0f /
Pi;
187 return (-2 * t + 3) * t * t;
210 return ((6 * t - 15) * t + 10) * t * t * t;
224 return (1 - std::cos(Pi * t)) * 0.5;
240 template<
typename T,
typename U>
243 return (1 - t) * lhs + t * rhs;
261 return val < lo ? lo : (val > hi ? hi : val);
296 return (val >
T(0)) - (val <
T(0));
314 return lhs > rhs ? lhs - rhs : rhs - lhs;
317 #ifndef DOXYGEN_SHOULD_SKIP_THIS constexpr float Pi2
The constant.
Definition: Math.h:44
constexpr float Epsilon
Machine epsilon.
Definition: Math.h:74
constexpr float radiansToDegrees(float radians)
Convert radians to degrees.
Definition: Math.h:125
constexpr float InvSqrt2
The constant.
Definition: Math.h:62
constexpr float degreesToRadians(float degrees)
Convert degrees to radians.
Definition: Math.h:113
T lerp(T lhs, T rhs, U t)
Linear interpolation function.
Definition: Math.h:242
constexpr T absdiff(T lhs, T rhs)
Absolute difference of two values.
Definition: Math.h:313
constexpr T square(T val)
Square function.
Definition: Math.h:275
constexpr T clamp(T val, T lo, T hi)
Clamping function.
Definition: Math.h:260
bool almostEquals(T a, T b, T epsilon=std::numeric_limits< T >::epsilon())
Compare two floats.
Definition: Math.h:88
constexpr float Sqrt2
The constant.
Definition: Math.h:56
constexpr T cubicStep(T t)
Cubic step (smoothstep)
Definition: Math.h:186
The namespace for gf classes.
Definition: Action.h:34
T cosineStep(T t)
Cosine step.
Definition: Math.h:223
constexpr float Pi
The constant.
Definition: Math.h:38
constexpr T linearStep(T t)
Linear step.
Definition: Math.h:165
constexpr float Sqrt3
The constant.
Definition: Math.h:68
constexpr int sign(T val)
Sign function.
Definition: Math.h:295
T(*)(T) Step
A step is a function with special features.
Definition: Math.h:153
constexpr T quinticStep(T t)
Quintic step (smootherstep)
Definition: Math.h:209
constexpr float Pi4
The constant.
Definition: Math.h:50