Skip to content

Commit 17cd2fd

Browse files
committed
More DBL_MIN/MAX_EPSILON upgrades
1 parent ce6fc8f commit 17cd2fd

13 files changed

+33
-29
lines changed

scripts/sipify.pl

+3-3
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@ sub fix_annotations {
434434

435435
sub fix_constants {
436436
my $line = $_[0];
437-
$line =~ s/\bstd::numeric_limits<double>::max\(\)/DBL_MAX/;
438-
$line =~ s/\bstd::numeric_limits<double>::lowest\(\)/-DBL_MAX/;
439-
$line =~ s/\bstd::numeric_limits<double>::epsilon\(\)/DBL_EPSILON/;
437+
$line =~ s/\bstd::numeric_limits<double>::max\(\)/DBL_MAX/g;
438+
$line =~ s/\bstd::numeric_limits<double>::lowest\(\)/-DBL_MAX/g;
439+
$line =~ s/\bstd::numeric_limits<double>::epsilon\(\)/DBL_EPSILON/g;
440440
return $line;
441441
}
442442

src/core/geometry/qgsabstractgeometry.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class CORE_EXPORT QgsAbstractGeometry
356356
*/
357357
virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT,
358358
QgsVertexId &vertexAfter SIP_OUT,
359-
int *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const = 0;
359+
int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const = 0;
360360

361361
//low-level editing
362362

@@ -486,7 +486,7 @@ class CORE_EXPORT QgsAbstractGeometry
486486
*
487487
* \since QGIS 3.0
488488
*/
489-
virtual bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) = 0;
489+
virtual bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) = 0;
490490

491491
/**
492492
* Returns approximate angle at a vertex. This is usually the average angle between adjacent

src/core/geometry/qgscircularstring.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
101101
QgsPoint endPoint() const override;
102102
QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
103103
QgsCircularString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
104-
bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
104+
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
105105

106106
void draw( QPainter &p ) const override;
107107
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
111111
bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
112112
bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
113113
bool deleteVertex( QgsVertexId position ) override;
114-
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;
114+
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
115115
bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
116116
void sumUpArea( double &sum SIP_OUT ) const override;
117117
bool hasCurvedSegments() const override;

src/core/geometry/qgscompoundcurve.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
6868
QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
6969

7070
QgsCompoundCurve *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
71-
bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
71+
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
7272

7373
/**
7474
* Returns the number of curves in the geometry.
@@ -104,7 +104,7 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
104104
bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
105105
bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
106106
bool deleteVertex( QgsVertexId position ) override;
107-
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;
107+
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
108108
bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
109109
void sumUpArea( double &sum SIP_OUT ) const override;
110110

src/core/geometry/qgscurvepolygon.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
6363
QgsPolygon *surfaceToPolygon() const override SIP_FACTORY;
6464
QgsAbstractGeometry *boundary() const override SIP_FACTORY;
6565
QgsCurvePolygon *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
66-
bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
66+
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
6767

6868
//curve polygon interface
6969
int numInteriorRings() const;
@@ -130,7 +130,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
130130
int nCoordinates() const override;
131131
int vertexNumberFromVertexId( QgsVertexId id ) const override;
132132
bool isEmpty() const override;
133-
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;
133+
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
134134

135135
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
136136
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;

src/core/geometry/qgsgeometry.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ class CORE_EXPORT QgsGeometry
794794
*
795795
* \since QGIS 3.0
796796
*/
797-
bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false );
797+
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false );
798798

