Skip to content

Commit d8c4a4d

Browse files
committed
add smooth
1 parent 6a97301 commit d8c4a4d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/gf2/core/Math.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifndef GF_MATH_H
44
#define GF_MATH_H
55

6+
#include <cassert>
67
#include <cmath>
78

89
#include <limits>
@@ -129,6 +130,13 @@ namespace gf {
129130
return (T(1) - std::cos(constants::Pi<T> * t)) * T(0.5);
130131
}
131132

133+
template<typename T>
134+
inline T smooth(T x, T lo, T hi, Step<T> func = cubic_step)
135+
{
136+
assert(!almost_equals(lo, hi));
137+
return func(details::min(T(1), details::max(T(0), (x - lo) / (hi - lo))));
138+
}
139+
132140
template<typename T, typename U>
133141
constexpr T lerp(T lhs, T rhs, U t)
134142
{

0 commit comments

Comments
 (0)