From e838c1b9e9031de742deeff763c06b1d39f399ef Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 14 Jun 2021 20:11:34 +0900 Subject: basegfx: use namespace for "ftools", make sure input is FP number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- basegfx/source/color/bcolortools.cxx | 2 +- include/basegfx/numeric/ftools.hxx | 33 +++++++++++++++++------------ svx/source/svdraw/svdotextdecomposition.cxx | 4 ++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/basegfx/source/color/bcolortools.cxx b/basegfx/source/color/bcolortools.cxx index 727b9c781774..160b48328966 100644 --- a/basegfx/source/color/bcolortools.cxx +++ b/basegfx/source/color/bcolortools.cxx @@ -152,7 +152,7 @@ namespace basegfx::utils } else { - if( fTools::equal(h,360) ) + if( fTools::equal(h, 360.0) ) h = 0; // 360 degrees is equivalent to 0 degrees h /= 60.0; 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 ::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 ::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 ::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 ::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 ::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 ::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 ::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 ::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 ::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 diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx index c2d5cd2301c8..c6f3bbdb8193 100644 --- a/svx/source/svdraw/svdotextdecomposition.cxx +++ b/svx/source/svdraw/svdotextdecomposition.cxx @@ -1188,8 +1188,8 @@ void SdrTextObj::impDecomposeStretchTextPrimitive( // now get back the laid out text size from outliner const Size aOutlinerTextSize(rOutliner.CalcTextSize()); const basegfx::B2DVector aOutlinerScale( - basegfx::fTools::equalZero(aOutlinerTextSize.Width()) ? 1.0 : aOutlinerTextSize.Width(), - basegfx::fTools::equalZero(aOutlinerTextSize.Height()) ? 1.0 : aOutlinerTextSize.Height()); + aOutlinerTextSize.Width() == tools::Long(0) ? 1.0 : aOutlinerTextSize.Width(), + aOutlinerTextSize.Height() == tools::Long(0) ? 1.0 : aOutlinerTextSize.Height()); // prepare matrices to apply to newly created primitives basegfx::B2DHomMatrix aNewTransformA; -- cgit