diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index b2ce339e1f..af75bb4fb3 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -10,6 +10,8 @@ #ifndef MATH_FUNC_HPP #define MATH_FUNC_HPP +#include "strong_typedef_type.hpp" + #include #include @@ -164,7 +166,7 @@ static inline uint ClampU(const uint a, const uint min, const uint max) * for the return type. * @see Clamp(int, int, int) */ -template +template ::value, int> = 0> constexpr To ClampTo(From value) { static_assert(std::numeric_limits::is_integer, "Do not clamp from non-integer values"); @@ -215,6 +217,15 @@ constexpr To ClampTo(From value) return static_cast(std::min(value, std::numeric_limits::max())); } +/** + * Specialization of ClampTo for #StrongType::Typedef. + */ +template ::value, int> = 0> +constexpr To ClampTo(From value) +{ + return ClampTo(value.base()); +} + /** * Returns the (absolute) difference between two (scalar) variables * @@ -256,10 +267,14 @@ static inline bool IsInsideBS(const T x, const size_t base, const size_t size) * @param max The maximum of the interval * @see IsInsideBS() */ -template -static inline constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) +template , std::is_base_of>, int> = 0> +static constexpr inline bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept { - return (size_t)(x - min) < (max - min); + if constexpr (std::is_base_of_v) { + return (size_t)(x.base() - min) < (max - min); + } else { + return (size_t)(x - min) < (max - min); + } } /**