12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #ifndef CORE_MATH_H
- #define CORE_MATH_H
- #include <math.h>
- #ifndef M_PI
- #define M_PI 3.14159265358979323846
- #endif
- #ifndef _GNU_SOURCE
- void sincosf(float a, float* s, float* c);
- #endif
- namespace Core::Math {
- template<typename T>
- T interpolate(const T& a, const T& b, float f) {
- return a * (1.0f - f) + b * f;
- }
- constexpr int roundUpLog2(int i) {
- if(i <= 0) {
- return 0;
- }
- int c = 1;
- while(((i - 1) >> c) > 0) {
- c++;
- }
- return c;
- }
- template<typename T>
- const T& min(const T& t) {
- return t;
- }
- template<typename T, typename... Args>
- const T& min(const T& t, Args&&... args) {
- const T& o = min(args...);
- return t < o ? t : o;
- }
- template<typename T>
- const T& max(const T& t) {
- return t;
- }
- template<typename T, typename... Args>
- const T& max(const T& t, Args&&... args) {
- const T& o = max(args...);
- return o < t ? t : o;
- }
- template<typename T>
- const T& clamp(const T& t, const T& borderA, const T& borderB) {
- const T& low = min(borderA, borderB);
- const T& high = max(borderA, borderB);
- return max(low, min(high, t));
- }
- }
- #endif
|