1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #ifndef CORE_MATH_HPP
- #define CORE_MATH_HPP
- #include "utils/Meta.hpp"
- namespace Core::Math {
- template<typename T>
- T interpolate(const T& a, const T& b, float f) {
- return a * (1.0f - f) + b * f;
- }
- constexpr bool isPowerOf2(int i) {
- return (i & (i - 1)) == 0;
- }
- constexpr int roundUpLog2(int i) {
- if(i <= 0) {
- return 0;
- }
- int c = 1;
- while(((i - 1) >> c) > 0) {
- c++;
- }
- return c;
- }
- template<typename T>
- constexpr const T& min(const T& t) {
- return t;
- }
- template<typename T, typename... Args>
- constexpr const T& min(const T& t, Args&&... args) {
- const T& o = min(Core::forward<Args>(args)...);
- return t < o ? t : o;
- }
- template<typename T>
- constexpr const T& max(const T& t) {
- return t;
- }
- template<typename T, typename... Args>
- constexpr const T& max(const T& t, Args&&... args) {
- const T& o = max(Core::forward<Args>(args)...);
- return o < t ? t : o;
- }
- template<typename T>
- constexpr 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));
- }
- constexpr float PI = 3.14159265358979323846f;
- float sin(float f);
- float cos(float f);
- float tan(float f);
- void sinCos(float a, float& s, float& c);
- constexpr float radianToDegree(float radians) {
- return radians * (180.0f / PI);
- }
- constexpr float degreeToRadian(float degrees) {
- return degrees * (PI / 180.0f);
- }
- float squareRoot(float f);
- }
- #endif
|