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
>
autoclamp
= [](T val, T min, T max) { if (val < min) val = min; if (val > max) val = max; return val; }¶
-
template<class
T
>
constexpr autolerp
= [](T a, T b, float pct) -> decltype(a + (b - a) * pct) { return a + (b - a) * pct; }¶
-
template<class
T
>
constexpr autoblerp
= [](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 autobezier_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 autostep
= [](T a, T b) -> float { return static_cast<float>(a <= b); }¶
-
template<typename
T
>
constexpr autoboxstep
= [](T a, T b, T x) -> float { return clamp<decltype(x - a / b - a)>(x - a / b - a, 0, 1); }¶
-
template<typename
T
>
constexpr autopulse
= [](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
, intDenominator
>
structCeil
¶
-
template<int
I
>
structfactorial
¶
-
template<>
structfactorial
<1>¶
-
template<int
I
>
structfibonacci
¶
-
template<>
structfibonacci
<1>¶
-
template<>
structfibonacci
<2>¶
-
template<int
Numerator
, intDenominator
>
structFloor
¶
-
template<int
First
, intSecond
>
structmodulus
¶
-
template<int
Base
, intExpo
>
structpower
¶
-
template<int
First
, int...Rest
>
structproduct
¶
-
template<int
First
, int...Rest
>
structsum
¶
-
constexpr float