Skip to content
Permalink
Browse files

(q)atan2 -> std::atan2

  • Loading branch information
nyalldawson committed Aug 24, 2017
1 parent 031bf41 commit 249b5050aaa2ea48e0b6bf8fa0d67b8832798a0f
@@ -39,7 +39,7 @@ float QgsAspectFilter::processNineCellWindow(
}
else
{
return 180.0 + atan2( derX, derY ) * 180.0 / M_PI;
return 180.0 + std::atan2( derX, derY ) * 180.0 / M_PI;
}
}

@@ -47,7 +47,7 @@ float QgsHillshadeFilter::processNineCellWindow( float *x11, float *x21, float *
}
else
{
aspect_rad = M_PI + atan2( derX, derY );
aspect_rad = M_PI + std::atan2( derX, derY );
}
return qMax( 0.0, 255.0 * ( ( cos( zenith_rad ) * cos( slope_rad ) ) + ( sin( zenith_rad ) * sin( slope_rad ) * cos( azimuth_rad - aspect_rad ) ) ) );
}
@@ -957,7 +957,7 @@ void DRW_Ellipse::toPolyline( DRW_Polyline *pol, int parts ) const
double radMajor = sqrt( secPoint.x * secPoint.x + secPoint.y * secPoint.y );
double radMinor = radMajor * ratio;
//calculate sin & cos of included angle
double incAngle = atan2( secPoint.y, secPoint.x );
double incAngle = std::atan2( secPoint.y, secPoint.x );
double cosRot = cos( incAngle );
double sinRot = sin( incAngle );

@@ -1860,7 +1860,7 @@ void DRW_MText::updateAngle()
{
if ( haveXAxis )
{
angle = atan2( secPoint.y, secPoint.x ) * 180 / M_PI;
angle = std::atan2( secPoint.y, secPoint.x ) * 180 / M_PI;
}
}

