26constexpr inline Type
lerp(Type input_lower_bound, Type input_upper_bound,
float percentage_zero_to_one)
29 if constexpr (std::is_floating_point<Type>::value)
30 return std::lerp(input_lower_bound, input_upper_bound, percentage_zero_to_one);
32 return (input_upper_bound - input_lower_bound) * percentage_zero_to_one + input_lower_bound;
46constexpr inline Type
mix(Type input_lower_bound, Type input_upper_bound,
float percentage_zero_to_one)
48 return Math::lerp(input_lower_bound, input_upper_bound, percentage_zero_to_one);
60constexpr inline Type
inverse_lerp(Type input_lower_bound, Type input_upper_bound, Type value_between)
62 return (value_between - input_lower_bound) / (input_upper_bound - input_lower_bound);
80constexpr inline Type
remap(Type input_value, Type orig_range_min, Type orig_range_max, Type new_range_min, Type new_range_max)
82 return lerp(new_range_min, new_range_max,
inverse_lerp(orig_range_min, orig_range_max, input_value));
94constexpr inline const Type &
saturate(
const Type &value,
const Type &lower_bound,
const Type &upper_bound)
96 return std::clamp( value, lower_bound, upper_bound );
100constexpr inline Type
step(Type y, Type x)
102 return (x >= y) ? 1 : 0;
105constexpr inline float smoothstep(
float input_value,
float left_edge = 0.0f,
float right_edge = 1.0f)
108 input_value = std::clamp<float>((input_value - left_edge) / (right_edge - left_edge), 0.0f, 1.0f);
110 return input_value * input_value * (3.0f - 2.0f * input_value);
115constexpr inline Type
smootherstep(Type input_value, Type left_edge, Type right_edge)
118 input_value = std::clamp((input_value - left_edge) / (right_edge - left_edge), Type{0}, Type{1});
119 if constexpr (std::is_same<Type, float>::value)
120 return input_value * input_value * input_value * (input_value * (6.0f * input_value - 15.0f) + 10.0f);
122 return input_value * input_value * input_value * (input_value * (6.0 * input_value - 15.0) + 10.0);
125template <
class Type =
float>
129 input_value = std::clamp<Type>((input_value - left_edge) / (right_edge - left_edge), Type{0}, Type{1});
135 Type accumulation = 0;
137 for (
int n = 0; n <= Order; ++n)
139 Type part0 = std::pow(
static_cast<Type
>(-1),
static_cast<Type
>(n));
142 Type part3 = std::pow( input_value,
static_cast<Type
>(Order + n + 1) );
144 accumulation += part0 *
static_cast<Type
>(part1) *
static_cast<Type
>(part2) * part3;
149template <
class Type =
float>
152 return Type{0.5} - std::sin( std::asin(Type{1.0} - Type{2.0} * std::clamp<Type>(input_value, Type{0}, Type{1})) / Type{3.0} );
158 return std::modf(input);
constexpr int binomial_coefficient(int row, int column)
constexpr Type smoothstep_generalized(Type input_value, Type left_edge=0, Type right_edge=1, int Order=1)
constexpr Type lerp(Type input_lower_bound, Type input_upper_bound, float percentage_zero_to_one)
constexpr Type remap(Type input_value, Type orig_range_min, Type orig_range_max, Type new_range_min, Type new_range_max)
constexpr Type inverse_lerp(Type input_lower_bound, Type input_upper_bound, Type value_between)
constexpr float smoothstep(float input_value, float left_edge=0.0f, float right_edge=1.0f)
constexpr const Type & saturate(const Type &value, const Type &lower_bound, const Type &upper_bound)
constexpr Type smootherstep(Type input_value, Type left_edge, Type right_edge)
constexpr Type mix(Type input_lower_bound, Type input_upper_bound, float percentage_zero_to_one)
constexpr Type step(Type y, Type x)
constexpr Type inverse_smoothstep(Type input_value)