Skip to content

Commit

Permalink
More DBL_MIN/MAX_EPSILON upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 16, 2018
1 parent ce6fc8f commit 17cd2fd
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 29 deletions.
6 changes: 3 additions & 3 deletions scripts/sipify.pl
Expand Up @@ -434,9 +434,9 @@ sub fix_annotations {

sub fix_constants {
my $line = $_[0];
$line =~ s/\bstd::numeric_limits<double>::max\(\)/DBL_MAX/;
$line =~ s/\bstd::numeric_limits<double>::lowest\(\)/-DBL_MAX/;
$line =~ s/\bstd::numeric_limits<double>::epsilon\(\)/DBL_EPSILON/;
$line =~ s/\bstd::numeric_limits<double>::max\(\)/DBL_MAX/g;
$line =~ s/\bstd::numeric_limits<double>::lowest\(\)/-DBL_MAX/g;
$line =~ s/\bstd::numeric_limits<double>::epsilon\(\)/DBL_EPSILON/g;
return $line;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsabstractgeometry.h
Expand Up @@ -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<double>::epsilon() ) const = 0;

//low-level editing

Expand Down Expand Up @@ -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<double>::epsilon(), bool useZValues = false ) = 0;

/**
* Returns approximate angle at a vertex. This is usually the average angle between adjacent
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgscircularstring.h
Expand Up @@ -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<double>::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 );
Expand All @@ -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<double>::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;
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgscompoundcurve.h
Expand Up @@ -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<double>::epsilon(), bool useZValues = false ) override;

/**
* Returns the number of curves in the geometry.
Expand Down Expand Up @@ -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<double>::epsilon() ) const override;
bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
void sumUpArea( double &sum SIP_OUT ) const override;

Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgscurvepolygon.h
Expand Up @@ -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<double>::epsilon(), bool useZValues = false ) override;

//curve polygon interface
int numInteriorRings() const;
Expand Down Expand Up @@ -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<double>::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;
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsgeometry.h
Expand Up @@ -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<double>::epsilon(), bool useZValues = false );

/**
* Returns true if this geometry exactly intersects with a \a rectangle. This test is exact
Expand Down Expand Up @@ -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<double>::epsilon() );
% MethodCode
{
sipRes = false;
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsgeometrycollection.h
Expand Up @@ -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<double>::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;
Expand Down Expand Up @@ -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<double>::epsilon() ) const override;
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;

//low-level editing
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgslinestring.h
Expand Up @@ -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<double>::epsilon(), bool useZValues = false ) override;
QPolygonF asQPolygonF() const override;

bool fromWkb( QgsConstWkbPtr &wkb ) override;
Expand Down Expand Up @@ -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<double>::epsilon() ) const override;
bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;

QgsPoint centroid() const override;
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgspoint.h
Expand Up @@ -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<double>::epsilon(), bool useZValues = false ) override;
void clear() override;
bool fromWkb( QgsConstWkbPtr &wkb ) override;
bool fromWkt( const QString &wkt ) override;
Expand All @@ -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<double>::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;

Expand Down
4 changes: 2 additions & 2 deletions src/core/processing/qgsprocessingparameters.h
Expand Up @@ -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<double>::lowest() + 1,
double maxValue = std::numeric_limits<double>::max()
);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspointxy.h
Expand Up @@ -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<double>::epsilon() ) const;

//! equality operator
bool operator==( const QgsPointXY &other );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassvectormaplayer.cpp
Expand Up @@ -143,7 +143,7 @@ void QgsGrassVectorMapLayer::load()
// Read columns' description
for ( int i = 0; i < nColumns; i++ )
{
QPair<double, double> minMax( DBL_MAX, -DBL_MAX );
QPair<double, double> minMax( std::numeric_limits<double>::max(), std::numeric_limits<double>::lowest() );

dbColumn *column = db_get_table_column( databaseTable, i );

Expand Down
16 changes: 10 additions & 6 deletions tests/code_layout/test_banned_keywords.sh
Expand Up @@ -5,14 +5,18 @@
declare -a KEYWORDS=()
declare -a HINTS=()

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

KEYWORDS[1]="DBL_MIN"
HINTS[1]="Use the type-safe method std::numeric_limits<double>::lowest() instead"
KEYWORDS[1]="DBL_MAX"
HINTS[1]="Use the type-safe method std::numeric_limits<double>::max() instead"

KEYWORDS[2]="DBL_MIN"
HINTS[2]="Use the type-safe method std::numeric_limits<double>::min() instead (but be careful - maybe you actually want lowest!!)"

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

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

RES=
DIR=$(git rev-parse --show-toplevel)
Expand Down

0 comments on commit 17cd2fd

Please sign in to comment.