aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/alnumeric.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/common/alnumeric.h b/common/alnumeric.h
index d3d0edfd..8d13f9bf 100644
--- a/common/alnumeric.h
+++ b/common/alnumeric.h
@@ -67,6 +67,19 @@ constexpr inline size_t clampz(size_t val, size_t min, size_t max) noexcept
{ return minz(max, maxz(min, val)); }
+constexpr inline float lerp(float val1, float val2, float mu) noexcept
+{ return val1 + (val2-val1)*mu; }
+constexpr inline float cubic(float val1, float val2, float val3, float val4, float mu) noexcept
+{
+ const float mu2{mu*mu}, mu3{mu2*mu};
+ const float a0{-0.5f*mu3 + mu2 + -0.5f*mu};
+ const float a1{ 1.5f*mu3 + -2.5f*mu2 + 1.0f};
+ const float a2{-1.5f*mu3 + 2.0f*mu2 + 0.5f*mu};
+ const float a3{ 0.5f*mu3 + -0.5f*mu2};
+ return val1*a0 + val2*a1 + val3*a2 + val4*a3;
+}
+
+
/** Find the next power-of-2 for non-power-of-2 numbers. */
inline uint32_t NextPowerOf2(uint32_t value) noexcept
{