Skip to content

Commit

Permalink
use Qt macros also for min/max/abs/fabs - removes OSX cmath kludges
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14713 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 19, 2010
1 parent 8868c95 commit 2f0c705
Show file tree
Hide file tree
Showing 60 changed files with 250 additions and 296 deletions.
5 changes: 1 addition & 4 deletions src/analysis/interpolation/CloughTocherInterpolator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@

#include "CloughTocherInterpolator.h"
#include "qgslogger.h"
#ifndef Q_OS_MACX

#include <cmath>
#else
#include <math.h>
#endif

double CloughTocherInterpolator::calcBernsteinPoly( int n, int i, int j, int k, double u, double v, double w )
{
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/DualEdgeTriangulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ int DualEdgeTriangulation::addPoint( Point3D* p )
//Take the higher z-Value in case of two equal points
Point3D* newPoint = mPointVector[mPointVector.count()-1];
Point3D* existingPoint = mPointVector[mTwiceInsPoint];
existingPoint->setZ( std::max( newPoint->getZ(), existingPoint->getZ() ) );
existingPoint->setZ( qMax( newPoint->getZ(), existingPoint->getZ() ) );

mPointVector.remove( mPointVector.count() - 1 );
delete newPoint;
Expand Down
8 changes: 4 additions & 4 deletions src/analysis/interpolation/MathUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ double MathUtils::distPointFromLine( Point3D* thepoint, Point3D* p1, Point3D* p2
double a = normal.getX();
double b = normal.getY();
double c = -( normal.getX() * p2->getX() + normal.getY() * p2->getY() );
double distance = fabs(( a * thepoint->getX() + b * thepoint->getY() + c ) / ( sqrt( a * a + b * b ) ) );
double distance = qAbs(( a * thepoint->getX() + b * thepoint->getY() + c ) / ( sqrt( a * a + b * b ) ) );
return distance;
}
else
Expand Down Expand Up @@ -250,8 +250,8 @@ bool MathUtils::inCircle( Point3D* testp, Point3D* p1, Point3D* p2, Point3D* p3
double px = testp->getX();
double py = testp->getY();

double xmin = min( min( ax, px ), min( bx, cx ) );
double ymin = min( min( ay, py ), min( by, cy ) );
double xmin = qMin( qMin( ax, px ), qMin( bx, cx ) );
double ymin = qMin( qMin( ay, py ), qMin( by, cy ) );
ax -= xmin;
bx -= xmin;
cx -= xmin;
Expand Down Expand Up @@ -479,7 +479,7 @@ double MathUtils::power( double a, int b )
return 1;
}
double tmp = a;
for ( int i = 2; i <= fabs(( double )b ); i++ )
for ( int i = 2; i <= qAbs(( double )b ); i++ )
{

a *= tmp;
Expand Down
4 changes: 0 additions & 4 deletions src/analysis/interpolation/MathUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#ifndef MATHUTILS_H
#define MATHUTILS_H

#ifndef Q_OS_MACX
#include <cmath>
#else
#include <math.h>
#endif
#include "Vector3D.h"
#include "Point3D.h"

Expand Down
4 changes: 0 additions & 4 deletions src/analysis/interpolation/Point3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#ifndef POINT3D_H
#define POINT3D_H

#ifndef Q_OS_MACX
#include <cmath>
#else
#include <math.h>
#endif
#include <iostream>

/**Point3D is a class to represent a three dimensional point*/
Expand Down
4 changes: 0 additions & 4 deletions src/analysis/interpolation/Vector3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#ifndef VECTOR3D_H
#define VECTOR3D_H

#ifndef Q_OS_MACX
#include <cmath>
#else
#include <math.h>
#endif

class ANALYSIS_EXPORT Vector3D
/**
Expand Down
70 changes: 33 additions & 37 deletions src/analysis/raster/qgsrastermatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@
#include "qgsrastermatrix.h"
#include <string.h>

#ifndef Q_OS_MACX
#include <cmath>
#else
#include <math.h>
#endif

QgsRasterMatrix::QgsRasterMatrix(): mColumns( 0 ), mRows( 0 ), mData( 0 )
{
}

QgsRasterMatrix::QgsRasterMatrix( int nCols, int nRows, float* data, double nodataValue ):
mColumns( nCols ), mRows( nRows ), mData( data ), mNodataValue( nodataValue )
mColumns( nCols ), mRows( nRows ), mData( data ), mNodataValue( nodataValue )
{
}

Expand Down Expand Up @@ -163,22 +159,22 @@ bool QgsRasterMatrix::atangens()

bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )
{
if( !mData )
if ( !mData )
{
return false;
}

int nEntries = mColumns * mRows;
double value;
for( int i = 0; i < nEntries; ++i )
for ( int i = 0; i < nEntries; ++i )
{
value = mData[i];
if( value != mNodataValue )
if ( value != mNodataValue )
{
switch( op )
switch ( op )
{
case opSQRT:
if( value < 0 ) //no complex numbers
if ( value < 0 ) //no complex numbers
{
mData[i] = static_cast<float>( mNodataValue );
}
Expand Down Expand Up @@ -213,15 +209,15 @@ bool QgsRasterMatrix::oneArgumentOperation( OneArgOperator op )

bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMatrix& other )
{
if( isNumber() && other.isNumber() ) //operation on two 1x1 matrices
if ( isNumber() && other.isNumber() ) //operation on two 1x1 matrices
{
//operations with nodata values always generate nodata
if( mData[0] == mNodataValue || other.number() == other.nodataValue() )
if ( mData[0] == mNodataValue || other.number() == other.nodataValue() )
{
mData[0] = static_cast<float>( mNodataValue );
return true;
}
switch( op )
switch ( op )
{
case opPLUS:
mData[0] = static_cast<float>( number() + other.number() );
Expand All @@ -233,7 +229,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
mData[0] = static_cast<float>( number() * other.number() );
break;
case opDIV:
if( other.number() == 0 )
if ( other.number() == 0 )
{
mData[0] = static_cast<float>( mNodataValue );
}
Expand All @@ -243,7 +239,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
}
break;
case opPOW:
if( !testPowerValidity( mData[0], ( float ) other.number() ) )
if ( !testPowerValidity( mData[0], ( float ) other.number() ) )
{
mData[0] = static_cast<float>( mNodataValue );
}
Expand Down Expand Up @@ -275,22 +271,22 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
}

//two matrices
if( !isNumber() && !other.isNumber() )
if ( !isNumber() && !other.isNumber() )
{
float* matrix = other.mData;
int nEntries = mColumns * mRows;
double value1, value2;

for( int i = 0; i < nEntries; ++i )
for ( int i = 0; i < nEntries; ++i )
{
value1 = mData[i]; value2 = matrix[i];
if( value1 == mNodataValue || value2 == other.mNodataValue )
if ( value1 == mNodataValue || value2 == other.mNodataValue )
{
mData[i] = static_cast<float>( mNodataValue );
}
else
{
switch( op )
switch ( op )
{
case opPLUS:
mData[i] = static_cast<float>( value1 + value2 );
Expand All @@ -302,7 +298,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
mData[i] = static_cast<float>( value1 * value2 );
break;
case opDIV:
if( value2 == 0 )
if ( value2 == 0 )
{
mData[i] = static_cast<float>( mNodataValue );
}
Expand All @@ -312,7 +308,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
}
break;
case opPOW:
if( !testPowerValidity( value1, value2 ) )
if ( !testPowerValidity( value1, value2 ) )
{
mData[i] = static_cast<float>( mNodataValue );
}
Expand Down Expand Up @@ -346,7 +342,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
}

//this matrix is a single number and the other one a real matrix
if( isNumber() )
if ( isNumber() )
{
float* matrix = other.mData;
int nEntries = other.nColumns() * other.nRows();
Expand All @@ -355,24 +351,24 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
mData = new float[nEntries]; mColumns = other.nColumns(); mRows = other.nRows();
mNodataValue = other.nodataValue();

if( value == mNodataValue )
if ( value == mNodataValue )
{
for( int i = 0; i < nEntries; ++i )
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = static_cast<float>( mNodataValue );
}
return true;
}

for( int i = 0; i < nEntries; ++i )
for ( int i = 0; i < nEntries; ++i )
{
if( matrix[i] == other.mNodataValue )
if ( matrix[i] == other.mNodataValue )
{
mData[i] = static_cast<float>( mNodataValue );
continue;
}

switch( op )
switch ( op )
{
case opPLUS:
mData[i] = static_cast<float>( value + matrix[i] );
Expand All @@ -384,7 +380,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
mData[i] = static_cast<float>( value * matrix[i] );
break;
case opDIV:
if( matrix[i] == 0 )
if ( matrix[i] == 0 )
{
mData[i] = static_cast<float>( mNodataValue );
}
Expand All @@ -394,7 +390,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
}
break;
case opPOW:
if( !testPowerValidity( value, matrix[i] ) )
if ( !testPowerValidity( value, matrix[i] ) )
{
mData[i] = static_cast<float>( mNodataValue );
}
Expand Down Expand Up @@ -430,23 +426,23 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
double value = other.number();
int nEntries = mColumns * mRows;

if( other.number() == other.mNodataValue )
if ( other.number() == other.mNodataValue )
{
for( int i = 0; i < nEntries; ++i )
for ( int i = 0; i < nEntries; ++i )
{
mData[i] = static_cast<float>( mNodataValue );
}
return true;
}

for( int i = 0; i < nEntries; ++i )
for ( int i = 0; i < nEntries; ++i )
{
if( mData[i] == mNodataValue )
if ( mData[i] == mNodataValue )
{
continue;
}

switch( op )
switch ( op )
{
case opPLUS:
mData[i] = static_cast<float>( mData[i] + value );
Expand All @@ -458,7 +454,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
mData[i] = static_cast<float>( mData[i] * value );
break;
case opDIV:
if( value == 0 )
if ( value == 0 )
{
mData[i] = static_cast<float>( mNodataValue );
}
Expand All @@ -468,7 +464,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
}
break;
case opPOW:
if( !testPowerValidity( mData[i], value ) )
if ( !testPowerValidity( mData[i], value ) )
{
mData[i] = static_cast<float>( mNodataValue );
}
Expand Down Expand Up @@ -503,7 +499,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa

bool QgsRasterMatrix::testPowerValidity( double base, double power )
{
if(( base == 0 && power < 0 ) || ( power < 0 && ( power - floor( power ) ) > 0 ) )
if (( base == 0 && power < 0 ) || ( power < 0 && ( power - floor( power ) ) > 0 ) )
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ void QgsLegend::legendLayerZoomNative()
QgsDebugMsg( "Raster units per pixel : " + QString::number( layer->rasterUnitsPerPixel() ) );
QgsDebugMsg( "MapUnitsPerPixel before : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );

mMapCanvas->zoomByFactor( fabs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
mMapCanvas->refresh();

QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
Expand Down
5 changes: 0 additions & 5 deletions src/app/qgsdisplayangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@

#include "qgsdisplayangle.h"
#include <QSettings>

#ifndef Q_OS_MACX
#include <cmath>
#else
#include <math.h>
#endif

QgsDisplayAngle::QgsDisplayAngle( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslabeldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void QgsLabelDialog::changeBufferColor( void )
int QgsLabelDialog::itemNoForField( QString theFieldName, QStringList theFieldList )
{
//if no matches assume first item in list is blank and return that
return std::max( 0, theFieldList.indexOf( theFieldName ) );
return qMax( 0, theFieldList.indexOf( theFieldName ) );
}

QgsLabelDialog::~QgsLabelDialog()
Expand Down
9 changes: 2 additions & 7 deletions src/app/qgsmaptoolmeasureangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
#include "qgsrubberband.h"
#include <QMouseEvent>
#include <QSettings>

#ifndef Q_OS_MACX
#include <cmath>
#else
#include <math.h>
#endif

QgsMapToolMeasureAngle::QgsMapToolMeasureAngle( QgsMapCanvas* canvas ): QgsMapTool( canvas ), mRubberBand( 0 ), mResultDisplay( 0 )
{
Expand Down Expand Up @@ -57,9 +52,9 @@ void QgsMapToolMeasureAngle::canvasMoveEvent( QMouseEvent * e )
double azimutOne = distArea->bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimutTwo = distArea->bearing( mAnglePoints.at( 1 ), point );
double resultAngle = azimutTwo - azimutOne;
QgsDebugMsg( QString::number( fabs( resultAngle ) ) );
QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
QgsDebugMsg( QString::number( M_PI ) );
if ( fabs( resultAngle ) > M_PI )
if ( qAbs( resultAngle ) > M_PI )
{
if ( resultAngle < 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolnodetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "qgsvectordataprovider.h"
#include "qgstolerance.h"
#include "qgsgeometry.h"
#include <math.h>
#include <cmath>
#include <QMouseEvent>
#include <QMessageBox>
#include "qgslogger.h"
Expand Down
Loading

0 comments on commit 2f0c705

Please sign in to comment.