diff --git a/maths.cpp b/maths.cpp index 2738af6a..b33c64c7 100644 --- a/maths.cpp +++ b/maths.cpp @@ -19,6 +19,8 @@ #include "maths.hpp" +#include "debug.hpp" + #include "float.hpp" #include @@ -174,3 +176,11 @@ sign (double val) { template int sign (int); + +//----------------------------------------------------------------------------- +// Simple instantiations. Some functions aren't used internally to the library +// so it's easier to instantiate early and check for broken code at library +// build time. + +template float smoothstep (float, float, float); +template double smoothstep (double, double, double); diff --git a/maths.hpp b/maths.hpp index d0c5b128..a7c5b756 100644 --- a/maths.hpp +++ b/maths.hpp @@ -20,6 +20,8 @@ #ifndef __MATHS_HPP #define __MATHS_HPP +#include "debug.hpp" + #include #include #include @@ -284,6 +286,17 @@ limit [[gnu::pure]] (const T val, const U hi, const V lo) } +// clamped cubic hermite interpolation +template +T +smoothstep [[gnu::pure]] (T a, T b, T x) +{ + CHECK_LE(a, b); + x = limit ((x - a) / (b - a), T{0}, T{1}); + return x * x * (3 - 2 * x); +} + + #include "maths.ipp" #endif // __MATHS_HPP