summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-06-14 20:11:34 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-06-16 10:47:27 +0200
commite838c1b9e9031de742deeff763c06b1d39f399ef (patch)
tree348e261e849cfa607b4117f7e788ca24d1a52d80
parentbf6dabe0ebad3cc5bc0edc04ae74fba0190b6203 (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>
-rw-r--r--basegfx/source/color/bcolortools.cxx2
-rw-r--r--include/basegfx/numeric/ftools.hxx33
-rw-r--r--svx/source/svdraw/svdotextdecomposition.cxx4
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 <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
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;