maths: add linear mixing function
This commit is contained in:
parent
e6115eb234
commit
0da8c189ec
16
maths.hpp
16
maths.hpp
@ -582,7 +582,8 @@ namespace util {
|
|||||||
|
|
||||||
// min/max clamping
|
// min/max clamping
|
||||||
template <typename T, typename U, typename V>
|
template <typename T, typename U, typename V>
|
||||||
constexpr T
|
constexpr
|
||||||
|
T
|
||||||
limit (const T val, const U lo, const V hi)
|
limit (const T val, const U lo, const V hi)
|
||||||
{
|
{
|
||||||
assert (lo <= hi);
|
assert (lo <= hi);
|
||||||
@ -596,6 +597,7 @@ namespace util {
|
|||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// clamped cubic hermite interpolation
|
// clamped cubic hermite interpolation
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
constexpr
|
||||||
T
|
T
|
||||||
smoothstep (T a, T b, T x)
|
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
|
// renormalisation of unit floating point and/or normalised integers
|
||||||
|
Loading…
Reference in New Issue
Block a user