Skip to content

Commit

Permalink
Use fabs/abs/labs instead of qAbs
Browse files Browse the repository at this point in the history
Better to stick to standard methods where available instead
of less supported Qt methods
  • Loading branch information
nyalldawson committed Aug 24, 2017
1 parent 4b009f9 commit f2b2c6d
Show file tree
Hide file tree
Showing 71 changed files with 671 additions and 670 deletions.
4 changes: 2 additions & 2 deletions src/analysis/interpolation/MathUtils.cc
Expand Up @@ -210,7 +210,7 @@ double MathUtils::distPointFromLine( QgsPoint *thepoint, QgsPoint *p1, QgsPoint
double a = normal.getX();
double b = normal.getY();
double c = -( normal.getX() * p2->x() + normal.getY() * p2->y() );
double distance = qAbs( ( a * thepoint->x() + b * thepoint->y() + c ) / ( sqrt( a * a + b * b ) ) );
double distance = fabs( ( a * thepoint->x() + b * thepoint->y() + c ) / ( sqrt( a * a + b * b ) ) );
return distance;
}
else
Expand Down Expand Up @@ -471,7 +471,7 @@ double MathUtils::power( double a, int b )
return 1;
}
double tmp = a;
for ( int i = 2; i <= qAbs( ( double )b ); i++ )
for ( int i = 2; i <= abs( b ); i++ )
{

a *= tmp;
Expand Down
8 changes: 4 additions & 4 deletions src/analysis/raster/qgsalignraster.cpp
Expand Up @@ -30,15 +30,15 @@

static double ceil_with_tolerance( double value )
{
if ( qAbs( value - std::round( value ) ) < 1e-6 )
if ( fabs( value - std::round( value ) ) < 1e-6 )
return std::round( value );
else
return qCeil( value );
}

static double floor_with_tolerance( double value )
{
if ( qAbs( value - std::round( value ) ) < 1e-6 )
if ( fabs( value - std::round( value ) ) < 1e-6 )
return std::round( value );
else
return qFloor( value );
Expand Down Expand Up @@ -538,7 +538,7 @@ bool QgsAlignRaster::suggestedWarpOutput( const QgsAlignRaster::RasterInfo &info
if ( eErr != CE_None )
return false;

QSizeF cs( qAbs( adfDstGeoTransform[1] ), qAbs( adfDstGeoTransform[5] ) );
QSizeF cs( fabs( adfDstGeoTransform[1] ), fabs( adfDstGeoTransform[5] ) );

if ( rect )
*rect = QgsRectangle( extents[0], extents[1], extents[2], extents[3] );
Expand Down Expand Up @@ -582,7 +582,7 @@ QgsAlignRaster::RasterInfo::~RasterInfo()

QSizeF QgsAlignRaster::RasterInfo::cellSize() const
{
return QSizeF( qAbs( mGeoTransform[1] ), qAbs( mGeoTransform[5] ) );
return QSizeF( fabs( mGeoTransform[1] ), fabs( mGeoTransform[5] ) );
}

QPointF QgsAlignRaster::RasterInfo::gridOffset() const
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsrelief.cpp
Expand Up @@ -353,7 +353,7 @@ bool QgsRelief::processNineCellWindow( float *x1, float *x2, float *x3, float *x
float aspect = mAspectFilter->processNineCellWindow( x1, x2, x3, x4, x5, x6, x7, x8, x9 );
if ( hillShadeValue285 != mOutputNodataValue && aspect != mOutputNodataValue )
{
double angle_diff = qAbs( 285 - aspect );
double angle_diff = fabs( 285 - aspect );
if ( angle_diff > 180 )
{
angle_diff -= 180;
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/qgsgeometrysnapper.cpp
Expand Up @@ -110,8 +110,8 @@ class Raytracer
// See http://playtechs.blogspot.ch/2007/03/raytracing-on-grid.html
public:
Raytracer( float x0, float y0, float x1, float y1 )
: m_dx( qAbs( x1 - x0 ) )
, m_dy( qAbs( y1 - y0 ) )
: m_dx( fabs( x1 - x0 ) )
, m_dy( fabs( y1 - y0 ) )
, m_x( qFloor( x0 ) )
, m_y( qFloor( y0 ) )
, m_n( 1 )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdecorationscalebar.cpp
Expand Up @@ -113,7 +113,7 @@ void QgsDecorationScaleBar::render( const QgsMapSettings &mapSettings, QgsRender
//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 = qAbs( context.mapToPixel().mapUnitsPerPixel() );
double myMapUnitsPerPixelDouble = fabs( context.mapToPixel().mapUnitsPerPixel() );
double myActualSize = mPreferredSize;

// Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslabelinggui.cpp
Expand Up @@ -237,7 +237,7 @@ void QgsLabelingGui::setLayer( QgsMapLayer *mapLayer )
// curved label max character angles
mMaxCharAngleInDSpinBox->setValue( lyr.maxCurvedCharAngleIn );
// lyr.maxCurvedCharAngleOut must be negative, but it is shown as positive spinbox in GUI
mMaxCharAngleOutDSpinBox->setValue( qAbs( lyr.maxCurvedCharAngleOut ) );
mMaxCharAngleOutDSpinBox->setValue( fabs( lyr.maxCurvedCharAngleOut ) );

wrapCharacterEdit->setText( lyr.wrapChar );
mFontMultiLineAlignComboBox->setCurrentIndex( ( unsigned int ) lyr.multilineAlign );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolmeasureangle.cpp
Expand Up @@ -64,9 +64,9 @@ void QgsMapToolMeasureAngle::canvasMoveEvent( QgsMapMouseEvent *e )
double azimuthOne = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = mDa.bearing( mAnglePoints.at( 1 ), point );
double resultAngle = azimuthTwo - azimuthOne;
QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
QgsDebugMsg( QString::number( fabs( resultAngle ) ) );
QgsDebugMsg( QString::number( M_PI ) );
if ( qAbs( resultAngle ) > M_PI )
if ( fabs( resultAngle ) > M_PI )
{
if ( resultAngle < 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsundowidget.cpp
Expand Up @@ -78,7 +78,7 @@ void QgsUndoWidget::indexChanged( int curIndx )
canRedo = mUndoStack->canRedo();
curCount = mUndoStack->count();
}
int offset = qAbs( mPreviousIndex - curIndx );
int offset = abs( mPreviousIndex - curIndx );

// when individually redoing, differentiate between last redo and a new command added to stack
bool lastRedo = ( mPreviousIndex == ( mPreviousCount - 1 ) && mPreviousCount == curCount && !canRedo );
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerarrow.cpp
Expand Up @@ -409,7 +409,7 @@ void QgsComposerArrow::adaptItemSceneRect()
{
//rectangle containing start and end point
QRectF rect = QRectF( qMin( mStartPoint.x(), mStopPoint.x() ), qMin( mStartPoint.y(), mStopPoint.y() ),
qAbs( mStopPoint.x() - mStartPoint.x() ), qAbs( mStopPoint.y() - mStartPoint.y() ) );
fabs( mStopPoint.x() - mStartPoint.x() ), fabs( mStopPoint.y() - mStartPoint.y() ) );
double enlarge = computeMarkerMargin();
rect.adjust( -enlarge, -enlarge, enlarge, enlarge );
QgsComposerItem::setSceneRect( rect );
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposermapgrid.cpp
Expand Up @@ -1465,11 +1465,11 @@ QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGr
if ( geographic )
{
//insert degree symbol for geographic coordinates
return QString::number( qAbs( value ), 'f', mGridAnnotationPrecision ) + QChar( 176 ) + hemisphere;
return QString::number( fabs( value ), 'f', mGridAnnotationPrecision ) + QChar( 176 ) + hemisphere;
}
else
{
return QString::number( qAbs( value ), 'f', mGridAnnotationPrecision ) + hemisphere;
return QString::number( fabs( value ), 'f', mGridAnnotationPrecision ) + hemisphere;
}
}
else if ( mGridAnnotationFormat == CustomFormat )
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposermousehandles.cpp
Expand Up @@ -593,7 +593,7 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event
double diffY = mouseMoveStopPoint.y() - mMouseMoveStartPos.y();

//it was only a click
if ( qAbs( diffX ) < std::numeric_limits<double>::min() && qAbs( diffY ) < std::numeric_limits<double>::min() )
if ( fabs( diffX ) < std::numeric_limits<double>::min() && fabs( diffY ) < std::numeric_limits<double>::min() )
{
mIsDragging = false;
mIsResizing = false;
Expand Down Expand Up @@ -824,7 +824,7 @@ void QgsComposerMouseHandles::dragMouseMove( QPointF currentPosition, bool lockM
{
//constrained (shift) moving should lock to horizontal/vertical movement
//reset the smaller of the x/y movements
if ( qAbs( moveRectX ) <= qAbs( moveRectY ) )
if ( fabs( moveRectX ) <= fabs( moveRectY ) )
{
moveRectX = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/composer/qgscomposernodesitem.cpp
Expand Up @@ -77,7 +77,7 @@ bool QgsComposerNodesItem::addNode( QPointF pt,

double distance = std::numeric_limits<double>::max();
if ( qIsInf( coef ) )
distance = qAbs( pt1.x() - start.x() );
distance = fabs( pt1.x() - start.x() );
else
{
const double coef2 = ( -1 / coef );
Expand All @@ -86,7 +86,7 @@ bool QgsComposerNodesItem::addNode( QPointF pt,
QPointF inter;
if ( qIsInf( coef2 ) )
{
distance = qAbs( pt1.y() - start.y() );
distance = fabs( pt1.y() - start.y() );
inter.setX( start.x() );
inter.setY( pt1.y() );
}
Expand All @@ -104,7 +104,7 @@ bool QgsComposerNodesItem::addNode( QPointF pt,
const double length3 = computeDistance( pt1, pt2 );
const double length4 = length1 + length2;

if ( qAbs( length3 - length4 ) < std::numeric_limits<float>::epsilon() )
if ( fabs( length3 - length4 ) < std::numeric_limits<float>::epsilon() )
distance = computeDistance( inter, start );
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposerpicture.cpp
Expand Up @@ -578,8 +578,8 @@ void QgsComposerPicture::setSceneRect( const QRectF &rectangle )

//if height has changed more than width, then fix width and set height correspondingly
//else, do the opposite
if ( qAbs( rect().width() - rectangle.width() ) <
qAbs( rect().height() - rectangle.height() ) )
if ( fabs( rect().width() - rectangle.width() ) <
fabs( rect().height() - rectangle.height() ) )
{
newRect.setHeight( targetImageSize.height() * newRect.width() / targetImageSize.width() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfpaintengine.cpp
Expand Up @@ -262,7 +262,7 @@ double QgsDxfPaintEngine::power( double a, int b )
return 1;

double tmp = a;
for ( int i = 2; i <= qAbs( static_cast< double >( b ) ); i++ )
for ( int i = 2; i <= abs( b ); i++ )
a *= tmp;

if ( b > 0 )
Expand Down
4 changes: 2 additions & 2 deletions src/core/effects/qgsimageoperation.cpp
Expand Up @@ -889,8 +889,8 @@ QRect QgsImageOperation::nonTransparentImageRect( const QImage &image, QSize min
if ( center )
{
// recompute min and max to center image
const int dx = qMax( qAbs( xmax - width / 2 ), qAbs( xmin - width / 2 ) );
const int dy = qMax( qAbs( ymax - height / 2 ), qAbs( ymin - height / 2 ) );
const int dx = qMax( abs( xmax - width / 2 ), abs( xmin - width / 2 ) );
const int dy = qMax( abs( ymax - height / 2 ), abs( ymin - height / 2 ) );
xmin = qMax( 0, width / 2 - dx );
xmax = qMin( width, width / 2 + dx );
ymin = qMax( 0, height / 2 - dy );
Expand Down
4 changes: 2 additions & 2 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -1007,13 +1007,13 @@ static QVariant fcnWordwrap( const QVariantList &values, const QgsExpressionCont
if ( strhit == lasthit || strhit == -1 )
{
//if no new backward delimiter found, try to locate forward
strhit = lines[i].indexOf( rx, strcurrent + qAbs( wrap ) );
strhit = lines[i].indexOf( rx, strcurrent + labs( wrap ) );
}
lasthit = strhit;
}
else
{
strhit = lines[i].indexOf( rx, strcurrent + qAbs( wrap ) );
strhit = lines[i].indexOf( rx, strcurrent + labs( wrap ) );
}
if ( strhit > -1 )
{
Expand Down
18 changes: 9 additions & 9 deletions src/core/geometry/qgscircle.cpp
Expand Up @@ -52,24 +52,24 @@ static bool isPerpendicular( const QgsPoint &pt1, const QgsPoint &pt2, const Qgs
double yDelta_b = pt3.y() - pt2.y();
double xDelta_b = pt3.x() - pt2.x();

if ( ( qAbs( xDelta_a ) <= epsilon ) && ( qAbs( yDelta_b ) <= epsilon ) )
if ( ( fabs( xDelta_a ) <= epsilon ) && ( fabs( yDelta_b ) <= epsilon ) )
{
return false;
}

if ( qAbs( yDelta_a ) <= epsilon )
if ( fabs( yDelta_a ) <= epsilon )
{
return true;
}
else if ( qAbs( yDelta_b ) <= epsilon )
else if ( fabs( yDelta_b ) <= epsilon )
{
return true;
}
else if ( qAbs( xDelta_a ) <= epsilon )
else if ( fabs( xDelta_a ) <= epsilon )
{
return true;
}
else if ( qAbs( xDelta_b ) <= epsilon )
else if ( fabs( xDelta_b ) <= epsilon )
{
return true;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ QgsCircle QgsCircle::from3Points( const QgsPoint &pt1, const QgsPoint &pt2, cons
double aSlope = yDelta_a / xDelta_a;
double bSlope = yDelta_b / xDelta_b;

if ( ( qAbs( xDelta_a ) <= epsilon ) && ( qAbs( yDelta_b ) <= epsilon ) )
if ( ( fabs( xDelta_a ) <= epsilon ) && ( fabs( yDelta_b ) <= epsilon ) )
{
center.setX( 0.5 * ( p2.x() + p3.x() ) );
center.setY( 0.5 * ( p1.y() + p2.y() ) );
Expand All @@ -147,7 +147,7 @@ QgsCircle QgsCircle::from3Points( const QgsPoint &pt1, const QgsPoint &pt2, cons
return QgsCircle( center, radius );
}

if ( qAbs( aSlope - bSlope ) <= epsilon )
if ( fabs( aSlope - bSlope ) <= epsilon )
{
return QgsCircle();
}
Expand Down Expand Up @@ -191,8 +191,8 @@ QgsCircle QgsCircle::from3Tangents( const QgsPoint &pt1_tg1, const QgsPoint &pt2

QgsCircle QgsCircle::fromExtent( const QgsPoint &pt1, const QgsPoint &pt2 )
{
double delta_x = qAbs( pt1.x() - pt2.x() );
double delta_y = qAbs( pt1.x() - pt2.y() );
double delta_x = fabs( pt1.x() - pt2.x() );
double delta_y = fabs( pt1.x() - pt2.y() );
if ( !qgsDoubleNear( delta_x, delta_y ) )
{
return QgsCircle();
Expand Down
6 changes: 3 additions & 3 deletions src/core/geometry/qgscircle.h
Expand Up @@ -133,7 +133,7 @@ class CORE_EXPORT QgsCircle : public QgsEllipse
*/
void setSemiMajorAxis( const double semiMajorAxis ) override
{
mSemiMajorAxis = qAbs( semiMajorAxis );
mSemiMajorAxis = fabs( semiMajorAxis );
mSemiMinorAxis = mSemiMajorAxis;
}

Expand All @@ -143,7 +143,7 @@ class CORE_EXPORT QgsCircle : public QgsEllipse
*/
void setSemiMinorAxis( const double semiMinorAxis ) override
{
mSemiMajorAxis = qAbs( semiMinorAxis );
mSemiMajorAxis = fabs( semiMinorAxis );
mSemiMinorAxis = mSemiMajorAxis;
}

Expand All @@ -152,7 +152,7 @@ class CORE_EXPORT QgsCircle : public QgsEllipse
//! Set the radius of the circle
void setRadius( double radius )
{
mSemiMajorAxis = qAbs( radius );
mSemiMajorAxis = fabs( radius );
mSemiMinorAxis = mSemiMajorAxis;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgscurvepolygon.cpp
Expand Up @@ -370,7 +370,7 @@ double QgsCurvePolygon::area() const
{
double area = 0.0;
mExteriorRing->sumUpArea( area );
totalArea += qAbs( area );
totalArea += fabs( area );
}

QList<QgsCurve *>::const_iterator ringIt = mInteriorRings.constBegin();
Expand All @@ -380,7 +380,7 @@ double QgsCurvePolygon::area() const
if ( ( *ringIt )->isRing() )
{
( *ringIt )->sumUpArea( area );
totalArea -= qAbs( area );
totalArea -= fabs( area );
}
}
return totalArea;
Expand Down
12 changes: 6 additions & 6 deletions src/core/geometry/qgsellipse.cpp
Expand Up @@ -25,8 +25,8 @@

void QgsEllipse::normalizeAxis()
{
mSemiMajorAxis = qAbs( mSemiMajorAxis );
mSemiMinorAxis = qAbs( mSemiMinorAxis );
mSemiMajorAxis = fabs( mSemiMajorAxis );
mSemiMinorAxis = fabs( mSemiMinorAxis );
if ( mSemiMajorAxis < mSemiMinorAxis )
{
std::swap( mSemiMajorAxis, mSemiMinorAxis );
Expand Down Expand Up @@ -72,17 +72,17 @@ QgsEllipse QgsEllipse::fromFoci( const QgsPoint &pt1, const QgsPoint &pt2, const
QgsEllipse QgsEllipse::fromExtent( const QgsPoint &pt1, const QgsPoint &pt2 )
{
QgsPoint center = QgsGeometryUtils::midpoint( pt1, pt2 );
double axis_a = qAbs( pt2.x() - pt1.x() ) / 2.0;
double axis_b = qAbs( pt2.y() - pt1.y() ) / 2.0;
double axis_a = fabs( pt2.x() - pt1.x() ) / 2.0;
double axis_b = fabs( pt2.y() - pt1.y() ) / 2.0;
double azimuth = 90.0;

return QgsEllipse( center, axis_a, axis_b, azimuth );
}

QgsEllipse QgsEllipse::fromCenterPoint( const QgsPoint &center, const QgsPoint &pt1 )
{
double axis_a = qAbs( pt1.x() - center.x() );
double axis_b = qAbs( pt1.y() - center.y() );
double axis_a = fabs( pt1.x() - center.x() );
double axis_b = fabs( pt1.y() - center.y() );
double azimuth = 90.0;

return QgsEllipse( center, axis_a, axis_b, azimuth );
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.cpp
Expand Up @@ -2558,7 +2558,7 @@ QgsLineString *smoothCurve( const QgsLineString &line, const unsigned int iterat
QgsPoint p3 = result->pointN( 1 );
double angle = QgsGeometryUtils::angleBetweenThreePoints( p1.x(), p1.y(), p2.x(), p2.y(),
p3.x(), p3.y() );
angle = qAbs( M_PI - angle );
angle = fabs( M_PI - angle );
skipFirst = angle > maxAngleRads;
}
for ( int i = 0; i < result->numPoints() - 1; i++ )
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsinternalgeometryengine.cpp
Expand Up @@ -290,7 +290,7 @@ QgsGeometry QgsInternalGeometryEngine::poleOfInaccessibility( double precision,

bool dotProductWithinAngleTolerance( double dotProduct, double lowerThreshold, double upperThreshold )
{
return lowerThreshold > qAbs( dotProduct ) || qAbs( dotProduct ) > upperThreshold;
return lowerThreshold > fabs( dotProduct ) || fabs( dotProduct ) > upperThreshold;
}

double normalizedDotProduct( const QgsPoint &a, const QgsPoint &b, const QgsPoint &c )
Expand Down Expand Up @@ -341,7 +341,7 @@ double squareness( QgsLineString *ring, double lowerThreshold, double upperThres
if ( !dotProductWithinAngleTolerance( dotProduct, lowerThreshold, upperThreshold ) )
continue;

sum += 2.0 * qMin( qAbs( dotProduct - 1.0 ), qMin( qAbs( dotProduct ), qAbs( dotProduct + 1 ) ) );
sum += 2.0 * qMin( fabs( dotProduct - 1.0 ), qMin( fabs( dotProduct ), fabs( dotProduct + 1 ) ) );
}
a = b;
b = c;
Expand Down

0 comments on commit f2b2c6d

Please sign in to comment.