maths: add linear mixing function

This commit is contained in:
Danny Robson 2016-12-21 20:23:13 +11:00
parent e6115eb234
commit 0da8c189ec

View File

@ -582,7 +582,8 @@ namespace util {
// min/max clamping
template <typename T, typename U, typename V>
constexpr T
constexpr
T
limit (const T val, const U lo, const V hi)
{
assert (lo <= hi);
@ -596,6 +597,7 @@ namespace util {
//-------------------------------------------------------------------------
// clamped cubic hermite interpolation
template <typename T>
constexpr
T
smoothstep (T a, T b, T x)
{
@ -605,6 +607,18 @@ namespace util {
}
//-------------------------------------------------------------------------
template <typename U, typename T>
constexpr
std::enable_if_t<std::is_floating_point<T>::value, U>
mix (U a, U b, T t)
{
assert (t >= 0);
assert (t <= 1);
return a * (1 - t) + b * t;
}
///////////////////////////////////////////////////////////////////////////
// renormalisation of unit floating point and/or normalised integers