[Libreoffice-commits] core.git: basegfx/source basegfx/test include/basegfx

Noel Grandin noel at peralex.com
Fri Jan 22 15:54:53 PST 2016


 basegfx/source/color/bcolortools.cxx           |    8 ++++----
 basegfx/source/polygon/b2dlinegeometry.cxx     |    2 +-
 basegfx/source/polygon/b2dpolygontools.cxx     |   22 +++++++++++-----------
 basegfx/source/polygon/b2dpolypolygontools.cxx |    6 +++---
 basegfx/source/polygon/b2dsvgpolypolygon.cxx   |    8 ++++----
 basegfx/source/tools/gradienttools.cxx         |    4 ++--
 basegfx/test/boxclipper.cxx                    |    2 +-
 include/basegfx/tuple/b2dtuple.hxx             |    4 ++--
 include/basegfx/tuple/b3dtuple.hxx             |    6 +++---
 9 files changed, 31 insertions(+), 31 deletions(-)

New commits:
commit 3fc292f7b32f30b98dad208eb03e086b927d38a2
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Jan 22 13:25:44 2016 +0200

    loplugin:fpcomparison in basegfx
    
    fix comparing of floating point values
    
    Change-Id: I54db66968cb999514747171eed82082612e0cac8
    Reviewed-on: https://gerrit.libreoffice.org/21708
    Reviewed-by: Armin Le Grand <Armin.Le.Grand at cib.de>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/basegfx/source/color/bcolortools.cxx b/basegfx/source/color/bcolortools.cxx
