From 47e7a100d97eb60c5a23de194ce1e1cd059e7ffb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 16 Jun 2018 08:48:57 +1000 Subject: [PATCH] DBL_EPSILON -> numeric_limits --- python/core/auto_generated/qgis.sip.in | 2 +- src/core/geometry/qgsgeos.cpp | 16 +++++----- src/core/geometry/qgspolygon.cpp | 2 +- src/core/qgis.h | 2 +- tests/src/core/testqgsdistancearea.cpp | 4 +-- tests/src/core/testqgsgeometry.cpp | 38 ++++++++++++------------ tests/src/core/testqgsgeometryimport.cpp | 12 ++++---- tests/src/core/testqgsgeometryutils.cpp | 14 ++++----- tests/src/core/testqgslayout.cpp | 16 +++++----- tests/src/core/testqgslayoutitem.cpp | 28 ++++++++--------- tests/src/core/testqgslayoututils.cpp | 14 ++++----- tests/src/core/testqgsrasterlayer.cpp | 2 +- tests/src/core/testqgsrastersublayer.cpp | 4 +-- 13 files changed, 77 insertions(+), 77 deletions(-) diff --git a/python/core/auto_generated/qgis.sip.in b/python/core/auto_generated/qgis.sip.in index 68c576d6c92..1e60e0df7a1 100644 --- a/python/core/auto_generated/qgis.sip.in +++ b/python/core/auto_generated/qgis.sip.in @@ -100,7 +100,7 @@ Returns a string representation of a double :param precision: number of decimal places to retain %End -bool qgsDoubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON ); +bool qgsDoubleNear( double a, double b, double epsilon = 4 * std::numeric_limits::epsilon() ); %Docstring Compare two doubles (but allow some difference) diff --git a/src/core/geometry/qgsgeos.cpp b/src/core/geometry/qgsgeos.cpp index 18ca5b75dc5..3e7e7cc7d93 100644 --- a/src/core/geometry/qgsgeos.cpp +++ b/src/core/geometry/qgsgeos.cpp @@ -310,17 +310,17 @@ void QgsGeos::subdivideRecursive( const GEOSGeometry *currentPart, int maxNodes, if ( height <= 0 ) { - halfClipRect1.setYMinimum( halfClipRect1.yMinimum() - DBL_EPSILON ); - halfClipRect2.setYMinimum( halfClipRect2.yMinimum() - DBL_EPSILON ); - halfClipRect1.setYMaximum( halfClipRect1.yMaximum() + DBL_EPSILON ); - halfClipRect2.setYMaximum( halfClipRect2.yMaximum() + DBL_EPSILON ); + halfClipRect1.setYMinimum( halfClipRect1.yMinimum() - std::numeric_limits::epsilon() ); + halfClipRect2.setYMinimum( halfClipRect2.yMinimum() - std::numeric_limits::epsilon() ); + halfClipRect1.setYMaximum( halfClipRect1.yMaximum() + std::numeric_limits::epsilon() ); + halfClipRect2.setYMaximum( halfClipRect2.yMaximum() + std::numeric_limits::epsilon() ); } if ( width <= 0 ) { - halfClipRect1.setXMinimum( halfClipRect1.xMinimum() - DBL_EPSILON ); - halfClipRect2.setXMinimum( halfClipRect2.xMinimum() - DBL_EPSILON ); - halfClipRect1.setXMaximum( halfClipRect1.xMaximum() + DBL_EPSILON ); - halfClipRect2.setXMaximum( halfClipRect2.xMaximum() + DBL_EPSILON ); + halfClipRect1.setXMinimum( halfClipRect1.xMinimum() - std::numeric_limits::epsilon() ); + halfClipRect2.setXMinimum( halfClipRect2.xMinimum() - std::numeric_limits::epsilon() ); + halfClipRect1.setXMaximum( halfClipRect1.xMaximum() + std::numeric_limits::epsilon() ); + halfClipRect2.setXMaximum( halfClipRect2.xMaximum() + std::numeric_limits::epsilon() ); } geos::unique_ptr clipPart1( GEOSClipByRect_r( geosinit.ctxt, currentPart, halfClipRect1.xMinimum(), halfClipRect1.yMinimum(), halfClipRect1.xMaximum(), halfClipRect1.yMaximum() ) ); diff --git a/src/core/geometry/qgspolygon.cpp b/src/core/geometry/qgspolygon.cpp index d507c5affbf..9db1bca4f82 100644 --- a/src/core/geometry/qgspolygon.cpp +++ b/src/core/geometry/qgspolygon.cpp @@ -260,7 +260,7 @@ double QgsPolygon::pointDistanceToBoundary( double x, double y ) const ( x < ( bX - aX ) * ( y - aY ) / ( bY - aY ) + aX ) ) inside = !inside; - minimumDistance = std::min( minimumDistance, QgsGeometryUtils::sqrDistToLine( x, y, aX, aY, bX, bY, minDistX, minDistY, 4 * DBL_EPSILON ) ); + minimumDistance = std::min( minimumDistance, QgsGeometryUtils::sqrDistToLine( x, y, aX, aY, bX, bY, minDistX, minDistY, 4 * std::numeric_limits::epsilon() ) ); } } diff --git a/src/core/qgis.h b/src/core/qgis.h index 7d36e2804de..dadc31ac660 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -248,7 +248,7 @@ inline QString qgsDoubleToString( double a, int precision = 17 ) * \param b second double * \param epsilon maximum difference allowable between doubles */ -inline bool qgsDoubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON ) +inline bool qgsDoubleNear( double a, double b, double epsilon = 4 * std::numeric_limits::epsilon() ) { const double diff = a - b; return diff > -epsilon && diff <= epsilon; diff --git a/tests/src/core/testqgsdistancearea.cpp b/tests/src/core/testqgsdistancearea.cpp index 97aa8100d3d..9ff17f7911f 100644 --- a/tests/src/core/testqgsdistancearea.cpp +++ b/tests/src/core/testqgsdistancearea.cpp @@ -234,14 +234,14 @@ void TestQgsDistanceArea::collections() double result = myDa.measureLength( lines ); QGSCOMPARENEAR( result, 12006159, 1 ); result = myDa.measureArea( lines ); - QGSCOMPARENEAR( result, 0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( result, 0, 4 * std::numeric_limits::epsilon() ); //collection of polygons QgsGeometry polys( QgsGeometryFactory::geomFromWkt( QStringLiteral( "GeometryCollection( Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) ).release() ); result = myDa.measureArea( polys ); QGSCOMPARENEAR( result, 670434859475LL, 1 ); result = myDa.measureLength( polys ); - QGSCOMPARENEAR( result, 0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( result, 0, 4 * std::numeric_limits::epsilon() ); //mixed collection QgsGeometry mixed( QgsGeometryFactory::geomFromWkt( QStringLiteral( "GeometryCollection( LineString(0 36.53, 5.76 -48.16), LineString(0 25.54, 24.20 36.70), Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) ).release() ); diff --git a/tests/src/core/testqgsgeometry.cpp b/tests/src/core/testqgsgeometry.cpp index 2ff538672aa..f35ffc6e743 100644 --- a/tests/src/core/testqgsgeometry.cpp +++ b/tests/src/core/testqgsgeometry.cpp @@ -681,8 +681,8 @@ void TestQgsGeometry::point() //toQPointF QgsPoint p11a( 5.0, 9.0 ); QPointF result = p11a.toQPointF(); - QGSCOMPARENEAR( result.x(), 5.0, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( result.y(), 9.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( result.x(), 5.0, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( result.y(), 9.0, 4 * std::numeric_limits::epsilon() ); //to/from WKB QgsPoint p12( QgsWkbTypes::PointZM, 1.0, 2.0, 3.0, -4.0 ); @@ -4199,26 +4199,26 @@ void TestQgsGeometry::lineString() l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) ); QVERIFY( l35.closestSegment( QgsPoint( 5, 10 ), p, v ) < 0 ); l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) << QgsPoint( 10, 10 ) ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf ), 2.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf ), 2.0, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 5, 10 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 1 ) ); QCOMPARE( leftOf, -1 ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf ), 1.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf ), 1.0, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 8, 10 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 1 ) ); QCOMPARE( leftOf, -1 ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 9 ), p, v, &leftOf ), 1.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 9 ), p, v, &leftOf ), 1.0, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 8, 10 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 1 ) ); QCOMPARE( leftOf, 1 ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 9 ), p, v, &leftOf ), 2.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 9 ), p, v, &leftOf ), 2.0, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 10, 10 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 1 ) ); QCOMPARE( leftOf, 1 ); l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) << QgsPoint( 10, 10 ) << QgsPoint( 10, 15 ) ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 12 ), p, v, &leftOf ), 1.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 12 ), p, v, &leftOf ), 1.0, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 10, 12 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 2 ) ); QCOMPARE( leftOf, 1 ); @@ -4227,7 +4227,7 @@ void TestQgsGeometry::lineString() << QgsPoint( 6, 4 ) << QgsPoint( 4, 4 ) << QgsPoint( 5, 5 ) ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 2.35, 4 ), p, v, &leftOf ), 2.7225, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 2.35, 4 ), p, v, &leftOf ), 2.7225, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 4, 4 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 2 ) ); QCOMPARE( leftOf, -1 ); @@ -4236,7 +4236,7 @@ void TestQgsGeometry::lineString() << QgsPoint( 4, 4 ) << QgsPoint( 6, 4 ) << QgsPoint( 5, 5 ) ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 2.35, 4 ), p, v, &leftOf ), 2.7225, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 2.35, 4 ), p, v, &leftOf ), 2.7225, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 4, 4 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 1 ) ); QCOMPARE( leftOf, 1 ); @@ -4245,7 +4245,7 @@ void TestQgsGeometry::lineString() << QgsPoint( 6, 4 ) << QgsPoint( 4, 4 ) << QgsPoint( 5, 5 ) ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 3.5, 2 ), p, v, &leftOf ), 4.250000, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 3.5, 2 ), p, v, &leftOf ), 4.250000, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 4, 4 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 2 ) ); QCOMPARE( leftOf, -1 ); @@ -4254,7 +4254,7 @@ void TestQgsGeometry::lineString() << QgsPoint( 4, 4 ) << QgsPoint( 6, 4 ) << QgsPoint( 5, 5 ) ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 3.5, 2 ), p, v, &leftOf ), 4.250000, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 3.5, 2 ), p, v, &leftOf ), 4.250000, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 4, 4 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 1 ) ); QCOMPARE( leftOf, 1 ); @@ -4263,7 +4263,7 @@ void TestQgsGeometry::lineString() << QgsPoint( 1, 4 ) << QgsPoint( 2, 2 ) << QgsPoint( 1, 1 ) ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 1, 0 ), p, v, &leftOf ), 1, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 1, 0 ), p, v, &leftOf ), 1, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 1, 1 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 1 ) ); QCOMPARE( leftOf, -1 ); @@ -4272,7 +4272,7 @@ void TestQgsGeometry::lineString() << QgsPoint( 2, 2 ) << QgsPoint( 1, 4 ) << QgsPoint( 1, 1 ) ); - QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 1, 0 ), p, v, &leftOf ), 1, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 1, 0 ), p, v, &leftOf ), 1, 4 * std::numeric_limits::epsilon() ); QCOMPARE( p, QgsPoint( 1, 1 ) ); QCOMPARE( v, QgsVertexId( 0, 0, 1 ) ); QCOMPARE( leftOf, 1 ); @@ -4287,13 +4287,13 @@ void TestQgsGeometry::lineString() QCOMPARE( area, 1.0 ); l36.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) << QgsPoint( 10, 10 ) ); l36.sumUpArea( area ); - QGSCOMPARENEAR( area, -24, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( area, -24, 4 * std::numeric_limits::epsilon() ); l36.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 2, 0 ) << QgsPoint( 2, 2 ) ); l36.sumUpArea( area ); - QGSCOMPARENEAR( area, -22, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( area, -22, 4 * std::numeric_limits::epsilon() ); l36.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 2, 0 ) << QgsPoint( 2, 2 ) << QgsPoint( 0, 2 ) ); l36.sumUpArea( area ); - QGSCOMPARENEAR( area, -18, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( area, -18, 4 * std::numeric_limits::epsilon() ); //boundingBox - test that bounding box is updated after every modification to the line string QgsLineString l37; @@ -4342,8 +4342,8 @@ void TestQgsGeometry::lineString() QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 1.5708, 0.0001 ); ( void )l38.vertexAngle( QgsVertexId( 0, 0, 2 ) ); //no crash l38.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 0, 1 ) ); - QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 0.0, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 0.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 0.0, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 0.0, 4 * std::numeric_limits::epsilon() ); l38.setPoints( QgsPointSequence() << QgsPoint( 1, 0 ) << QgsPoint( 0, 0 ) ); QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 4.71239, 0.0001 ); QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 4.71239, 0.0001 ); @@ -10927,7 +10927,7 @@ void TestQgsGeometry::compoundCurve() << QgsPoint( 1, 1 ) ); double lsArea = 0.0; ls.sumUpArea( lsArea ); - QGSCOMPARENEAR( ccArea, lsArea, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( ccArea, lsArea, 4 * std::numeric_limits::epsilon() ); //addVertex diff --git a/tests/src/core/testqgsgeometryimport.cpp b/tests/src/core/testqgsgeometryimport.cpp index 1c73d24bd92..72b60c27e13 100644 --- a/tests/src/core/testqgsgeometryimport.cpp +++ b/tests/src/core/testqgsgeometryimport.cpp @@ -85,8 +85,8 @@ void TestQgsGeometryImport::pointWkt() QCOMPARE( geom.wkbType(), QgsWkbTypes::Point ); QgsPointXY point = geom.asPoint(); - QGSCOMPARENEAR( point.x(), x, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( point.y(), y, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( point.x(), x, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( point.y(), y, 4 * std::numeric_limits::epsilon() ); } void TestQgsGeometryImport::pointWkb_data() @@ -113,8 +113,8 @@ void TestQgsGeometryImport::pointWkb() QgsPointXY point = geom.asPoint(); QCOMPARE( geom.wkbType(), QgsWkbTypes::Point ); - QGSCOMPARENEAR( point.x(), x, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( point.y(), y, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( point.x(), x, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( point.y(), y, 4 * std::numeric_limits::epsilon() ); } void TestQgsGeometryImport::pointGeos_data() @@ -140,8 +140,8 @@ void TestQgsGeometryImport::pointGeos() QgsPointXY geomPt = geom.asPoint(); - QGSCOMPARENEAR( x, geomPt.x(), 4 * DBL_EPSILON ); - QGSCOMPARENEAR( y, geomPt.y(), 4 * DBL_EPSILON ); + QGSCOMPARENEAR( x, geomPt.x(), 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( y, geomPt.y(), 4 * std::numeric_limits::epsilon() ); } void TestQgsGeometryImport::linestringWkt_data() diff --git a/tests/src/core/testqgsgeometryutils.cpp b/tests/src/core/testqgsgeometryutils.cpp index 51b3535aa82..7211a64f2be 100644 --- a/tests/src/core/testqgsgeometryutils.cpp +++ b/tests/src/core/testqgsgeometryutils.cpp @@ -211,8 +211,8 @@ void TestQgsGeometryUtils::testSegmentMidPoint() midPoint, radius, left ); QVERIFY( ok ); - QGSCOMPARENEAR( midPoint.x(), expectedX, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( midPoint.y(), expectedY, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( midPoint.x(), expectedX, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( midPoint.y(), expectedY, 4 * std::numeric_limits::epsilon() ); } void TestQgsGeometryUtils::testSegmentMidPointCenter() @@ -266,7 +266,7 @@ void TestQgsGeometryUtils::testCircleLength() QFETCH( double, y3 ); QFETCH( double, expected ); - QGSCOMPARENEAR( expected, QgsGeometryUtils::circleLength( x1, y1, x2, y2, x3, y3 ), 4 * DBL_EPSILON ); + QGSCOMPARENEAR( expected, QgsGeometryUtils::circleLength( x1, y1, x2, y2, x3, y3 ), 4 * std::numeric_limits::epsilon() ); } void TestQgsGeometryUtils::testNormalizedAngle_data() @@ -323,7 +323,7 @@ void TestQgsGeometryUtils::testLineAngle() double lineAngle = QgsGeometryUtils::lineAngle( x1, y1, x2, y2 ) * 180 / M_PI; if ( expected > -99999 ) - QGSCOMPARENEAR( lineAngle, expected, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( lineAngle, expected, 4 * std::numeric_limits::epsilon() ); } void TestQgsGeometryUtils::testLinePerpendicularAngle_data() @@ -530,9 +530,9 @@ void TestQgsGeometryUtils::testCircleCenterRadius() double radius, centerX, centerY; QgsGeometryUtils::circleCenterRadius( QgsPoint( x1, y1 ), QgsPoint( x2, y2 ), QgsPoint( x3, y3 ), radius, centerX, centerY ); - QGSCOMPARENEAR( expectedRadius, radius, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( expectedCenterX, centerX, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( expectedCenterY, centerY, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( expectedRadius, radius, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( expectedCenterX, centerX, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( expectedCenterY, centerY, 4 * std::numeric_limits::epsilon() ); } //QgsGeometryUtils::sqrDistToLine diff --git a/tests/src/core/testqgslayout.cpp b/tests/src/core/testqgslayout.cpp index ba1287fbac7..3628f4f0e7d 100644 --- a/tests/src/core/testqgslayout.cpp +++ b/tests/src/core/testqgslayout.cpp @@ -841,9 +841,9 @@ void TestQgsLayout::georeference() t = exporter.computeGeoTransform( map ); QGSCOMPARENEAR( t[0], 1925.0, 1.0 ); QGSCOMPARENEAR( t[1], 0.211719, 0.0001 ); - QGSCOMPARENEAR( t[2], 0.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( t[2], 0.0, 4 * std::numeric_limits::epsilon() ); QGSCOMPARENEAR( t[3], 3050, 1 ); - QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( t[4], 0.0, 4 * std::numeric_limits::epsilon() ); QGSCOMPARENEAR( t[5], -0.211694, 0.0001 ); t.reset(); @@ -852,9 +852,9 @@ void TestQgsLayout::georeference() t = exporter.computeGeoTransform(); QGSCOMPARENEAR( t[0], 1925.0, 1.0 ); QGSCOMPARENEAR( t[1], 0.211719, 0.0001 ); - QGSCOMPARENEAR( t[2], 0.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( t[2], 0.0, 4 * std::numeric_limits::epsilon() ); QGSCOMPARENEAR( t[3], 3050, 1 ); - QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( t[4], 0.0, 4 * std::numeric_limits::epsilon() ); QGSCOMPARENEAR( t[5], -0.211694, 0.0001 ); t.reset(); @@ -862,9 +862,9 @@ void TestQgsLayout::georeference() t = exporter.computeGeoTransform( map, QRectF( 70, 100, 50, 60 ) ); QGSCOMPARENEAR( t[0], 2100.0, 1.0 ); QGSCOMPARENEAR( t[1], 0.211864, 0.0001 ); - QGSCOMPARENEAR( t[2], 0.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( t[2], 0.0, 4 * std::numeric_limits::epsilon() ); QGSCOMPARENEAR( t[3], 2800, 1 ); - QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( t[4], 0.0, 4 * std::numeric_limits::epsilon() ); QGSCOMPARENEAR( t[5], -0.211864, 0.0001 ); t.reset(); @@ -872,9 +872,9 @@ void TestQgsLayout::georeference() t = exporter.computeGeoTransform( map, QRectF(), 75 ); QGSCOMPARENEAR( t[0], 1925.0, 1 ); QGSCOMPARENEAR( t[1], 0.847603, 0.0001 ); - QGSCOMPARENEAR( t[2], 0.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( t[2], 0.0, 4 * std::numeric_limits::epsilon() ); QGSCOMPARENEAR( t[3], 3050.0, 1 ); - QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( t[4], 0.0, 4 * std::numeric_limits::epsilon() ); QGSCOMPARENEAR( t[5], -0.846774, 0.0001 ); t.reset(); diff --git a/tests/src/core/testqgslayoutitem.cpp b/tests/src/core/testqgslayoutitem.cpp index 1c37cfe982c..14a2151e6e9 100644 --- a/tests/src/core/testqgslayoutitem.cpp +++ b/tests/src/core/testqgslayoutitem.cpp @@ -1091,18 +1091,18 @@ void TestQgsLayoutItem::fixedSize() item->setRect( 0, 0, 5.0, 6.0 ); //temporarily set rect to random size item->attemptResize( QgsLayoutSize( 7.0, 8.0, QgsUnitTypes::LayoutPoints ) ); //check size matches fixed item size converted to mm - QGSCOMPARENEAR( item->rect().width(), 2.0 * 25.4, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( item->rect().height(), 4.0 * 25.4, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( item->rect().width(), 2.0 * 25.4, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( item->rect().height(), 4.0 * 25.4, 4 * std::numeric_limits::epsilon() ); item->attemptResize( QgsLayoutSize( 7.0, 8.0, QgsUnitTypes::LayoutInches ) ); //check size matches fixed item size converted to mm - QGSCOMPARENEAR( item->rect().width(), 2.0 * 25.4, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( item->rect().height(), 4.0 * 25.4, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( item->rect().width(), 2.0 * 25.4, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( item->rect().height(), 4.0 * 25.4, 4 * std::numeric_limits::epsilon() ); //check that setting a fixed size applies this size immediately item->updateFixedSize( QgsLayoutSize( 150, 250, QgsUnitTypes::LayoutMillimeters ) ); - QGSCOMPARENEAR( item->rect().width(), 150.0, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( item->rect().height(), 250.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( item->rect().width(), 150.0, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( item->rect().height(), 250.0, 4 * std::numeric_limits::epsilon() ); } void TestQgsLayoutItem::minSize() @@ -1120,18 +1120,18 @@ void TestQgsLayoutItem::minSize() //try to resize to less than minimum size item->attemptResize( QgsLayoutSize( 1.0, 0.5, QgsUnitTypes::LayoutPoints ) ); //check size matches min item size converted to mm - QGSCOMPARENEAR( item->rect().width(), 50.0, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( item->rect().height(), 100.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( item->rect().width(), 50.0, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( item->rect().height(), 100.0, 4 * std::numeric_limits::epsilon() ); //check that resize to larger than min size works item->attemptResize( QgsLayoutSize( 0.1, 0.2, QgsUnitTypes::LayoutMeters ) ); - QGSCOMPARENEAR( item->rect().width(), 100.0, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( item->rect().height(), 200.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( item->rect().width(), 100.0, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( item->rect().height(), 200.0, 4 * std::numeric_limits::epsilon() ); //check that setting a minimum size applies this size immediately item->updateMinSize( QgsLayoutSize( 150, 250, QgsUnitTypes::LayoutMillimeters ) ); - QGSCOMPARENEAR( item->rect().width(), 150.0, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( item->rect().height(), 250.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( item->rect().width(), 150.0, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( item->rect().height(), 250.0, 4 * std::numeric_limits::epsilon() ); //also need check that fixed size trumps min size std::unique_ptr< FixedMinSizedItem > fixedMinItem( new FixedMinSizedItem( &l ) ); @@ -1144,8 +1144,8 @@ void TestQgsLayoutItem::minSize() //try to resize to less than minimum size fixedMinItem->attemptResize( QgsLayoutSize( 1.0, 0.5, QgsUnitTypes::LayoutPoints ) ); //check size matches fixed item size, not minimum size (converted to mm) - QGSCOMPARENEAR( fixedMinItem->rect().width(), 20.0, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( fixedMinItem->rect().height(), 40.0, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( fixedMinItem->rect().width(), 20.0, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( fixedMinItem->rect().height(), 40.0, 4 * std::numeric_limits::epsilon() ); } void TestQgsLayoutItem::move() diff --git a/tests/src/core/testqgslayoututils.cpp b/tests/src/core/testqgslayoututils.cpp index dc5ecfe2d05..cab1cb30b7a 100644 --- a/tests/src/core/testqgslayoututils.cpp +++ b/tests/src/core/testqgslayoututils.cpp @@ -112,8 +112,8 @@ void TestQgsLayoutUtils::rotate() double x = ( *it ).first.x1(); double y = ( *it ).first.y1(); QgsLayoutUtils::rotate( ( *it ).second, x, y ); - QGSCOMPARENEAR( x, ( *it ).first.x2(), 4 * DBL_EPSILON ); - QGSCOMPARENEAR( y, ( *it ).first.y2(), 4 * DBL_EPSILON ); + QGSCOMPARENEAR( x, ( *it ).first.x2(), 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( y, ( *it ).first.y2(), 4 * std::numeric_limits::epsilon() ); } } @@ -140,7 +140,7 @@ void TestQgsLayoutUtils::normalizedAngle() { double result = QgsLayoutUtils::normalizedAngle( ( *it ).first ); qDebug() << QStringLiteral( "actual: %1 expected: %2" ).arg( result ).arg( ( *it ).second ); - QGSCOMPARENEAR( result, ( *it ).second, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( result, ( *it ).second, 4 * std::numeric_limits::epsilon() ); } @@ -161,7 +161,7 @@ void TestQgsLayoutUtils::normalizedAngle() { double result = QgsLayoutUtils::normalizedAngle( ( *it ).first, true ); qDebug() << QStringLiteral( "actual: %1 expected: %2" ).arg( result ).arg( ( *it ).second ); - QGSCOMPARENEAR( result, ( *it ).second, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( result, ( *it ).second, 4 * std::numeric_limits::epsilon() ); } } @@ -211,7 +211,7 @@ void TestQgsLayoutUtils::snappedAngle() QList< QPair< double, double > >::const_iterator it = testVals.constBegin(); for ( ; it != testVals.constEnd(); ++it ) { - QGSCOMPARENEAR( QgsLayoutUtils::snappedAngle( ( *it ).first ), ( *it ).second, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( QgsLayoutUtils::snappedAngle( ( *it ).first ), ( *it ).second, 4 * std::numeric_limits::epsilon() ); } } @@ -594,7 +594,7 @@ void TestQgsLayoutUtils::largestRotatedRect() || ( qgsDoubleNear( rotatedRectBounds.height(), bounds.height(), 0.001 ) && ( rotatedRectBounds.width() <= bounds.width() ) ) ); //also verify that aspect ratio of rectangle has not changed - QGSCOMPARENEAR( result.width() / result.height(), wideRect.width() / wideRect.height(), 4 * DBL_EPSILON ); + QGSCOMPARENEAR( result.width() / result.height(), wideRect.width() / wideRect.height(), 4 * std::numeric_limits::epsilon() ); } //and again for the high rectangle for ( double rotation = 10; rotation < 360; rotation += 10 ) @@ -609,7 +609,7 @@ void TestQgsLayoutUtils::largestRotatedRect() || ( qgsDoubleNear( rotatedRectBounds.height(), bounds.height(), 0.001 ) && ( rotatedRectBounds.width() <= bounds.width() ) ) ); //also verify that aspect ratio of rectangle has not changed - QGSCOMPARENEAR( result.width() / result.height(), highRect.width() / highRect.height(), 4 * DBL_EPSILON ); + QGSCOMPARENEAR( result.width() / result.height(), highRect.width() / highRect.height(), 4 * std::numeric_limits::epsilon() ); } } diff --git a/tests/src/core/testqgsrasterlayer.cpp b/tests/src/core/testqgsrasterlayer.cpp index 89052028e01..c7f947f3711 100644 --- a/tests/src/core/testqgsrasterlayer.cpp +++ b/tests/src/core/testqgsrasterlayer.cpp @@ -390,7 +390,7 @@ void TestQgsRasterLayer::checkStats() //QVERIFY( myStatistics.elementCount == 100 ); QVERIFY( myStatistics.minimumValue == 0 ); QVERIFY( myStatistics.maximumValue == 9 ); - QGSCOMPARENEAR( myStatistics.mean, 4.5, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( myStatistics.mean, 4.5, 4 * std::numeric_limits::epsilon() ); double stdDev = 2.87228132326901431; // TODO: verify why GDAL stdDev is so different from generic (2.88675) mReport += QStringLiteral( "stdDev = %1 expected = %2
\n" ).arg( myStatistics.stdDev ).arg( stdDev ); diff --git a/tests/src/core/testqgsrastersublayer.cpp b/tests/src/core/testqgsrastersublayer.cpp index c3ce794277f..2dd80f702c8 100644 --- a/tests/src/core/testqgsrastersublayer.cpp +++ b/tests/src/core/testqgsrastersublayer.cpp @@ -171,8 +171,8 @@ void TestQgsRasterSubLayer::checkStats() QVERIFY( sublayer->width() == width ); QVERIFY( sublayer->height() == height ); - QGSCOMPARENEAR( myStatistics.minimumValue, min, 4 * DBL_EPSILON ); - QGSCOMPARENEAR( myStatistics.maximumValue, max, 4 * DBL_EPSILON ); + QGSCOMPARENEAR( myStatistics.minimumValue, min, 4 * std::numeric_limits::epsilon() ); + QGSCOMPARENEAR( myStatistics.maximumValue, max, 4 * std::numeric_limits::epsilon() ); mReport += QLatin1String( "

Passed

" ); delete sublayer; }