Skip to content

Commit

Permalink
use Qt for isnan/isinf/abs
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14711 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 18, 2010
1 parent 07a3f62 commit 2a3a087
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/analysis/interpolation/qgsinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int QgsInterpolator::cacheBaseData()
continue;
}
attributeValue = att_it.value().toDouble( &attributeConversionOk );
if ( !attributeConversionOk || isnan( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation
if ( !attributeConversionOk || qIsNaN( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation
{
continue;
}
Expand Down
12 changes: 9 additions & 3 deletions src/analysis/interpolation/qgstininterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
#include "qgsvectorlayer.h"
#include <QProgressDialog>

QgsTINInterpolator::QgsTINInterpolator( const QList<LayerData>& inputData, TIN_INTERPOLATION interpolation, bool showProgressDialog ): QgsInterpolator( inputData ), mTriangulation( 0 ), \
mTriangleInterpolator( 0 ), mIsInitialized( false ), mShowProgressDialog( showProgressDialog ), mExportTriangulationToFile( false ), mInterpolation( interpolation )
QgsTINInterpolator::QgsTINInterpolator( const QList<LayerData>& inputData, TIN_INTERPOLATION interpolation, bool showProgressDialog )
: QgsInterpolator( inputData )
, mTriangulation( 0 )
, mTriangleInterpolator( 0 )
, mIsInitialized( false )
, mShowProgressDialog( showProgressDialog )
, mExportTriangulationToFile( false )
, mInterpolation( interpolation )
{
}

Expand Down Expand Up @@ -185,7 +191,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
return 3;
}
attributeValue = att_it.value().toDouble( &attributeConversionOk );
if ( !attributeConversionOk || isnan( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation
if ( !attributeConversionOk || qIsNaN( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation
{
return 4;
}
Expand Down
1 change: 0 additions & 1 deletion src/app/qgsprojectproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "ui_qgsprojectpropertiesbase.h"
#include "qgis.h"
#include "qgisgui.h"
#include "qgssnappingdialog.h"
#include "qgscontexthelp.h"

class QgsMapCanvas;
Expand Down
12 changes: 2 additions & 10 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@

#ifndef QGIS_H
#define QGIS_H

#include <QEvent>
#include <QString>
#include <cfloat>

#ifndef Q_OS_MACX
#include <cmath>
#else
#include <math.h>
#endif
#ifdef WIN32
#include <float.h>
#define isnan(f) _isnan(f)
#define isinf(f) (!_finite(f) && !_isnan(f))
#endif
#include <qnumeric.h>

/** \ingroup core
* The QGis class provides global constants for use throughout the application.
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsclipper.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ inline void QgsClipper::trimFeatureToBoundary(
// look at each edge of the polygon in turn

//ignore segments with nan or inf coordinates
if ( isnan( inX[i2] ) || isnan( inY[i2] ) || isinf( inX[i2] ) || isinf( inY[i2] )
|| isnan( inX[i1] ) || isnan( inY[i1] ) || isinf( inX[i1] ) || isinf( inY[i1] ) )
if ( qIsNaN( inX[i2] ) || qIsNaN( inY[i2] ) || qIsInf( inX[i2] ) || qIsInf( inY[i2] )
|| qIsNaN( inX[i1] ) || qIsNaN( inY[i1] ) || qIsInf( inX[i1] ) || qIsInf( inY[i1] ) )
{
i1 = i2;
continue;
Expand Down Expand Up @@ -268,7 +268,7 @@ inline QgsPoint QgsClipper::intersect( const double x1, const double y1,

QgsPoint p;

if ( std::abs( r_d ) > SMALL_NUM && std::abs( r_n ) > SMALL_NUM )
if ( qAbs( r_d ) > SMALL_NUM && qAbs( r_n ) > SMALL_NUM )
{ // they cross
double r = r_n / r_d;
p.set( x1 + r*( x2 - x1 ), y1 + r*( y2 - y1 ) );
Expand All @@ -277,7 +277,7 @@ inline QgsPoint QgsClipper::intersect( const double x1, const double y1,
{
// Should never get here, but if we do for some reason, cause a
// clunk because something else is wrong if we do.
Q_ASSERT( std::abs( r_d ) > SMALL_NUM && std::abs( r_n ) > SMALL_NUM );
Q_ASSERT( qAbs( r_d ) > SMALL_NUM && qAbs( r_n ) > SMALL_NUM );
}

return p;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
//data defined position / alignment / rotation?
bool dataDefinedPosition = false;
bool dataDefinedRotation = false;
double xPos, yPos, angle;
double xPos = 0.0, yPos = 0.0, angle = 0.0;
bool ddXPos, ddYPos;

QMap< DataDefinedProperties, int >::const_iterator dPosXIt = dataDefinedProperties.find( QgsPalLayerSettings::PositionX );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgspoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ QString QgsPoint::toString( int thePrecision ) const
QString QgsPoint::toDegreesMinutesSeconds( int thePrecision ) const
{
int myDegreesX = int( std::abs( m_x ) );
float myFloatMinutesX = float(( std::abs( m_x ) - myDegreesX ) * 60 );
float myFloatMinutesX = float(( qAbs( m_x ) - myDegreesX ) * 60 );
int myIntMinutesX = int( myFloatMinutesX );
float mySecondsX = float( myFloatMinutesX - myIntMinutesX ) * 60;

int myDegreesY = int( std::abs( m_y ) );
float myFloatMinutesY = float(( std::abs( m_y ) - myDegreesY ) * 60 );
float myFloatMinutesY = float(( qAbs( m_y ) - myDegreesY ) * 60 );
int myIntMinutesY = int( myFloatMinutesY );
float mySecondsY = float( myFloatMinutesY - myIntMinutesY ) * 60;

Expand Down
16 changes: 8 additions & 8 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ unsigned char *QgsVectorLayer::drawLineString( unsigned char *feature, QgsRender
// the rest of them so end the loop at that point.
for ( register unsigned int i = 0; i < nPoints; ++i )
{
if ( std::abs( x[i] ) > QgsClipper::MAX_X ||
std::abs( y[i] ) > QgsClipper::MAX_Y )
if ( qAbs( x[i] ) > QgsClipper::MAX_X ||
qAbs( y[i] ) > QgsClipper::MAX_Y )
{
QgsClipper::trimFeature( x, y, true ); // true = polyline
nPoints = x.size(); // trimming may change nPoints.
Expand Down Expand Up @@ -546,8 +546,8 @@ unsigned char *QgsVectorLayer::drawPolygon( unsigned char *feature, QgsRenderCon
// the rest of them so end the loop at that point.
for ( register unsigned int i = 0; i < nPoints; ++i )
{
if ( std::abs( ring->first[i] ) > QgsClipper::MAX_X ||
std::abs( ring->second[i] ) > QgsClipper::MAX_Y )
if ( qAbs( ring->first[i] ) > QgsClipper::MAX_X ||
qAbs( ring->second[i] ) > QgsClipper::MAX_Y )
{
QgsClipper::trimFeature( ring->first, ring->second, false );
break;
Expand Down Expand Up @@ -4037,8 +4037,8 @@ void QgsVectorLayer::drawFeature( QgsRenderContext &renderContext,
double y = *(( double * )( feature + 5 + sizeof( double ) ) );

transformPoint( x, y, &renderContext.mapToPixel(), renderContext.coordinateTransform() );
if ( std::abs( x ) > QgsClipper::MAX_X ||
std::abs( y ) > QgsClipper::MAX_Y )
if ( qAbs( x ) > QgsClipper::MAX_X ||
qAbs( y ) > QgsClipper::MAX_Y )
{
break;
}
Expand Down Expand Up @@ -4085,8 +4085,8 @@ void QgsVectorLayer::drawFeature( QgsRenderContext &renderContext,
//QPointF pt( x, y );

// Work around a +/- 32768 limitation on coordinates
if ( std::abs( x ) > QgsClipper::MAX_X ||
std::abs( y ) > QgsClipper::MAX_Y )
if ( qAbs( x ) > QgsClipper::MAX_X ||
qAbs( y ) > QgsClipper::MAX_Y )
needToTrim = true;
else
p->drawImage( pt, *marker );
Expand Down
4 changes: 2 additions & 2 deletions src/core/spatialindex/geometry/Region.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ double Tools::Geometry::Region::getMinimumDistance( const Region& r ) const

if ( r.m_pHigh[i] < m_pLow[i] )
{
x = std::abs( r.m_pHigh[i] - m_pLow[i] );
x = qAbs( r.m_pHigh[i] - m_pLow[i] );
}
else if ( m_pHigh[i] < r.m_pLow[i] )
{
x = std::abs( r.m_pLow[i] - m_pHigh[i] );
x = qAbs( r.m_pLow[i] - m_pHigh[i] );
}

ret += x * x;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsquickprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ void QgsQuickPrint::renderPrintScaleBar( QPainter * thepPainter,
//Get map units per pixel. This can be negative at times (to do with
//projections) and that just confuses the rest of the code in this
//function, so force to a positive number.
double myMapUnitsPerPixelDouble = std::abs( thepMapRenderer->mapUnitsPerPixel() );
double myMapUnitsPerPixelDouble = qAbs( thepMapRenderer->mapUnitsPerPixel() );
//
// Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze
int myLayerCount = thepMapRenderer->layerSet().count();
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/georeferencer/qgsgeoreftransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ int QgsLinearGeorefTransform::linear_transform( void *pTransformerArg, int bDstT
else
{
// Guard against division by zero
if ( abs( t->scaleX ) < std::numeric_limits<double>::epsilon() ||
abs( t->scaleY ) < std::numeric_limits<double>::epsilon() )
if ( qAbs( t->scaleX ) < std::numeric_limits<double>::epsilon() ||
qAbs( t->scaleY ) < std::numeric_limits<double>::epsilon() )
{
for ( int i = 0; i < nPointCount; ++i )
{
Expand Down Expand Up @@ -591,7 +591,7 @@ bool QgsProjectiveGeorefTransform::updateParametersFromGCPs( const std::vector<Q

double det = H[0] * adjoint[0] + H[3] * adjoint[1] + H[6] * adjoint[2];

if ( std::abs( det ) < 1024.0*std::numeric_limits<double>::epsilon() )
if ( qAbs( det ) < 1024.0*std::numeric_limits<double>::epsilon() )
{
mParameters.hasInverse = false;
}
Expand Down Expand Up @@ -644,7 +644,7 @@ int QgsProjectiveGeorefTransform::projective_transform( void *pTransformerArg, i
{
double Z = x[i] * H[6] + y[i] * H[7] + H[8];
// Projects to infinity?
if ( std::abs( Z ) < 1024.0*std::numeric_limits<double>::epsilon() )
if ( qAbs( Z ) < 1024.0*std::numeric_limits<double>::epsilon() )
{
panSuccess[i] = false;
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/georeferencer/qgsleastsquares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ void QgsLeastSquares::linear( std::vector<QgsPoint> mapCoords,
origin.setX( aX );
origin.setY( aY );

pixelXSize = std::abs( bX );
pixelYSize = std::abs( bY );
pixelXSize = qAbs( bX );
pixelYSize = qAbs( bY );
}


Expand Down
2 changes: 1 addition & 1 deletion src/plugins/scale_bar/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void QgsScaleBarPlugin::renderScaleBar( QPainter * theQPainter )
//Get map units per pixel. This can be negative at times (to do with
//projections) and that just confuses the rest of the code in this
//function, so force to a positive number.
double myMapUnitsPerPixelDouble = std::abs( qGisInterface->mapCanvas()->mapUnitsPerPixel() );
double myMapUnitsPerPixelDouble = qAbs( qGisInterface->mapCanvas()->mapUnitsPerPixel() );

// Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze
int myLayerCount = qGisInterface->mapCanvas()->layerCount();
Expand Down

0 comments on commit 2a3a087

Please sign in to comment.