Kaydet (Commit) 3fc292f7 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Thorsten Behrens

loplugin:fpcomparison in basegfx

fix comparing of floating point values

Change-Id: I54db66968cb999514747171eed82082612e0cac8
Reviewed-on: https://gerrit.libreoffice.org/21708Reviewed-by: 's avatarArmin Le Grand <Armin.Le.Grand@cib.de>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst d8df6631
......@@ -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;
}
......
......@@ -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);
......
......@@ -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())
{
......
......@@ -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);
......
......@@ -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)
{
......
......@@ -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);
}
......
......@@ -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
......
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment