diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_base.hh | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/source/blender/blenlib/BLI_math_base.hh b/source/blender/blenlib/BLI_math_base.hh index 81f5343056e..034c6968c94 100644 --- a/source/blender/blenlib/BLI_math_base.hh +++ b/source/blender/blenlib/BLI_math_base.hh @@ -108,12 +108,20 @@ template<typename T, BLI_ENABLE_IF((is_math_float_type<FactorT>))> inline T interpolate(const T &a, const T &b, const FactorT &t) { - return a * (1 - t) + b * t; + auto result = a * (1 - t) + b * t; + if constexpr (std::is_integral_v<T> && std::is_floating_point_v<FactorT>) { + result = std::round(result); + } + return result; } template<typename T> inline T midpoint(const T &a, const T &b) { - return (a + b) * T(0.5); + auto result = (a + b) * T(0.5); + if constexpr (std::is_integral_v<T>) { + result = std::round(result); + } + return result; } } // namespace blender::math |