1#ifndef LIBSBX_MATH_SMOOTH_VALUE_HPP_
2#define LIBSBX_MATH_SMOOTH_VALUE_HPP_
8#include <libsbx/units/time.hpp>
10#include <libsbx/utility/logger.hpp>
12#include <libsbx/math/concepts.hpp>
13#include <libsbx/math/constants.hpp>
14#include <libsbx/math/traits.hpp>
15#include <libsbx/math/algorithm.hpp>
19enum class smoothing_mode : std::uint8_t {
24template<
typename Type>
27template<
typename Type>
30template<
floating_po
int Type>
33template<
typename Type>
34concept smoothable = is_smoothable_v<Type>;
36template<smoothable Type, smoothing_mode Mode>
41 using value_type = Type;
43 inline static constexpr auto mode = Mode;
53 template<
floating_po
int Ratio>
112 constexpr auto value()
const noexcept -> value_type {
116 constexpr operator value_type()
const noexcept {
120 constexpr void update(
const units::second& delta_time,
const value_type base_speed) {
121 const auto difference = _target - _current;
128 const auto step = _compute_step(difference, base_speed, delta_time);
131 if (std::abs(step) >= std::abs(difference)) {
145 constexpr auto _compute_step(
const value_type difference,
const value_type base_speed,
const units::second& delta_time)
const -> value_type {
147 case smoothing_mode::linear: {
148 return (difference > 0 ? 1 : -1) * base_speed * delta_time;
150 case smoothing_mode::proportional: {
151 return difference * base_speed * delta_time;
164template<smoothable Type>
171template<smoothable Type>
Definition: smooth_value.hpp:37
Definition: quantity.hpp:65
Definition: traits.hpp:10
Definition: smooth_value.hpp:25