| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- export module Core.Math;
- import Core.Meta;
- export namespace Core {
- template<typename T>
- T interpolate(const T& a, const T& b, float f) noexcept {
- return a * (1.0f - f) + b * f;
- }
- constexpr bool isPowerOf2(int i) noexcept {
- return (i & (i - 1)) == 0;
- }
- template<typename T>
- constexpr T roundUpLog2(T i) noexcept {
- if(i <= 0) {
- return 0;
- }
- T c = 1;
- while(((i - 1) >> c) > 0) {
- c++;
- }
- return c;
- }
- template<typename T>
- constexpr const T& min(const T& t) noexcept {
- return t;
- }
- template<typename T, typename... Args>
- constexpr const T& min(const T& t, Args&&... args) noexcept {
- const T& o = min(Core::forward<Args>(args)...);
- return t < o ? t : o;
- }
- template<typename T>
- constexpr const T& max(const T& t) noexcept {
- return t;
- }
- template<typename T, typename... Args>
- constexpr const T& max(const T& t, Args&&... args) noexcept {
- 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) noexcept {
- const T& low = min(borderA, borderB);
- const T& high = max(borderA, borderB);
- return max(low, min(high, t));
- }
- inline constexpr float PI = 3.14159265358979323846f;
- template<typename T>
- constexpr T radianToDegree(const T& radians) noexcept {
- return radians * static_cast<T>(180.0f / PI);
- }
- template<typename T>
- constexpr T degreeToRadian(const T& radians) noexcept {
- return radians * static_cast<T>(PI / 180.0f);
- }
- }
|