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>
This commit is contained in:
Noel Grandin
2016-01-22 13:25:44 +02:00
committed by Thorsten Behrens
parent d8df6631ac
commit 3fc292f7b3
9 changed files with 31 additions and 31 deletions

View File

@@ -43,9 +43,9 @@ namespace basegfx { namespace tools
s = l > 0.5 ? d/(2.0-maxVal-minVal) : s = l > 0.5 ? d/(2.0-maxVal-minVal) :
d/(maxVal + minVal); d/(maxVal + minVal);
if( r == maxVal ) if( rtl::math::approxEqual(r, maxVal) )
h = (g - b)/d; h = (g - b)/d;
else if( g == maxVal ) else if( rtl::math::approxEqual(g, maxVal) )
h = 2.0 + (b - r)/d; h = 2.0 + (b - r)/d;
else else
h = 4.0 + (r - g)/d; h = 4.0 + (r - g)/d;
@@ -117,11 +117,11 @@ namespace basegfx { namespace tools
if( !fTools::equalZero(s) ) if( !fTools::equalZero(s) )
{ {
if( maxVal == r ) if( rtl::math::approxEqual(maxVal, r) )
{ {
h = (g - b) / delta; h = (g - b) / delta;
} }
else if( maxVal == g ) else if( rtl::math::approxEqual(maxVal, g) )
{ {
h = 2.0 + (b - r) / delta; h = 2.0 + (b - r) / delta;
} }

View File

@@ -715,7 +715,7 @@ namespace basegfx
double fCutPos(0.0); double fCutPos(0.0);
tools::findCut(aStartPoint, rTangentPrev, aEndPoint, rTangentEdge, CutFlagValue::ALL, &fCutPos); 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)); const B2DPoint aCutPoint(aStartPoint + (rTangentPrev * fCutPos));
aEdgePolygon.append(aCutPoint); aEdgePolygon.append(aCutPoint);

View File

@@ -200,7 +200,7 @@ namespace basegfx
// add curved edge and generate DistanceBound // add curved edge and generate DistanceBound
double fBound(0.0); 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 // If not set, use B2DCubicBezier functionality to guess a rough value
const double fRoughLength((aBezier.getEdgeLength() + aBezier.getControlPolygonLength()) / 2.0); const double fRoughLength((aBezier.getEdgeLength() + aBezier.getControlPolygonLength()) / 2.0);
@@ -270,7 +270,7 @@ namespace basegfx
aRetval.append(aBezier.getStartPoint()); aRetval.append(aBezier.getStartPoint());
// #i37443# prepare convenient AngleBound if none was given // #i37443# prepare convenient AngleBound if none was given
if(0.0 == fAngleBound) if(rtl::math::approxEqual(0.0, fAngleBound))
{ {
#ifdef DBG_UTIL #ifdef DBG_UTIL
fAngleBound = fAngleBoundStartValue; fAngleBound = fAngleBoundStartValue;
@@ -855,7 +855,7 @@ namespace basegfx
bStartDone = true; bStartDone = true;
// if same point, end is done, too. // if same point, end is done, too.
if(fFrom == fTo) if(rtl::math::approxEqual(fFrom, fTo))
{ {
bEndDone = true; bEndDone = true;
} }
@@ -1588,7 +1588,7 @@ namespace basegfx
fRadiusY = fOne; fRadiusY = fOne;
} }
if(fZero == fRadiusX || fZero == fRadiusY) if(rtl::math::approxEqual(fZero, fRadiusX) || rtl::math::approxEqual(fZero, fRadiusY))
{ {
B2DPolygon aRetval; B2DPolygon aRetval;
@@ -1610,7 +1610,7 @@ namespace basegfx
return aRetval; 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 // in both directions full radius, use ellipse
const B2DPoint aCenter(rRect.getCenter()); const B2DPoint aCenter(rRect.getCenter());
@@ -1627,7 +1627,7 @@ namespace basegfx
const double fKappa((M_SQRT2 - 1.0) * 4.0 / 3.0); const double fKappa((M_SQRT2 - 1.0) * 4.0 / 3.0);
// create start point at bottom center // create start point at bottom center
if(fOne != fRadiusX) if(!rtl::math::approxEqual(fOne, fRadiusX))
{ {
const B2DPoint aBottomCenter(rRect.getCenter().getX(), rRect.getMaxY()); const B2DPoint aBottomCenter(rRect.getCenter().getX(), rRect.getMaxY());
aRetval.append(aBottomCenter); aRetval.append(aBottomCenter);
@@ -1673,7 +1673,7 @@ namespace basegfx
aRetval.setClosed( true ); aRetval.setClosed( true );
// remove double created points if there are extreme radii involved // 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(); aRetval.removeDoublePoints();
} }
@@ -2235,7 +2235,7 @@ namespace basegfx
/// return 0 for input of 0, -1 for negative and 1 for positive input /// return 0 for input of 0, -1 for negative and 1 for positive input
inline int lcl_sgn( const double n ) 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()); aBezier.setStartPoint(aBezier.getEndPoint());
} }
if(1.0 == rCut) if(rtl::math::approxEqual(1.0, rCut))
{ {
// correct rEdgeIndex when not last point // correct rEdgeIndex when not last point
if(rCandidate.isClosed()) if(rCandidate.isClosed())
@@ -2531,7 +2531,7 @@ namespace basegfx
{ {
const sal_uInt32 nPointCount(rCandidate.count()); 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; B2DPolygon aRetval;
@@ -2770,7 +2770,7 @@ namespace basegfx
B2DPolygon growInNormalDirection(const B2DPolygon& rCandidate, double fValue) B2DPolygon growInNormalDirection(const B2DPolygon& rCandidate, double fValue)
{ {
if(0.0 != fValue) if(!rtl::math::approxEqual(0.0, fValue))
{ {
if(rCandidate.areControlPointsUsed()) if(rCandidate.areControlPointsUsed())
{ {

View File

@@ -233,7 +233,7 @@ namespace basegfx
void applyLineDashing(const B2DPolyPolygon& rCandidate, const ::std::vector<double>& rDotDashArray, B2DPolyPolygon* pLineTarget, B2DPolyPolygon* pGapTarget, double fFullDashDotLen) 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 // calculate fFullDashDotLen from rDotDashArray
fFullDashDotLen = ::std::accumulate(rDotDashArray.begin(), rDotDashArray.end(), 0.0); fFullDashDotLen = ::std::accumulate(rDotDashArray.begin(), rDotDashArray.end(), 0.0);
@@ -378,7 +378,7 @@ namespace basegfx
B2DPolyPolygon growInNormalDirection(const B2DPolyPolygon& rCandidate, double fValue) B2DPolyPolygon growInNormalDirection(const B2DPolyPolygon& rCandidate, double fValue)
{ {
if(0.0 != fValue) if(!rtl::math::approxEqual(0.0, fValue))
{ {
B2DPolyPolygon aRetval; B2DPolyPolygon aRetval;
@@ -578,7 +578,7 @@ namespace basegfx
B2DPoint end (corners[index2corner[j+1]], B2DPoint end (corners[index2corner[j+1]],
corners[index2corner[j+1]+1]); corners[index2corner[j+1]+1]);
if( start.getX() == end.getX() ) if( rtl::math::approxEqual(start.getX(), end.getX()) )
{ {
start.setY(start.getY()+fSegmentEndChopVert); start.setY(start.getY()+fSegmentEndChopVert);
end.setY(end.getY()-fSegmentEndChopVert); end.setY(end.getY()-fSegmentEndChopVert);

View File

@@ -471,10 +471,10 @@ namespace basegfx
nY += nLastY; 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 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 // straight line segment according to SVG spec
aCurrPoly.append(B2DPoint(nX, nY)); aCurrPoly.append(B2DPoint(nX, nY));
@@ -857,8 +857,8 @@ namespace basegfx
} }
else else
{ {
const bool bXEqual(aEdgeStart.getX() == aEdgeEnd.getX()); const bool bXEqual(rtl::math::approxEqual(aEdgeStart.getX(), aEdgeEnd.getX()));
const bool bYEqual(aEdgeStart.getY() == aEdgeEnd.getY()); const bool bYEqual(rtl::math::approxEqual(aEdgeStart.getY(), aEdgeEnd.getY()));
if(bXEqual && bYEqual) if(bXEqual && bYEqual)
{ {

View File

@@ -176,7 +176,7 @@ namespace basegfx
aTextureTransform.translate(fTargetOffsetX, fTargetOffsetY); aTextureTransform.translate(fTargetOffsetX, fTargetOffsetY);
// prepare aspect for texture // 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); return ODFGradientInfo(aTextureTransform, fAspectRatio, nSteps);
} }
@@ -253,7 +253,7 @@ namespace basegfx
aTextureTransform.translate(fTargetOffsetX, fTargetOffsetY); aTextureTransform.translate(fTargetOffsetX, fTargetOffsetY);
// prepare aspect for texture // 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); return ODFGradientInfo(aTextureTransform, fAspectRatio, nSteps);
} }

View File

@@ -52,7 +52,7 @@ double getRandomOrdinal( const ::std::size_t n )
inline bool compare(const B2DPoint& left, const B2DPoint& right) inline bool compare(const B2DPoint& left, const B2DPoint& right)
{ {
return left.getX()<right.getX() 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 class boxclipper : public CppUnit::TestFixture

View File

@@ -254,8 +254,8 @@ namespace basegfx
inline B2DTuple average(const B2DTuple& rOld1, const B2DTuple& rOld2) inline B2DTuple average(const B2DTuple& rOld1, const B2DTuple& rOld2)
{ {
return B2DTuple( return B2DTuple(
rOld1.getX() == rOld2.getX() ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5, rtl::math::approxEqual(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.getY(), rOld2.getY()) ? rOld1.getY() : (rOld1.getY() + rOld2.getY()) * 0.5);
} }
inline B2DTuple operator+(const B2DTuple& rTupA, const B2DTuple& rTupB) inline B2DTuple operator+(const B2DTuple& rTupA, const B2DTuple& rTupB)

View File

@@ -308,9 +308,9 @@ namespace basegfx
inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2) inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2)
{ {
return B3DTuple( return B3DTuple(
rOld1.getX() == rOld2.getX() ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5, rtl::math::approxEqual(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.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.getZ(), rOld2.getZ()) ? rOld1.getZ() : (rOld1.getZ() + rOld2.getZ()) * 0.5);
} }
inline B3DTuple operator+(const B3DTuple& rTupA, const B3DTuple& rTupB) inline B3DTuple operator+(const B3DTuple& rTupA, const B3DTuple& rTupB)