This commit is contained in:
İsmail Yılmaz 2026-08-10 10:45:48 +05:30 committed by GitHub
commit b7626b5283
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View file

@ -261,11 +261,21 @@ void SeedRandom();
// Math utils
template <typename T>
inline T Lerp(T a, T b, double t)
constexpr inline T Lerp(T a, T b, double t) noexcept
{
return T(a * (1.0 - t) + b * t);
}
template <typename T, typename F>
constexpr inline T Lerp(const T& a, const T& b, double t, const F& easefn) noexcept // Avoid copying large vector types.
{
static_assert(std::is_invocable_r_v<double, F, double>,
"Upp::Lerp: Easing function must take and return a double");
const double e = easefn(t);
return T(a * (1.0 - e) + b * e);
}
inline double sqr (double a) { return a * a; }
inline double argsinh (double s) { return log(s + sqrt(s * s + 1)); }
inline double argcosh (double c) { ASSERT(c >= 1); return log(c + sqrt(c * c - 1)); }

View file

@ -125,12 +125,29 @@ Random after seeding it with fixed value.&]
[s3; &]
[s4; &]
[s5;:Upp`:`:Lerp`(T`,T`,double`): [@(0.0.255) template] <[@(0.0.255) typename]
T> T [* Lerp](T [*@3 a], T [*@3 b], [@(0.0.255) double] [*@3 t])&]
T>&]
[s5;:Upp`:`:Lerp`(T`,T`,double`): [@(0.0.255) constexpr] T [* Lerp](T
[*@3 a], T [*@3 b], [@(0.0.255) double] [*@3 t])&]
[s2; Computes the linear interpolation between [*@3 a] and [*@3 b], if
the parameter [*@3 t] is inside `[0,1`] (the linear extrapolation
otherwise).&]
[s3; &]
[s4; &]
[s5;:Upp`:`:Lerp`(const T`&`,const T`&`,double`,const F`&`): [@(0.0.255) template]
<[@(0.0.255) typename] T, [@(0.0.255) typename] F>&]
[s5;:Upp`:`:Lerp`(const T`&`,const T`&`,double`,const F`&`): [@(0.0.255) constexpr]
T [* Lerp]([@(0.0.255) const] T[@(0.0.255) `&] [*@3 a], [@(0.0.255) const]
T[@(0.0.255) `&] [*@3 b], [@(0.0.255) double] [*@3 t], [@(0.0.255) const]
F[@(0.0.255) `&] [*@3 easefn])&]
[s2; Computes the linear interpolation between [*@3 a] and [*@3 b], if
the parameter [*@3 t] is inside `[0,1`] (the linear extrapolation
otherwise).[@N Easing function ][*@3 easefn][@N can be used to achieve
different effects (bounce, ease`-in, ease`-out, etc.). Easing
function must take and return a ][@(0.0.255) double][@N . This overload
can also be used with large types (such as vectors and matrices
with defined operators).]&]
[s3; &]
[s4; &]
[s5;:ZeroArray`(x`): [* ZeroArray]([*@3 x])&]
[s2;%% Fills C array [%-*@3 x] with zeros.&]
[s3; &]