|
MathFu
An open source project by
FPL.
|
Utility functions. More...
Utility functions.
Macros | |
| #define | MATHFU_STATIC_ASSERT(x) static_assert_util<(x)>() |
| Compile time assert for pre-C++11 compilers. More... | |
Functions | |
| template<class T > | |
| T | mathfu::Clamp (const T &x, const T &lower, const T &upper) |
| Clamp x within [lower, upper]. More... | |
| template<class T , class T2 > | |
| T | mathfu::Lerp (const T &range_start, const T &range_end, const T2 &percent) |
| Linearly interpolate between range_start and range_end, based on percent. More... | |
| template<class T > | |
| T | mathfu::Lerp (const T &range_start, const T &range_end, const T &percent) |
| Linearly interpolate between range_start and range_end, based on percent. More... | |
| template<class T > | |
| bool | mathfu::InRange (T val, T range_start, T range_end) |
| Check if val is within [range_start..range_end). More... | |
| template<class T > | |
| T | mathfu::Random () |
| Generate a random value of type T. More... | |
| template<class T > | |
| T | mathfu::RandomRange (T range) |
| Generate a random value of type T in the range -range...+range. More... | |
| template<class T > | |
| T | mathfu::RandomInRange (T range_start, T range_end) |
| Generate a random number between [range_start, range_end]. More... | |
| template<class T > | |
| T | mathfu::RoundUpToPowerOf2 (T x) |
| Round a value up to the nearest power of 2. More... | |
| template<> | |
| int32_t | mathfu::RoundUpToPowerOf2 (int32_t x) |
| Specialized version of RoundUpToPowerOf2 for int32_t. | |
| template<typename T > | |
| uint32_t | mathfu::RoundUpToTypeBoundary (uint32_t v) |
| Round a value up to the type's size boundary. More... | |
| template<typename T , int d> | |
| Vector< T, d > | mathfu::RoundUpToPowerOf2 (const Vector< T, d > &v) |
| Specialized version of RoundUpToPowerOf2 for vector. | |
| #define MATHFU_STATIC_ASSERT | ( | x | ) | static_assert_util<(x)>() |
Compile time assert for pre-C++11 compilers.
For example:
MATHFU_STATIC_ASSERT(0 == 1);
will result in a compile error.
| T mathfu::Clamp | ( | const T & | x, |
| const T & | lower, | ||
| const T & | upper | ||
| ) |
| bool mathfu::InRange | ( | T | val, |
| T | range_start, | ||
| T | range_end | ||
| ) |
| T mathfu::Lerp | ( | const T & | range_start, |
| const T & | range_end, | ||
| const T2 & | percent | ||
| ) |
Linearly interpolate between range_start and range_end, based on percent.
| range_start | Start of the range. |
| range_end | End of the range. |
| percent | Value between 0.0 and 1.0 used to interpolate between range_start and range_end. Where a value of 0.0 results in a return value of range_start and 1.0 results in a return value of range_end. |
| T | Type of the range to interpolate over. |
| T2 | Type of the value used to perform interpolation (e.g float or double). |
| T mathfu::Lerp | ( | const T & | range_start, |
| const T & | range_end, | ||
| const T & | percent | ||
| ) |
Linearly interpolate between range_start and range_end, based on percent.
| range_start | Start of the range. |
| range_end | End of the range. |
| percent | Value between 0.0 and 1.0 used to interpolate between range_start and range_end. Where a value of 0.0 results in a return value of range_start and 1.0 results in a return value of range_end. |
| T | Type of the range to interpolate over. |
|
inline |
Generate a random value of type T.
This method generates a random value of type T, greater than or equal to 0.0 and less than 1.0.
This function uses the standard C library function rand() from math.h to generate the random number.
|
inline |
|
inline |
Generate a random value of type T in the range -range...+range.
This function uses the standard C library function rand() from math.h to generate the random number.
| range | Range of the random value to generate. |
| T mathfu::RoundUpToPowerOf2 | ( | T | x | ) |
Round a value up to the nearest power of 2.
| x | Value to round up. |
| uint32_t mathfu::RoundUpToTypeBoundary | ( | uint32_t | v | ) |
Round a value up to the type's size boundary.
| v | Value to round up. |