Utils

namespace tnt

Functions

constexpr float operator""_pi(unsigned long long num)

Variables

constexpr float PI = {3.1415926f}
constexpr auto RadianToDegree = [](float rad) -> float { return (rad * (180.0f / PI)); }
constexpr auto DegreeToRadian = [](float deg) -> float { return (deg * (PI / 180.0f)); }
template<typename T>
auto clamp = [](T val, T min, T max) { if (val < min) val = min; if (val > max) val = max; return val; }
template<class T>
constexpr auto lerp = [](T a, T b, float pct) -> decltype(a + (b - a) * pct) { return a + (b - a) * pct; }
template<class T>
constexpr auto blerp = [](T a1, T a2, T b1, T b2, float pct1, float pct2) { return (a1 * (1 - pct1) * (1 - pct2) + a2 * pct1 * (1 - pct2) + b1 * pct2 * (1 - pct1) + b2 * pct1 * pct2); }
template<class T>
constexpr auto bezier_curve = [](T p1, T p2, T p3, T p4, float pct) { return ((p1 * (1 - pct) * (1 - pct) * (1 - pct)) + (p2 * 3 * (1 - pct) * (1 - pct) * pct) + (p3 * 3 * (1 - pct) * pct * pct) + (p4 * pct * pct * pct)); }
template<typename T>
constexpr auto step = [](T a, T b) -> float { return static_cast<float>(a <= b); }
template<typename T>
constexpr auto boxstep = [](T a, T b, T x) -> float { return clamp<decltype(x - a / b - a)>(x - a / b - a, 0, 1); }
template<typename T>
constexpr auto pulse = [](T a, T b, T x) -> float { return step<T>(a, x) - step<T>(b, x); }
auto smoothstep = [](float a, float b, float x) -> float { if (x < a) return 0; else if (x >= b) return 1; x = boxstep<float>(a, b, x); return (x * x * (3 - x - x)); }
const auto gamacorrect = [](float gamma, float x) -> float { return std::powf(x, 1 / gamma); }
const auto bias = [](float b, float x) -> float { return std::powf(x, std::logf(b) / std::logf(0.5)); }
const auto gain = [](float g, float x) -> float { if (x < 0.5) return bias(1 - g, x + x) / 2; return 1 - bias(1 - g, 2 - x - x) / 2; }
constexpr auto Q_rsqrt = [](float number) -> float { constexpr float threehalfs = 1.5F; float const &x2{number * 0.5F}; float y{number}; long i{*(long *)&y}; i = 0x5f3759df - (i >> 1); y = *(float *)&i; y = y * (threehalfs - (x2 * y * y)); return y; }
constexpr auto Q_sqrt = [](float number) -> float { constexpr float threehalfs = 1.5F; float const &x2{number * 0.5F}; float y{number}; long i{*(long *)&y}; i = 0x5f3759df - (i >> 1); y = *(float *)&i; y = y * (threehalfs - (x2 * y * y)); return number * y; }
template<int Numerator, int Denominator>
struct Ceil

Public Types

enum [anonymous]

Values:

enumerator value
template<int I>
struct factorial

Public Types

enum [anonymous]

Values:

enumerator value
template<>
struct factorial<1>

Public Types

enum [anonymous]

Values:

enumerator value
template<int I>
struct fibonacci

Public Types

enum [anonymous]

Values:

enumerator value
template<>
struct fibonacci<1>

Public Types

enum [anonymous]

Values:

enumerator value
template<>
struct fibonacci<2>

Public Types

enum [anonymous]

Values:

enumerator value
template<int Numerator, int Denominator>
struct Floor

Public Types

enum [anonymous]

Values:

enumerator remain
enumerator value
template<int Numerator>
struct Floor<Numerator, 1>

Public Types

enum [anonymous]

Values:

enumerator value
template<int First, int Second>
struct modulus

Public Types

enum [anonymous]

Values:

enumerator value
template<int Base, int Expo>
struct power

Public Types

enum [anonymous]

Values:

enumerator value
template<int Expo>
struct power<0, Expo>

Public Types

enum [anonymous]

Values:

enumerator value
template<int Expo>
struct power<1, Expo>

Public Types

enum [anonymous]

Values:

enumerator value
template<int Base>
struct power<Base, 0>

Public Types

enum [anonymous]

Values:

enumerator value
template<int First, int... Rest>
struct product

Public Types

enum [anonymous]

Values:

enumerator value
template<int First, int Second>
struct product<First, Second>

Public Types

enum [anonymous]

Values:

enumerator value
template<int First, int... Rest>
struct sum

Public Types

enum [anonymous]

Values:

enumerator value
template<int First, int Second>
struct sum<First, Second>

Public Types

enum [anonymous]

Values:

enumerator value