index 293deb8..7e139ac 100644
--- a/basegfx/source/color/bcolortools.cxx
+++ b/basegfx/source/color/bcolortools.cxx
@@ -43,9 +43,9 @@ namespace basegfx { namespace tools
             s = l > 0.5 ? d/(2.0-maxVal-minVal) :
                 d/(maxVal + minVal);
 
-            if( r == maxVal )
+            if( rtl::math::approxEqual(r, maxVal) )
                 h = (g - b)/d;
-            else if( g == maxVal )
+            else if( rtl::math::approxEqual(g, maxVal) )
                 h = 2.0 + (b - r)/d;
             else
                 h = 4.0 + (r - g)/d;
@@ -117,11 +117,11 @@ namespace basegfx { namespace tools
 
         if( !fTools::equalZero(s) )
         {
-            if( maxVal == r )
+            if( rtl::math::approxEqual(maxVal, r) )
             {
                 h = (g - b) / delta;
             }
-            else if( maxVal == g )
+            else if( rtl::math::approxEqual(maxVal, g) )
             {
                 h = 2.0 + (b - r) / delta;
             }
diff --git a/basegfx/source/polygon/b2dlinegeometry.cxx b/basegfx/source/polygon/b2dlinegeometry.cxx
index c259fef..2b6f6f9 100644
--- a/basegfx/source/polygon/b2dlinegeometry.cxx
+++ b/basegfx/source/polygon/b2dlinegeometry.cxx
@@ -715,7 +715,7 @@ namespace basegfx
                     double fCutPos(0.0);
                     tools::findCut(aStartPoint, rTangentPrev, aEndPoint, rTangentEdge, CutFlagValue::ALL, &fCutPos);
 
-                    if(0.0 != fCutPos)
+                    if(!rtl::math::approxEqual(0.0, fCutPos))
                     {
                         const B2DPoint aCutPoint(aStartPoint + (rTangentPrev * fCutPos));
                         aEdgePolygon.append(aCutPoint);
diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx
index 6f2542b..3eee5a5 100644
--- a/basegfx/source/polygon/b2dpolygontools.cxx
+++ b/basegfx/source/polygon/b2dpolygontools.cxx
@@ -200,7 +200,7 @@ namespace basegfx
                             // add curved edge and generate DistanceBound
                             double fBound(0.0);
 
-                            if(0.0 == fDistanceBound)
+                            if(rtl::math::approxEqual(0.0, fDistanceBound))
                             {
                                 // If not set, use B2DCubicBezier functionality to guess a rough value
                                 const double fRoughLength((aBezier.getEdgeLength() + aBezier.getControlPolygonLength()) / 2.0);
@@ -270,7 +270,7 @@ namespace basegfx
                     aRetval.append(aBezier.getStartPoint());
 
                     // #i37443# prepare convenient AngleBound if none was given
-                    if(0.0 == fAngleBound)
+                    if(rtl::math::approxEqual(0.0, fAngleBound))
                     {
 #ifdef DBG_UTIL
                         fAngleBound = fAngleBoundStartValue;
@@ -855,7 +855,7 @@ namespace basegfx
                                 bStartDone = true;
 
                                 // if same point, end is done, too.
-                                if(fFrom == fTo)
+                                if(rtl::math::approxEqual(fFrom, fTo))
                                 {
                                     bEndDone = true;
                                 }
@@ -1588,7 +1588,7 @@ namespace basegfx
                 fRadiusY = fOne;
             }
 
-            if(fZero == fRadiusX || fZero == fRadiusY)
+            if(rtl::math::approxEqual(fZero, fRadiusX) || rtl::math::approxEqual(fZero, fRadiusY))
             {
                 B2DPolygon aRetval;
 
@@ -1610,7 +1610,7 @@ namespace basegfx
 
                 return aRetval;
             }
-            else if(fOne == fRadiusX && fOne == fRadiusY)
+            else if(rtl::math::approxEqual(fOne, fRadiusX) && rtl::math::approxEqual(fOne, fRadiusY))
             {
                 // in both directions full radius, use ellipse
                 const B2DPoint aCenter(rRect.getCenter());
@@ -1627,7 +1627,7 @@ namespace basegfx
                 const double fKappa((M_SQRT2 - 1.0) * 4.0 / 3.0);
 
                 // create start point at bottom center
-                if(fOne != fRadiusX)
+                if(!rtl::math::approxEqual(fOne, fRadiusX))
                 {
                     const B2DPoint aBottomCenter(rRect.getCenter().getX(), rRect.getMaxY());
                     aRetval.append(aBottomCenter);
@@ -1673,7 +1673,7 @@ namespace basegfx
                 aRetval.setClosed( true );
 
                 // remove double created points if there are extreme radii involved
-                if(fOne == fRadiusX || fOne == fRadiusY)
+                if(rtl::math::approxEqual(fOne, fRadiusX) || rtl::math::approxEqual(fOne, fRadiusY))
                 {
                     aRetval.removeDoublePoints();
                 }
@@ -2235,7 +2235,7 @@ namespace basegfx
             /// return 0 for input of 0, -1 for negative and 1 for positive input
             inline int lcl_sgn( const double n )
             {
-                return n == 0.0 ? 0 : 1 - 2*int(rtl::math::isSignBitSet(n));
+                return rtl::math::approxEqual(n, 0.0) ? 0 : 1 - 2*int(rtl::math::isSignBitSet(n));
             }
         }
 
@@ -2484,7 +2484,7 @@ namespace basegfx
                     aBezier.setStartPoint(aBezier.getEndPoint());
                 }
 
-                if(1.0 == rCut)
+                if(rtl::math::approxEqual(1.0, rCut))
                 {
                     // correct rEdgeIndex when not last point
                     if(rCandidate.isClosed())
@@ -2531,7 +2531,7 @@ namespace basegfx
         {
             const sal_uInt32 nPointCount(rCandidate.count());
 
-            if(nPointCount && 0.0 != rOriginal.getWidth() && 0.0 != rOriginal.getHeight())
+            if(nPointCount && !rtl::math::approxEqual(0.0, rOriginal.getWidth()) && !rtl::math::approxEqual(0.0, rOriginal.getHeight()))
             {
                 B2DPolygon aRetval;
 
@@ -2770,7 +2770,7 @@ namespace basegfx
 
         B2DPolygon growInNormalDirection(const B2DPolygon& rCandidate, double fValue)
         {
-            if(0.0 != fValue)
+            if(!rtl::math::approxEqual(0.0, fValue))
             {
                 if(rCandidate.areControlPointsUsed())
                 {
diff --git a/basegfx/source/polygon/b2dpolypolygontools.cxx b/basegfx/source/polygon/b2dpolypolygontools.cxx
index 45c54f5..8bc7f58 100644
--- a/basegfx/source/polygon/b2dpolypolygontools.cxx
+++ b/basegfx/source/polygon/b2dpolypolygontools.cxx
@@ -233,7 +233,7 @@ namespace basegfx
 
         void applyLineDashing(const B2DPolyPolygon& rCandidate, const ::std::vector<double>& rDotDashArray, B2DPolyPolygon* pLineTarget, B2DPolyPolygon* pGapTarget, double fFullDashDotLen)
         {
-            if(0.0 == fFullDashDotLen && rDotDashArray.size())
+            if(rtl::math::approxEqual(0.0, fFullDashDotLen) && rDotDashArray.size())
             {
                 // calculate fFullDashDotLen from rDotDashArray
                 fFullDashDotLen = ::std::accumulate(rDotDashArray.begin(), rDotDashArray.end(), 0.0);
@@ -378,7 +378,7 @@ namespace basegfx
 
         B2DPolyPolygon growInNormalDirection(const B2DPolyPolygon& rCandidate, double fValue)
         {
-            if(0.0 != fValue)
+            if(!rtl::math::approxEqual(0.0, fValue))
             {
                 B2DPolyPolygon aRetval;
 
@@ -578,7 +578,7 @@ namespace basegfx
                     B2DPoint end  (corners[index2corner[j+1]],
                                    corners[index2corner[j+1]+1]);
 
-                    if( start.getX() == end.getX() )
+                    if( rtl::math::approxEqual(start.getX(), end.getX()) )
                     {
                         start.setY(start.getY()+fSegmentEndChopVert);
                         end.setY(end.getY()-fSegmentEndChopVert);
diff --git a/basegfx/source/polygon/b2dsvgpolypolygon.cxx b/basegfx/source/polygon/b2dsvgpolypolygon.cxx
index 25773e7..e472e97 100644
--- a/basegfx/source/polygon/b2dsvgpolypolygon.cxx
+++ b/basegfx/source/polygon/b2dsvgpolypolygon.cxx
@@ -471,10 +471,10 @@ namespace basegfx
                                 nY += nLastY;
                             }
 
-                            if( nX == nLastX && nY == nLastY )
+                            if( rtl::math::approxEqual(nX, nLastX) && rtl::math::approxEqual(nY, nLastY) )
                                 continue; // start==end -> skip according to SVG spec
 
-                            if( fRX == 0.0 || fRY == 0.0 )
+                            if( rtl::math::approxEqual(fRX, 0.0) || rtl::math::approxEqual(fRY, 0.0) )
                             {
                                 // straight line segment according to SVG spec
                                 aCurrPoly.append(B2DPoint(nX, nY));
@@ -857,8 +857,8 @@ namespace basegfx
                             }
                             else
                             {
-                                const bool bXEqual(aEdgeStart.getX() == aEdgeEnd.getX());
-                                const bool bYEqual(aEdgeStart.getY() == aEdgeEnd.getY());
+                                const bool bXEqual(rtl::math::approxEqual(aEdgeStart.getX(), aEdgeEnd.getX()));
+                                const bool bYEqual(rtl::math::approxEqual(aEdgeStart.getY(), aEdgeEnd.getY()));
 
                                 if(bXEqual && bYEqual)
                                 {
diff --git a/basegfx/source/tools/gradienttools.cxx b/basegfx/source/tools/gradienttools.cxx
index 11bd62f..e8f2f30 100644
--- a/basegfx/source/tools/gradienttools.cxx
+++ b/basegfx/source/tools/gradienttools.cxx
@@ -176,7 +176,7 @@ namespace basegfx
         aTextureTransform.translate(fTargetOffsetX, fTargetOffsetY);
 
         // prepare aspect for texture
-        const double fAspectRatio((0.0 != fTargetSizeY) ?  fTargetSizeX / fTargetSizeY : 1.0);
+        const double fAspectRatio(rtl::math::approxEqual(0.0, fTargetSizeY) ? 1.0 : (fTargetSizeX / fTargetSizeY));
 
         return ODFGradientInfo(aTextureTransform, fAspectRatio, nSteps);
     }
@@ -253,7 +253,7 @@ namespace basegfx
         aTextureTransform.translate(fTargetOffsetX, fTargetOffsetY);
 
         // prepare aspect for texture
-        const double fAspectRatio((0.0 != fTargetSizeY) ? fTargetSizeX / fTargetSizeY : 1.0);
+        const double fAspectRatio(rtl::math::approxEqual(0.0, fTargetSizeY) ? 1.0 : (fTargetSizeX / fTargetSizeY));
 
         return ODFGradientInfo(aTextureTransform, fAspectRatio, nSteps);
     }
diff --git a/basegfx/test/boxclipper.cxx b/basegfx/test/boxclipper.cxx
index d110468..0847a39 100644
--- a/basegfx/test/boxclipper.cxx
+++ b/basegfx/test/boxclipper.cxx
@@ -52,7 +52,7 @@ double getRandomOrdinal( const ::std::size_t n )
 inline bool compare(const B2DPoint& left, const B2DPoint& right)
 {
     return left.getX()<right.getX()
-        || (left.getX()==right.getX() && left.getY()<right.getY());
+        || (rtl::math::approxEqual(left.getX(),right.getX()) && left.getY()<right.getY());
 }
 
 class boxclipper : public CppUnit::TestFixture
diff --git a/include/basegfx/tuple/b2dtuple.hxx b/include/basegfx/tuple/b2dtuple.hxx
index 3819a5b..b6748a9 100644
--- a/include/basegfx/tuple/b2dtuple.hxx
+++ b/include/basegfx/tuple/b2dtuple.hxx
@@ -254,8 +254,8 @@ namespace basegfx
     inline B2DTuple average(const B2DTuple& rOld1, const B2DTuple& rOld2)
     {
         return B2DTuple(
-            rOld1.getX() == rOld2.getX() ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5,
-            rOld1.getY() == rOld2.getY() ? rOld1.getY() : (rOld1.getY() + rOld2.getY()) * 0.5);
+            rtl::math::approxEqual(rOld1.getX(), rOld2.getX()) ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5,
+            rtl::math::approxEqual(rOld1.getY(), rOld2.getY()) ? rOld1.getY() : (rOld1.getY() + rOld2.getY()) * 0.5);
     }
 
     inline B2DTuple operator+(const B2DTuple& rTupA, const B2DTuple& rTupB)
diff --git a/include/basegfx/tuple/b3dtuple.hxx b/include/basegfx/tuple/b3dtuple.hxx
index 842e3bc..30b95be 100644
--- a/include/basegfx/tuple/b3dtuple.hxx
+++ b/include/basegfx/tuple/b3dtuple.hxx
@@ -308,9 +308,9 @@ namespace basegfx
     inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2)
     {
         return B3DTuple(
-            rOld1.getX() == rOld2.getX() ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5,
-            rOld1.getY() == rOld2.getY() ? rOld1.getY() : (rOld1.getY() + rOld2.getY()) * 0.5,
-            rOld1.getZ() == rOld2.getZ() ? rOld1.getZ() : (rOld1.getZ() + rOld2.getZ()) * 0.5);
+            rtl::math::approxEqual(rOld1.getX(), rOld2.getX()) ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5,
+            rtl::math::approxEqual(rOld1.getY(), rOld2.getY()) ? rOld1.getY() : (rOld1.getY() + rOld2.getY()) * 0.5,
+            rtl::math::approxEqual(rOld1.getZ(), rOld2.getZ()) ? rOld1.getZ() : (rOld1.getZ() + rOld2.getZ()) * 0.5);
     }
 
     inline B3DTuple operator+(const B3DTuple& rTupA, const B3DTuple& rTupB)


More information about the Libreoffice-commits mailing list