@@ -681,7 +681,7 @@ QgsPointXY QgsNodeTool::positionForEndpointMarker( const QgsPointLocator::Match
double dx = pt1.x() - pt0.x();
double dy = pt1.y() - pt0.y();
double dist = 15 * canvas()->mapSettings().mapUnitsPerPixel();
double angle = atan2( dy, dx ); // to the top: angle=0, to the right: angle=90, to the left: angle=-90
double angle = std::atan2( dy, dx ); // to the top: angle=0, to the right: angle=90, to the left: angle=-90
double x = pt1.x() + cos( angle ) * dist;
double y = pt1.y() + sin( angle ) * dist;
return QgsPointXY( x, y );
@@ -152,7 +152,7 @@ void QgsMapToolRotateFeature::canvasMoveEvent( QgsMapMouseEvent *e )
{
const double XDistance = e->pos().x() - mStPoint.x();
const double YDistance = e->pos().y() - mStPoint.y();
double rotation = atan2( YDistance, XDistance ) * ( 180 / PI );
double rotation = std::atan2( YDistance, XDistance ) * ( 180 / PI );

if ( mRotationWidget )
{
@@ -297,7 +297,7 @@ void QgsMapToolRotateFeature::canvasReleaseEvent( QgsMapMouseEvent *e )

double XDistance = mInitialPos.x() - mAnchorPoint->x();
double YDistance = mInitialPos.y() - mAnchorPoint->y() ;
mRotationOffset = atan2( YDistance, XDistance ) * ( 180 / PI );
mRotationOffset = std::atan2( YDistance, XDistance ) * ( 180 / PI );

createRotationWidget();
if ( e->modifiers() & Qt::ShiftModifier )
@@ -204,7 +204,7 @@ double QgsMapToolRotatePointSymbols::calculateAzimut( QPoint mousePos )
{
int dx = mousePos.x() - mSnappedPoint.x();
int dy = mousePos.y() - mSnappedPoint.y();
return 180 - atan2( ( double ) dx, ( double ) dy ) * 180.0 / M_PI;
return 180 - std::atan2( ( double ) dx, ( double ) dy ) * 180.0 / M_PI;
}

void QgsMapToolRotatePointSymbols::createPixmapItem( QgsMarkerSymbol *markerSymbol )
@@ -288,7 +288,7 @@ static QVariant fcnAtan2( const QVariantList &values, const QgsExpressionContext
{
double y = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
double x = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
return QVariant( atan2( y, x ) );
return QVariant( std::atan2( y, x ) );
}
static QVariant fcnExp( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
{
@@ -199,7 +199,7 @@ QgsPointSequence QgsEllipse::points( unsigned int segments ) const
double m = mCenter.m();

QVector<double> t;
double azimuth = atan2( quadrant().at( 0 ).y() - mCenter.y(), quadrant().at( 0 ).x() - mCenter.x() );
double azimuth = std::atan2( quadrant().at( 0 ).y() - mCenter.y(), quadrant().at( 0 ).x() - mCenter.x() );
for ( unsigned int i = 0; i < segments; ++i )
{
t.append( 2 * M_PI - ( ( 2 * M_PI ) / segments * i ) ); // Since the algorithm used rotates in the trigonometric direction (counterclockwise)
@@ -430,7 +430,7 @@ QgsPoint QgsGeometryUtils::pointOnLineWithDistance( const QgsPoint &startPoint,

double QgsGeometryUtils::ccwAngle( double dy, double dx )
{
double angle = atan2( dy, dx ) * 180 / M_PI;
double angle = std::atan2( dy, dx ) * 180 / M_PI;
if ( angle < 0 )
{
return 360 + angle;
@@ -664,9 +664,9 @@ void QgsGeometryUtils::segmentizeArc( const QgsPoint &p1, const QgsPoint &p2, co
}

//angles of pt1, pt2, pt3
double a1 = atan2( circlePoint1.y() - centerY, circlePoint1.x() - centerX );
double a2 = atan2( circlePoint2.y() - centerY, circlePoint2.x() - centerX );
double a3 = atan2( circlePoint3.y() - centerY, circlePoint3.x() - centerX );
double a1 = std::atan2( circlePoint1.y() - centerY, circlePoint1.x() - centerX );
double a2 = std::atan2( circlePoint2.y() - centerY, circlePoint2.x() - centerX );
double a3 = std::atan2( circlePoint3.y() - centerY, circlePoint3.x() - centerX );

/* Adjust a3 up so we can increment from a1 to a3 cleanly */
if ( a3 <= a1 )
@@ -1092,15 +1092,15 @@ QgsLineString QgsGeometryUtils::perpendicularSegment( const QgsPoint &p, const Q

double QgsGeometryUtils::lineAngle( double x1, double y1, double x2, double y2 )
{
double at = atan2( y2 - y1, x2 - x1 );
double at = std::atan2( y2 - y1, x2 - x1 );
double a = -at + M_PI / 2.0;
return normalizedAngle( a );
}

double QgsGeometryUtils::angleBetweenThreePoints( double x1, double y1, double x2, double y2, double x3, double y3 )
{
double angle1 = atan2( y1 - y2, x1 - x2 );
double angle2 = atan2( y3 - y2, x3 - x2 );
double angle1 = std::atan2( y1 - y2, x1 - x2 );
double angle2 = std::atan2( y3 - y2, x3 - x2 );
return normalizedAngle( angle1 - angle2 );
}

@@ -538,7 +538,7 @@ double QgsPoint::azimuth( const QgsPoint &other ) const
{
double dx = other.x() - mX;
double dy = other.y() - mY;
return ( atan2( dx, dy ) * 180.0 / M_PI );
return ( std::atan2( dx, dy ) * 180.0 / M_PI );
}

double QgsPoint::inclination( const QgsPoint &other ) const
@@ -456,8 +456,8 @@ int FeaturePart::createCandidatesAroundPoint( double x, double y, QList< LabelPo

if ( distanceToLabel > 0 )
{
gamma1 = atan2( labelHeight / 2, distanceToLabel + labelWidth / 2 );
gamma2 = atan2( labelWidth / 2, distanceToLabel + labelHeight / 2 );
gamma1 = std::atan2( labelHeight / 2, distanceToLabel + labelWidth / 2 );
gamma2 = std::atan2( labelWidth / 2, distanceToLabel + labelHeight / 2 );
}
else
{
@@ -629,7 +629,7 @@ int FeaturePart::createCandidatesAlongLineNearStraightSegments( QList<LabelPosit
continue;
if ( qgsDoubleNear( y1, y2 ) && qgsDoubleNear( x1, x2 ) )
continue;
double vertexAngle = M_PI - ( atan2( y3 - y2, x3 - x2 ) - atan2( y2 - y1, x2 - x1 ) );
double vertexAngle = M_PI - ( std::atan2( y3 - y2, x3 - x2 ) - std::atan2( y2 - y1, x2 - x1 ) );
vertexAngle = QgsGeometryUtils::normalizedAngle( vertexAngle );

// extreme angles form more than 45 degree angle at a node - these are the ones we don't want labels to cross
@@ -670,7 +670,7 @@ int FeaturePart::createCandidatesAlongLineNearStraightSegments( QList<LabelPosit
{
// at an extreme angle node, so reset counters
straightSegmentLengths << currentStraightSegmentLength;
straightSegmentAngles << QgsGeometryUtils::normalizedAngle( atan2( y[i] - segmentStartY, x[i] - segmentStartX ) );
straightSegmentAngles << QgsGeometryUtils::normalizedAngle( std::atan2( y[i] - segmentStartY, x[i] - segmentStartX ) );
longestSegmentLength = qMax( longestSegmentLength, currentStraightSegmentLength );
segmentIndex++;
currentStraightSegmentLength = 0;
@@ -681,7 +681,7 @@ int FeaturePart::createCandidatesAlongLineNearStraightSegments( QList<LabelPosit
}
distanceToSegment[line->nbPoints - 1] = totalLineLength;
straightSegmentLengths << currentStraightSegmentLength;
straightSegmentAngles << QgsGeometryUtils::normalizedAngle( atan2( y[numberNodes - 1] - segmentStartY, x[numberNodes - 1] - segmentStartX ) );
straightSegmentAngles << QgsGeometryUtils::normalizedAngle( std::atan2( y[numberNodes - 1] - segmentStartY, x[numberNodes - 1] - segmentStartX ) );
longestSegmentLength = qMax( longestSegmentLength, currentStraightSegmentLength );
double middleOfLine = totalLineLength / 2.0;

@@ -765,7 +765,7 @@ int FeaturePart::createCandidatesAlongLineNearStraightSegments( QList<LabelPosit
angle = 0.0;
}
else
angle = atan2( candidateEndY - candidateStartY, candidateEndX - candidateStartX );
angle = std::atan2( candidateEndY - candidateStartY, candidateEndX - candidateStartX );

beta = angle + M_PI / 2;

@@ -910,7 +910,7 @@ int FeaturePart::createCandidatesAlongLineNearMidpoint( QList<LabelPosition *> &
angle = 0.0;
}
else
angle = atan2( candidateEndY - candidateStartY, candidateEndX - candidateStartX );
angle = std::atan2( candidateEndY - candidateStartY, candidateEndX - candidateStartX );

beta = angle + M_PI / 2;

@@ -1022,7 +1022,7 @@ LabelPosition *FeaturePart::curvedPlacementAtOffset( PointSet *path_positions, d
// Determine the angle of the path segment under consideration
double dx = path_positions->x[endindex] - path_positions->x[index];
double dy = path_positions->y[endindex] - path_positions->y[index];
double line_angle = atan2( -dy, dx );
double line_angle = std::atan2( -dy, dx );

bool isRightToLeft = ( line_angle > 0.55 * M_PI || line_angle < -0.45 * M_PI );
reversed = isRightToLeft;
@@ -1051,7 +1051,7 @@ LabelPosition *FeaturePart::curvedPlacementAtOffset( PointSet *path_positions, d
double dx = new_x - old_x;
double dy = new_y - old_y;

double angle = atan2( -dy, dx );
double angle = std::atan2( -dy, dx );

for ( int i = 0; i < li->char_num; i++ )
{
@@ -1071,7 +1071,7 @@ LabelPosition *FeaturePart::curvedPlacementAtOffset( PointSet *path_positions, d
}

// Calculate angle from the start of the character to the end based on start_/end_ position
angle = atan2( start_y - end_y, end_x - start_x );
angle = std::atan2( start_y - end_y, end_x - start_x );

// Test last_character_angle vs angle
// since our rendering angle has changed then check against our
@@ -1246,7 +1246,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition * > &lPos
slp->setCost( cost );

// average angle is calculated with respect to periodicity of angles
double angle_avg = atan2( sin_avg / li->char_num, cos_avg / li->char_num );
double angle_avg = std::atan2( sin_avg / li->char_num, cos_avg / li->char_num );
bool localreversed = flip ? !reversed : reversed;
// displacement - we loop through 3 times, generating above, online then below line placements successively
for ( int i = 0; i <= 2; ++i )
@@ -1446,7 +1446,7 @@ int FeaturePart::createCandidatesForPolygon( QList< LabelPosition *> &lPos, Poin
alpha = box->alpha;
}

beta = atan2( labelHeight, labelWidth ) + alpha;
beta = std::atan2( labelHeight, labelWidth ) + alpha;


//alpha = box->alpha;
@@ -426,7 +426,7 @@ QgsPointXY QgsDistanceArea::computeSpheroidProject(
{
azimuth = azimuth - M_PI * 2.0;
}
sigma1 = atan2( tan_u1, cos( azimuth ) );
sigma1 = std::atan2( tan_u1, cos( azimuth ) );
sin_alpha = cos( u1 ) * sin( azimuth );
alpha = asin( sin_alpha );
cos_alphasq = 1.0 - POW2( sin_alpha );
@@ -444,12 +444,12 @@ QgsPointXY QgsDistanceArea::computeSpheroidProject(
}
while ( i < 999 && std::fabs( ( last_sigma - sigma ) / sigma ) > 1.0e-9 );

lat2 = atan2( ( sin( u1 ) * cos( sigma ) + cos( u1 ) * sin( sigma ) *
cos( azimuth ) ), ( omf * sqrt( POW2( sin_alpha ) +
POW2( sin( u1 ) * sin( sigma ) - cos( u1 ) * cos( sigma ) *
cos( azimuth ) ) ) ) );
lambda = atan2( ( sin( sigma ) * sin( azimuth ) ), ( cos( u1 ) * cos( sigma ) -
sin( u1 ) * sin( sigma ) * cos( azimuth ) ) );
lat2 = std::atan2( ( sin( u1 ) * cos( sigma ) + cos( u1 ) * sin( sigma ) *
cos( azimuth ) ), ( omf * sqrt( POW2( sin_alpha ) +
POW2( sin( u1 ) * sin( sigma ) - cos( u1 ) * cos( sigma ) *
cos( azimuth ) ) ) ) );
lambda = std::atan2( ( sin( sigma ) * sin( azimuth ) ), ( cos( u1 ) * cos( sigma ) -
sin( u1 ) * sin( sigma ) * cos( azimuth ) ) );
C = ( f / 16.0 ) * cos_alphasq * ( 4.0 + f * ( 4.0 - 3.0 * cos_alphasq ) );
omega = lambda - ( 1.0 - C ) * f * sin_alpha * ( sigma + C * sin( sigma ) *
( cos( two_sigma_m ) + C * cos( sigma ) * ( -1.0 + 2.0 * POW2( cos( two_sigma_m ) ) ) ) );
@@ -525,7 +525,7 @@ double QgsDistanceArea::bearing( const QgsPointXY &p1, const QgsPointXY &p2 ) co
{
double dx = p2.x() - p1.x();
double dy = p2.y() - p1.y();
bearing = atan2( dx, dy );
bearing = std::atan2( dx, dy );
}

return bearing;
@@ -579,7 +579,7 @@ double QgsDistanceArea::computeDistanceBearing(
tu2 = ( cosU1 * sinU2 - sinU1 * cosU2 * cosLambda );
sinSigma = sqrt( tu1 * tu1 + tu2 * tu2 );
cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
sigma = atan2( sinSigma, cosSigma );
sigma = std::atan2( sinSigma, cosSigma );
alpha = asin( cosU1 * cosU2 * sinLambda / sinSigma );
cosSqAlpha = cos( alpha ) * cos( alpha );
cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha;
@@ -601,12 +601,12 @@ double QgsDistanceArea::computeDistanceBearing(

if ( course1 )
{
*course1 = atan2( tu1, tu2 );
*course1 = std::atan2( tu1, tu2 );
}
if ( course2 )
{
// PI is added to return azimuth from P2 to P1
*course2 = atan2( cosU1 * sinLambda, -sinU1 * cosU2 + cosU1 * sinU2 * cosLambda ) + M_PI;
*course2 = std::atan2( cosU1 * sinLambda, -sinU1 * cosU2 + cosU1 * sinU2 * cosLambda ) + M_PI;
}

return s;
@@ -285,7 +285,7 @@ double QgsPointXY::azimuth( const QgsPointXY &other ) const
{
double dx = other.x() - mX;
double dy = other.y() - mY;
return ( atan2( dx, dy ) * 180.0 / M_PI );
return ( std::atan2( dx, dy ) * 180.0 / M_PI );
}

QgsPointXY QgsPointXY::project( double distance, double bearing ) const
@@ -117,7 +117,7 @@ double QgsScaleCalculator::calculateGeographicDistance( const QgsRectangle &mapE
double lat = ( mapExtent.yMaximum() + mapExtent.yMinimum() ) * 0.5;
static const double RADS = ( 4.0 * atan( 1.0 ) ) / 180.0;
double a = std::pow( cos( lat * RADS ), 2 );
double c = 2.0 * atan2( sqrt( a ), sqrt( 1.0 - a ) );
double c = 2.0 * std::atan2( sqrt( a ), sqrt( 1.0 - a ) );
static const double RA = 6378000; // [m]
// The eccentricity. This comes from sqrt(1.0 - rb*rb/(ra*ra)) with rb set
// to 6357000 m.
@@ -96,7 +96,7 @@ QgsVector QgsVector::perpVector() const

double QgsVector::angle() const
{
double angle = atan2( mY, mX );
double angle = std::atan2( mY, mX );
return angle < 0.0 ? angle + 2.0 * M_PI : angle;
}

@@ -107,7 +107,7 @@ double QgsVector::angle( QgsVector v ) const

QgsVector QgsVector::rotateBy( double rot ) const
{
double angle = atan2( mY, mX ) + rot;
double angle = std::atan2( mY, mX ) + rot;
double len = length();
return QgsVector( len * cos( angle ), len * sin( angle ) );
}
@@ -211,7 +211,7 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext
double derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33, cellYSize );

double slopeRad = atan( mZFactor * sqrt( derX * derX + derY * derY ) );
double aspectRad = atan2( derX, -derY );
double aspectRad = std::atan2( derX, -derY );


double grayValue;
@@ -438,8 +438,8 @@ void spiralArcTo( QPainterPath &path, QPointF center, qreal startAngle, qreal st
else
{
// angles in the new circle
qreal a1 = atan2( cCenter.y() - A.y(), A.x() - cCenter.x() );
qreal a2 = atan2( cCenter.y() - I2.y(), I2.x() - cCenter.x() );
qreal a1 = std::atan2( cCenter.y() - A.y(), A.x() - cCenter.x() );
qreal a2 = std::atan2( cCenter.y() - I2.y(), I2.x() - cCenter.x() );
pathArcTo( path, cCenter, cRadius, a1, a2, direction );
}

@@ -452,8 +452,8 @@ void spiralArcTo( QPainterPath &path, QPointF center, qreal startAngle, qreal st
else
{
// angles in the new circle
qreal a1 = atan2( cCenter.y() - I2.y(), I2.x() - cCenter.x() );
qreal a2 = atan2( cCenter.y() - B.y(), B.x() - cCenter.x() );
qreal a1 = std::atan2( cCenter.y() - I2.y(), I2.x() - cCenter.x() );
qreal a2 = std::atan2( cCenter.y() - B.y(), B.x() - cCenter.x() );
pathArcTo( path, cCenter, cRadius, a1, a2, direction );
}
}
@@ -473,9 +473,9 @@ QPolygonF curvedArrow( QPointF po, QPointF pm, QPointF pd,
}

// angles of each point
qreal angle_o = clampAngle( atan2( circleCenter.y() - po.y(), po.x() - circleCenter.x() ) );
qreal angle_m = clampAngle( atan2( circleCenter.y() - pm.y(), pm.x() - circleCenter.x() ) );
qreal angle_d = clampAngle( atan2( circleCenter.y() - pd.y(), pd.x() - circleCenter.x() ) );
qreal angle_o = clampAngle( std::atan2( circleCenter.y() - po.y(), po.x() - circleCenter.x() ) );
qreal angle_m = clampAngle( std::atan2( circleCenter.y() - pm.y(), pm.x() - circleCenter.x() ) );
qreal angle_d = clampAngle( std::atan2( circleCenter.y() - pd.y(), pd.x() - circleCenter.x() ) );

// arc direction : 1 = counter-clockwise, -1 = clockwise
int direction = clampAngle( angle_m - angle_o ) < clampAngle( angle_m - angle_d ) ? 1 : -1;
@@ -2594,7 +2594,7 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext &
width = outputPixelDist / sin( lineAngle * M_PI / 180 );

// recalculate real angle and distance after rounding to pixels
lineAngle = 180 * atan2( static_cast< double >( height ), static_cast< double >( width ) ) / M_PI;
lineAngle = 180 * std::atan2( static_cast< double >( height ), static_cast< double >( width ) ) / M_PI;
if ( lineAngle < 0 )
{
lineAngle += 360.;
@@ -1004,7 +1004,7 @@ static double _averageAngle( QPointF prevPt, QPointF pt, QPointF nextPt )
double a2 = MyLine( pt, nextPt ).angle();
double unitX = cos( a1 ) + cos( a2 ), unitY = sin( a1 ) + sin( a2 );

return atan2( unitY, unitX );
return std::atan2( unitY, unitX );
}

void QgsMarkerLineSymbolLayer::renderPolylineVertex( const QPolygonF &points, QgsSymbolRenderContext &context, Placement placement )

0 comments on commit 249b505

Please sign in to comment.
You can’t perform that action at this time.