Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_math_base.hh
| Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| template<typename T, | template<typename T, | ||||
| typename FactorT, | typename FactorT, | ||||
| BLI_ENABLE_IF((std::is_arithmetic_v<T>)), | BLI_ENABLE_IF((std::is_arithmetic_v<T>)), | ||||
| BLI_ENABLE_IF((is_math_float_type<FactorT>))> | BLI_ENABLE_IF((is_math_float_type<FactorT>))> | ||||
| inline T interpolate(const T &a, const T &b, const FactorT &t) | 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) | template<typename T> inline T midpoint(const T &a, const T &b) | ||||
| { | { | ||||
| return (a + b) * T(0.5); | return (a + b) * T(0.5); | ||||
HooglyBoogly: This could use a `std::round` too probably, to make negative numbers consistent. | |||||
| } | } | ||||
| } // namespace blender::math | } // namespace blender::math | ||||
This could use a std::round too probably, to make negative numbers consistent.