2#ifndef LIBSBX_MATH_SMOOTH_VALUE_HPP_
3#define LIBSBX_MATH_SMOOTH_VALUE_HPP_
9#include <libsbx/units/time.hpp>
11#include <libsbx/utility/logger.hpp>
15#include <libsbx/math/traits.hpp>
20enum class smoothing_mode : std::uint8_t {
25template<
typename Type>
28template<
typename Type>
31template<
floating_po
int Type>
34template<
typename Type>
35concept smoothable = is_smoothable_v<Type>;
37template<smoothable Type, smoothing_mode Mode>
42 using value_type = Type;
44 inline static constexpr auto mode = Mode;
54 template<
floating_po
int Ratio>
113 constexpr auto value()
const noexcept -> value_type {
117 constexpr operator value_type()
const noexcept {
121 constexpr void update(
const units::second& delta_time,
const value_type base_speed) {
122 const auto difference = _target - _current;
129 const auto step = _compute_step(difference, base_speed, delta_time);
132 if (std::abs(step) >= std::abs(difference)) {
146 constexpr auto _compute_step(
const value_type difference,
const value_type base_speed,
const units::second& delta_time)
const -> value_type {
148 case smoothing_mode::linear: {
149 return (difference > 0 ? 1 : -1) * base_speed * delta_time;
151 case smoothing_mode::proportional: {
152 return difference * base_speed * delta_time;
165template<smoothable Type>
172template<smoothable Type>
Definition: smooth_value.hpp:38
Definition: quantity.hpp:66
Generic math algorithms and helpers.
constexpr auto mix(const Type x, const Type y, const Type a) -> Type
Linearly interpolates between two values.
Definition: algorithm.ipp:7
Core numeric concepts and type traits.
Definition: traits.hpp:11
Definition: smooth_value.hpp:26