Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_math_base.hh
| Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | template<typename T> inline T distance(const T &a, const T &b) | ||||
| return std::abs(a - b); | return std::abs(a - b); | ||||
| } | } | ||||
| template<typename T, BLI_ENABLE_IF((is_math_float_type<T>))> inline T fract(const T &a) | template<typename T, BLI_ENABLE_IF((is_math_float_type<T>))> inline T fract(const T &a) | ||||
| { | { | ||||
| return a - std::floor(a); | return a - std::floor(a); | ||||
| } | } | ||||
| template<typename T> inline T sqrt(const T &a) | template<typename T> inline T sqrt(const T &a) | ||||
| { | { | ||||
| return std::sqrt(a); | return std::sqrt(a); | ||||
| } | } | ||||
| template<typename T> inline T cos(const T &a) | template<typename T> inline T cos(const T &a) | ||||
| { | { | ||||
| return std::cos(a); | return std::cos(a); | ||||
| } | } | ||||
| template<typename T> inline T sin(const T &a) | template<typename T> inline T sin(const T &a) | ||||
| { | { | ||||
| return std::sin(a); | return std::sin(a); | ||||
| } | } | ||||
| template<typename T> inline T tan(const T &a) | template<typename T> inline T tan(const T &a) | ||||
| { | { | ||||
| return std::tan(a); | return std::tan(a); | ||||
| } | } | ||||
| template<typename T> inline T acos(const T &a) | template<typename T> inline T acos(const T &a) | ||||
| { | { | ||||
| return std::acos(a); | return std::acos(a); | ||||
| } | } | ||||
| template<typename T> inline T asin(const T &a) | template<typename T> inline T asin(const T &a) | ||||
| { | { | ||||
| return std::asin(a); | return std::asin(a); | ||||
| } | } | ||||
| template<typename T> inline T atan(const T &a) | template<typename T> inline T atan(const T &a) | ||||
| { | { | ||||
| return std::atan(a); | return std::atan(a); | ||||
| } | } | ||||
HooglyBoogly: Any particular reasoning for adding these? So far it's seemed fine using `std::sin`, etc. in… | |||||
Done Inline ActionsThe std::sin is only defined for float, double, and IntegralType. Adding things to the std namespace is highly discouraged. It should be possible to use some higher level functions which indirectly use sine/cosine on something else. The statement that "currently you can just stick to std::sin" is a self-reinforcing barrier in a way of using those utilities for anything else that is not supported by std::sin. Unless the API is designed in a more flexible way you will not see actual cases when something outside of standard types is used. Designing the API in a flexible way is not that hard. sergey: The `std::sin` is only defined for `float`, `double`, and `IntegralType`. Adding things to the… | |||||
Done Inline ActionsThis wasn't meant to be part of the patch and should have been added to master directly. fclem: This wasn't meant to be part of the patch and should have been added to master directly. | |||||
| template<typename T> inline T atan2(const T &y, const T &x) | template<typename T> inline T atan2(const T &y, const T &x) | ||||
| { | { | ||||
| return std::atan2(y, x); | return std::atan2(y, x); | ||||
| } | } | ||||
| template<typename T> inline T hypot(const T &y, const T &x) | |||||
| { | |||||
| return std::hypot(y, x); | |||||
| } | |||||
| 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) | ||||
| { | { | ||||
| auto result = 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>) { | if constexpr (std::is_integral_v<T> && std::is_floating_point_v<FactorT>) { | ||||
| Show All 15 Lines | |||||
Any particular reasoning for adding these? So far it's seemed fine using std::sin, etc. in these cases