diff --git a/scripts/sipify.pl b/scripts/sipify.pl index 5d2ef5d6f9d..2b6f22286a8 100755 --- a/scripts/sipify.pl +++ b/scripts/sipify.pl @@ -434,9 +434,9 @@ sub fix_annotations { sub fix_constants { my $line = $_[0]; - $line =~ s/\bstd::numeric_limits::max\(\)/DBL_MAX/; - $line =~ s/\bstd::numeric_limits::lowest\(\)/-DBL_MAX/; - $line =~ s/\bstd::numeric_limits::epsilon\(\)/DBL_EPSILON/; + $line =~ s/\bstd::numeric_limits::max\(\)/DBL_MAX/g; + $line =~ s/\bstd::numeric_limits::lowest\(\)/-DBL_MAX/g; + $line =~ s/\bstd::numeric_limits::epsilon\(\)/DBL_EPSILON/g; return $line; } diff --git a/src/core/geometry/qgsabstractgeometry.h b/src/core/geometry/qgsabstractgeometry.h index 5d73b6574fa..f74f9b3de5f 100644 --- a/src/core/geometry/qgsabstractgeometry.h +++ b/src/core/geometry/qgsabstractgeometry.h @@ -356,7 +356,7 @@ class CORE_EXPORT QgsAbstractGeometry */ virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, - int *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const = 0; + int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits::epsilon() ) const = 0; //low-level editing @@ -486,7 +486,7 @@ class CORE_EXPORT QgsAbstractGeometry * * \since QGIS 3.0 */ - virtual bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) = 0; + virtual bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits::epsilon(), bool useZValues = false ) = 0; /** * Returns approximate angle at a vertex. This is usually the average angle between adjacent diff --git a/src/core/geometry/qgscircularstring.h b/src/core/geometry/qgscircularstring.h index 3e8f3a932bc..71d9f99cd93 100644 --- a/src/core/geometry/qgscircularstring.h +++ b/src/core/geometry/qgscircularstring.h @@ -101,7 +101,7 @@ class CORE_EXPORT QgsCircularString: public QgsCurve QgsPoint endPoint() const override; QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY; QgsCircularString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY; - bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override; + bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits::epsilon(), bool useZValues = false ) override; void draw( QPainter &p ) const override; void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) override SIP_THROW( QgsCsException ); @@ -111,7 +111,7 @@ class CORE_EXPORT QgsCircularString: public QgsCurve bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override; bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override; bool deleteVertex( QgsVertexId position ) override; - double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override; + double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits::epsilon() ) const override; bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override; void sumUpArea( double &sum SIP_OUT ) const override; bool hasCurvedSegments() const override; diff --git a/src/core/geometry/qgscompoundcurve.h b/src/core/geometry/qgscompoundcurve.h index 7430382ea90..b30a2f5ab12 100644 --- a/src/core/geometry/qgscompoundcurve.h +++ b/src/core/geometry/qgscompoundcurve.h @@ -68,7 +68,7 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY; QgsCompoundCurve *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY; - bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override; + bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits::epsilon(), bool useZValues = false ) override; /** * Returns the number of curves in the geometry. @@ -104,7 +104,7 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override; bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override; bool deleteVertex( QgsVertexId position ) override; - double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override; + double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits::epsilon() ) const override; bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override; void sumUpArea( double &sum SIP_OUT ) const override; diff --git a/src/core/geometry/qgscurvepolygon.h b/src/core/geometry/qgscurvepolygon.h index 6f2858cb939..40942dea1c1 100644 --- a/src/core/geometry/qgscurvepolygon.h +++ b/src/core/geometry/qgscurvepolygon.h @@ -63,7 +63,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface QgsPolygon *surfaceToPolygon() const override SIP_FACTORY; QgsAbstractGeometry *boundary() const override SIP_FACTORY; QgsCurvePolygon *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY; - bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override; + bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits::epsilon(), bool useZValues = false ) override; //curve polygon interface int numInteriorRings() const; @@ -130,7 +130,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface int nCoordinates() const override; int vertexNumberFromVertexId( QgsVertexId id ) const override; bool isEmpty() const override; - double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override; + double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits::epsilon() ) const override; bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override; void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override; diff --git a/src/core/geometry/qgsgeometry.h b/src/core/geometry/qgsgeometry.h index cb82777704b..4c32249b7c7 100644 --- a/src/core/geometry/qgsgeometry.h +++ b/src/core/geometry/qgsgeometry.h @@ -794,7 +794,7 @@ class CORE_EXPORT QgsGeometry * * \since QGIS 3.0 */ - bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ); + bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits::epsilon(), bool useZValues = false ); /** * Returns true if this geometry exactly intersects with a \a rectangle. This test is exact @@ -1630,7 +1630,7 @@ class CORE_EXPORT QgsGeometry * tolerance * \since QGIS 2.9 */ - static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * DBL_EPSILON ); + static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * std::numeric_limits::epsilon() ); % MethodCode { sipRes = false; diff --git a/src/core/geometry/qgsgeometrycollection.h b/src/core/geometry/qgsgeometrycollection.h index a1fcd7c8988..7b678474c8c 100644 --- a/src/core/geometry/qgsgeometrycollection.h +++ b/src/core/geometry/qgsgeometrycollection.h @@ -68,7 +68,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry QString geometryType() const override; void clear() override; QgsGeometryCollection *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY; - bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override; + bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits::epsilon(), bool useZValues = false ) override; QgsAbstractGeometry *boundary() const override SIP_FACTORY; void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override; int vertexNumberFromVertexId( QgsVertexId id ) const override; @@ -108,7 +108,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry QgsCoordinateSequence coordinateSequence() const override; int nCoordinates() const override; - double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override; + double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits::epsilon() ) const override; bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override; //low-level editing diff --git a/src/core/geometry/qgslinestring.h b/src/core/geometry/qgslinestring.h index 47634cd7980..4cd5ba4f326 100644 --- a/src/core/geometry/qgslinestring.h +++ b/src/core/geometry/qgslinestring.h @@ -229,7 +229,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve void clear() override; bool isEmpty() const override; QgsLineString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY; - bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override; + bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits::epsilon(), bool useZValues = false ) override; QPolygonF asQPolygonF() const override; bool fromWkb( QgsConstWkbPtr &wkb ) override; @@ -271,7 +271,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve QgsLineString *reversed() const override SIP_FACTORY; - double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override; + double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits::epsilon() ) const override; bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override; QgsPoint centroid() const override; diff --git a/src/core/geometry/qgspoint.h b/src/core/geometry/qgspoint.h index 2fa4e617cc3..eed55930091 100644 --- a/src/core/geometry/qgspoint.h +++ b/src/core/geometry/qgspoint.h @@ -392,7 +392,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry int dimension() const override; QgsPoint *clone() const override SIP_FACTORY; QgsPoint *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY; - bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override; + bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits::epsilon(), bool useZValues = false ) override; void clear() override; bool fromWkb( QgsConstWkbPtr &wkb ) override; bool fromWkt( const QString &wkt ) override; @@ -414,7 +414,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override; bool deleteVertex( QgsVertexId position ) override; - double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override; + double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits::epsilon() ) const override; bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override; void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override; diff --git a/src/core/processing/qgsprocessingparameters.h b/src/core/processing/qgsprocessingparameters.h index 1613cdcd851..f3a3c2c94ef 100644 --- a/src/core/processing/qgsprocessingparameters.h +++ b/src/core/processing/qgsprocessingparameters.h @@ -1186,8 +1186,8 @@ class CORE_EXPORT QgsProcessingParameterNumber : public QgsProcessingParameterDe Type type = Integer, const QVariant &defaultValue = QVariant(), bool optional = false, - double minValue = -DBL_MAX + 1, - double maxValue = DBL_MAX + double minValue = std::numeric_limits::lowest() + 1, + double maxValue = std::numeric_limits::max() ); /** diff --git a/src/core/qgspointxy.h b/src/core/qgspointxy.h index 56de906bef0..f8ec5a1d9af 100644 --- a/src/core/qgspointxy.h +++ b/src/core/qgspointxy.h @@ -210,7 +210,7 @@ class CORE_EXPORT QgsPointXY * \returns true if points are equal within specified tolerance * \since QGIS 2.9 */ - bool compare( const QgsPointXY &other, double epsilon = 4 * DBL_EPSILON ) const; + bool compare( const QgsPointXY &other, double epsilon = 4 * std::numeric_limits::epsilon() ) const; //! equality operator bool operator==( const QgsPointXY &other ); diff --git a/src/providers/grass/qgsgrassvectormaplayer.cpp b/src/providers/grass/qgsgrassvectormaplayer.cpp index 2ad1b1b105b..e1286c7abbe 100644 --- a/src/providers/grass/qgsgrassvectormaplayer.cpp +++ b/src/providers/grass/qgsgrassvectormaplayer.cpp @@ -143,7 +143,7 @@ void QgsGrassVectorMapLayer::load() // Read columns' description for ( int i = 0; i < nColumns; i++ ) { - QPair minMax( DBL_MAX, -DBL_MAX ); + QPair minMax( std::numeric_limits::max(), std::numeric_limits::lowest() ); dbColumn *column = db_get_table_column( databaseTable, i ); diff --git a/tests/code_layout/test_banned_keywords.sh b/tests/code_layout/test_banned_keywords.sh index 2e72a5315cd..317c9cf188e 100755 --- a/tests/code_layout/test_banned_keywords.sh +++ b/tests/code_layout/test_banned_keywords.sh @@ -5,14 +5,18 @@ declare -a KEYWORDS=() declare -a HINTS=() -KEYWORDS[0]="DBL_MAX" -HINTS[0]="Use the type-safe method std::numeric_limits::max() instead" +KEYWORDS[0]="\-DBL_MAX" +HINTS[0]="Use the type-safe method std::numeric_limits::lowest() instead" -KEYWORDS[1]="DBL_MIN" -HINTS[1]="Use the type-safe method std::numeric_limits::lowest() instead" +KEYWORDS[1]="DBL_MAX" +HINTS[1]="Use the type-safe method std::numeric_limits::max() instead" + +KEYWORDS[2]="DBL_MIN" +HINTS[2]="Use the type-safe method std::numeric_limits::min() instead (but be careful - maybe you actually want lowest!!)" + +KEYWORDS[3]="DBL_EPSILON" +HINTS[3]="Use the type-safe method std::numeric_limits::epsilon() instead" -KEYWORDS[2]="DBL_EPSILON" -HINTS[2]="Use the type-safe method std::numeric_limits::epsilon() instead" RES= DIR=$(git rev-parse --show-toplevel)