799799
/**
800800
* Returns true if this geometry exactly intersects with a \a rectangle. This test is exact
@@ -1630,7 +1630,7 @@ class CORE_EXPORT QgsGeometry
16301630
* tolerance
16311631
* \since QGIS 2.9
16321632
*/
1633-
static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * DBL_EPSILON );
1633+
static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
16341634
% MethodCode
16351635
{
16361636
sipRes = false;

src/core/geometry/qgsgeometrycollection.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
6868
QString geometryType() const override;
6969
void clear() override;
7070
QgsGeometryCollection *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
71-
bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
71+
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
7272
QgsAbstractGeometry *boundary() const override SIP_FACTORY;
7373
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
7474
int vertexNumberFromVertexId( QgsVertexId id ) const override;
@@ -108,7 +108,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
108108
QgsCoordinateSequence coordinateSequence() const override;
109109
int nCoordinates() const override;
110110

111-
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;
111+
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
112112
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
113113

114114
//low-level editing

src/core/geometry/qgslinestring.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve
229229
void clear() override;
230230
bool isEmpty() const override;
231231
QgsLineString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
232-
bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
232+
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
233233
QPolygonF asQPolygonF() const override;
234234

235235
bool fromWkb( QgsConstWkbPtr &wkb ) override;
@@ -271,7 +271,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve
271271

272272
QgsLineString *reversed() const override SIP_FACTORY;
273273

274-
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;
274+
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
275275
bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
276276

277277
QgsPoint centroid() const override;

src/core/geometry/qgspoint.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
392392
int dimension() const override;
393393
QgsPoint *clone() const override SIP_FACTORY;
394394
QgsPoint *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
395-
bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
395+
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
396396
void clear() override;
397397
bool fromWkb( QgsConstWkbPtr &wkb ) override;
398398
bool fromWkt( const QString &wkt ) override;
@@ -414,7 +414,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
414414
bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
415415
bool deleteVertex( QgsVertexId position ) override;
416416

417-
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;
417+
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
418418
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
419419
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
420420

src/core/processing/qgsprocessingparameters.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1186,8 +1186,8 @@ class CORE_EXPORT QgsProcessingParameterNumber : public QgsProcessingParameterDe
11861186
Type type = Integer,
11871187
const QVariant &defaultValue = QVariant(),
11881188
bool optional = false,
1189-
double minValue = -DBL_MAX + 1,
1190-
double maxValue = DBL_MAX
1189+
double minValue = std::numeric_limits<double>::lowest() + 1,
1190+
double maxValue = std::numeric_limits<double>::max()
11911191
);
11921192

11931193
/**

src/core/qgspointxy.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class CORE_EXPORT QgsPointXY
210210
* \returns true if points are equal within specified tolerance
211211
* \since QGIS 2.9
212212
*/
213-
bool compare( const QgsPointXY &other, double epsilon = 4 * DBL_EPSILON ) const;
213+
bool compare( const QgsPointXY &other, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const;
214214

215215
//! equality operator
216216
bool operator==( const QgsPointXY &other );

src/providers/grass/qgsgrassvectormaplayer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void QgsGrassVectorMapLayer::load()
143143
// Read columns' description
144144
for ( int i = 0; i < nColumns; i++ )
145145
{
146-
QPair<double, double> minMax( DBL_MAX, -DBL_MAX );
146+
QPair<double, double> minMax( std::numeric_limits<double>::max(), std::numeric_limits<double>::lowest() );
147147

148148
dbColumn *column = db_get_table_column( databaseTable, i );
149149

tests/code_layout/test_banned_keywords.sh

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
declare -a KEYWORDS=()
66
declare -a HINTS=()
77

8-
KEYWORDS[0]="DBL_MAX"
9-
HINTS[0]="Use the type-safe method std::numeric_limits<double>::max() instead"
8+
KEYWORDS[0]="\-DBL_MAX"
9+
HINTS[0]="Use the type-safe method std::numeric_limits<double>::lowest() instead"
1010

11-
KEYWORDS[1]="DBL_MIN"
12-
HINTS[1]="Use the type-safe method std::numeric_limits<double>::lowest() instead"
11+
KEYWORDS[1]="DBL_MAX"
12+
HINTS[1]="Use the type-safe method std::numeric_limits<double>::max() instead"
13+
14+
KEYWORDS[2]="DBL_MIN"
15+
HINTS[2]="Use the type-safe method std::numeric_limits<double>::min() instead (but be careful - maybe you actually want lowest!!)"
16+
17+
KEYWORDS[3]="DBL_EPSILON"
18+
HINTS[3]="Use the type-safe method std::numeric_limits<double>::epsilon() instead"
1319

14-
KEYWORDS[2]="DBL_EPSILON"
15-
HINTS[2]="Use the type-safe method std::numeric_limits<double>::epsilon() instead"
1620

1721
RES=
1822
DIR=$(git rev-parse --show-toplevel)

0 commit comments

Comments
 (0)