diff options
author | Noel Grandin <noel@peralex.com> | 2016-01-22 13:25:44 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2016-01-22 23:54:20 +0000 |
commit | 3fc292f7b32f30b98dad208eb03e086b927d38a2 (patch) | |
tree | 94c0fcc02274e24d354fda24d3bfb251a9c2e3a5 /basegfx/source | |
parent | d8df6631ac173a920be834096c522014732ac151 (diff) |
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@cib.de>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'basegfx/source')
-rw-r--r-- | basegfx/source/color/bcolortools.cxx | 8 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dlinegeometry.cxx | 2 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dpolygontools.cxx | 22 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dpolypolygontools.cxx | 6 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dsvgpolypolygon.cxx | 8 | ||||
-rw-r--r-- | basegfx/source/tools/gradienttools.cxx | 4 |
6 files changed, 25 insertions, 25 deletions
diff --git a/basegfx/source/color/bcolortools.cxx b/basegfx/source/color/bcolortools.cxx index 293deb836517..7e139ac83263 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 c259fef49504..2b6f6f95e999 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 6f2542b06838..3eee5a5377f9 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 45c54f5ba861..8bc7f580701c 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 25773e7fac40..e472e97b6c61 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 11bd62f61843..e8f2f3091d4f 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); } |