diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-06-14 20:11:34 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-06-16 10:47:27 +0200 |
commit | e838c1b9e9031de742deeff763c06b1d39f399ef (patch) | |
tree | 348e261e849cfa607b4117f7e788ca24d1a52d80 /include/basegfx | |
parent | bf6dabe0ebad3cc5bc0edc04ae74fba0190b6203 (diff) |
basegfx: use namespace for "ftools", make sure input is FP number
Don't use empty class with static methods for ftools, but just
use namespace instead. Also make sure it works with any floating
point numbers (float and double) and don't allow input if it is
anything else than a floating point number
Change-Id: I94b964291b3999d38ae13afe6ddfdbe6d891d410
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117154
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include/basegfx')
-rw-r--r-- | include/basegfx/numeric/ftools.hxx | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/include/basegfx/numeric/ftools.hxx b/include/basegfx/numeric/ftools.hxx index 54a8436f86a5..b72f069cb875 100644 --- a/include/basegfx/numeric/ftools.hxx +++ b/include/basegfx/numeric/ftools.hxx @@ -166,60 +166,67 @@ namespace basegfx */ BASEGFX_DLLPUBLIC double normalizeToRange(double v, const double fRange); - class BASEGFX_DLLPUBLIC fTools + namespace fTools { - public: /// Get threshold value for equalZero and friends - static double getSmallValue() { return 0.000000001f; } + inline double getSmallValue() { return 0.000000001f; } /// Compare against small value - static bool equalZero(const double& rfVal) + template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false> + inline bool equalZero(const T& rfVal) { return (fabs(rfVal) <= getSmallValue()); } /// Compare against given small value - static bool equalZero(const double& rfVal, const double& rfSmallValue) + template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false> + inline bool equalZero(const T& rfVal, const T& rfSmallValue) { return (fabs(rfVal) <= rfSmallValue); } - static bool equal(const double& rfValA, const double& rfValB) + template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false> + inline bool equal(T const& rfValA, T const& rfValB) { // changed to approxEqual usage for better numerical correctness return rtl_math_approxEqual(rfValA, rfValB); } - static bool equal(const double& rfValA, const double& rfValB, const double& rfSmallValue) + template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false> + inline bool equal(const T& rfValA, const T& rfValB, const T& rfSmallValue) { return (fabs(rfValA - rfValB) <= rfSmallValue); } - static bool less(const double& rfValA, const double& rfValB) + template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false> + inline bool less(const T& rfValA, const T& rfValB) { return (rfValA < rfValB && !equal(rfValA, rfValB)); } - static bool lessOrEqual(const double& rfValA, const double& rfValB) + template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false> + inline bool lessOrEqual(const T& rfValA, const T& rfValB) { return (rfValA < rfValB || equal(rfValA, rfValB)); } - static bool more(const double& rfValA, const double& rfValB) + template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false> + inline bool more(const T& rfValA, const T& rfValB) { return (rfValA > rfValB && !equal(rfValA, rfValB)); } - static bool moreOrEqual(const double& rfValA, const double& rfValB) + template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false> + inline bool moreOrEqual(const T& rfValA, const T& rfValB) { return (rfValA > rfValB || equal(rfValA, rfValB)); } - static bool betweenOrEqualEither(const double& rfValA, const double& rfValB, const double& rfValC) + template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false> + inline bool betweenOrEqualEither(const T& rfValA, const T& rfValB, const T& rfValC) { return (rfValA > rfValB && rfValA < rfValC) || equal(rfValA, rfValB) || equal(rfValA, rfValC); } - }; } // end of namespace basegfx |