1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 06:43:22 +02:00

PI defines cleanup

This commit is contained in:
Martin Tůma 2018-05-15 21:51:56 +02:00
parent a762445bce
commit 025a403c73
11 changed files with 34 additions and 49 deletions

View File

@ -271,5 +271,6 @@ win32 {
icons/plt.ico \
icons/rte.ico \
icons/wpt.ico
DEFINES += _USE_MATH_DEFINES
}
DEFINES += APP_VERSION=\\\"$$VERSION\\\"

View File

@ -4,9 +4,6 @@
#include <cmath>
#include <QDebug>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif // M_PI
#define deg2rad(d) (((d)*M_PI)/180.0)
#define rad2deg(d) (((d)*180.0)/M_PI)

View File

@ -20,10 +20,10 @@ RectC::RectC(const Coordinates &center, double radius)
double deltaLon = asin(sin(radDist) / cos(radlat));
minLon = radLon - deltaLon;
if (minLon < MIN_LON)
minLon += 2.0 * M_PI;
minLon += M_2_PI;
maxLon = radLon + deltaLon;
if (maxLon > MAX_LON)
maxLon -= 2.0 * M_PI;
maxLon -= M_2_PI;
} else {
// a pole is within the distance
minLat = qMax(minLat, MIN_LAT);

View File

@ -45,10 +45,6 @@ Defense.
#include "albersequal.h"
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endif // M_PI_2
#define ONE_MINUS_SQR(x) (1.0 - (x) * (x))
#define ALBERS_Q(slat, one_minus_sqr_es_sin, es_sin) \
(_one_minus_es2 * ((slat) / (one_minus_sqr_es_sin) - \
@ -128,9 +124,9 @@ PointD AlbersEqual::ll2xy(const Coordinates &c) const
dlam = deg2rad(c.lon()) - _longitudeOrigin;
if (dlam > M_PI)
dlam -= 2.0 * M_PI;
dlam -= M_2_PI;
if (dlam < -M_PI)
dlam += 2.0 * M_PI;
dlam += M_2_PI;
sin_lat = sin(deg2rad(c.lat()));
es_sin = _es * sin_lat;
@ -216,9 +212,9 @@ Coordinates AlbersEqual::xy2ll(const PointD &p) const
lon = _longitudeOrigin + theta / _n;
if (lon > M_PI)
lon -= M_PI * 2;
lon -= M_2_PI;
if (lon < -M_PI)
lon += M_PI * 2;
lon += M_2_PI;
if (lon > M_PI)
lon = M_PI;

View File

@ -12,12 +12,12 @@
static QPointF ll2m(const Coordinates &c)
{
return QPointF(c.lon(), rad2deg(log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0))));
return QPointF(c.lon(), rad2deg(log(tan(M_PI_4 + deg2rad(c.lat())/2.0))));
}
static Coordinates m2ll(const QPointF &p)
{
return Coordinates(p.x(), rad2deg(2 * atan(exp(deg2rad(p.y()))) - M_PI/2));
return Coordinates(p.x(), rad2deg(2.0 * atan(exp(deg2rad(p.y()))) - M_PI_2));
}
static qreal zoom2scale(int zoom)

View File

@ -45,9 +45,6 @@ Defense.
#include "geocentric.h"
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endif // M_PI_2
#define AD_C 1.0026000
Point3D Geocentric::fromGeodetic(const Coordinates &c, const Datum &datum)
@ -63,7 +60,7 @@ Point3D Geocentric::fromGeodetic(const Coordinates &c, const Datum &datum)
double Rn = e->radius() / (sqrt(1.0 - e2 * slat2));
if (lon > M_PI)
lon -= (2 * M_PI);
lon -= M_2_PI;
return Point3D(Rn * clat * cos(lon), Rn * clat * sin(lon),
(Rn * (1 - e2)) * slat);

View File

@ -45,12 +45,6 @@ Defense.
#include "ellipsoid.h"
#include "lambertconic.h"
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endif // M_PI_2
#ifndef M_PI_4
#define M_PI_4 0.785398163397448309616
#endif /* M_PI_4 */
#define LAMBERT_m(clat, essin) (clat / sqrt(1.0 - essin * essin))
#define LAMBERT2_t(lat, essin, es_over_2) \
@ -72,7 +66,7 @@ LambertConic1::LambertConic1(const Ellipsoid *ellipsoid, double latitudeOrigin,
lat_orig = deg2rad(latitudeOrigin);
_longitudeOrigin = deg2rad(longitudeOrigin);
if (_longitudeOrigin > M_PI)
_longitudeOrigin -= 2 * M_PI;
_longitudeOrigin -= M_2_PI;
_falseEasting = falseEasting;
_falseNorthing = falseNorthing;
@ -111,9 +105,9 @@ PointD LambertConic1::ll2xy(const Coordinates &c) const
dlam = deg2rad(c.lon()) - _longitudeOrigin;
if (dlam > M_PI)
dlam -= 2 * M_PI;
dlam -= M_2_PI;
if (dlam < -M_PI)
dlam += 2 * M_PI;
dlam += M_2_PI;
theta = _n * dlam;
@ -177,13 +171,13 @@ Coordinates LambertConic1::xy2ll(const PointD &p) const
if (lon - M_PI < 3.5e-6)
lon = M_PI;
else
lon -= 2 * M_PI;
lon -= M_2_PI;
}
if (lon < -M_PI) {
if (fabs(lon + M_PI) < 3.5e-6)
lon = -M_PI;
else
lon += 2 * M_PI;
lon += M_2_PI;
}
if (fabs(lon) < 2.0e-7)

View File

@ -56,7 +56,7 @@ Mercator::Mercator(const Ellipsoid *ellipsoid, double latitudeOrigin,
_latitudeOrigin = deg2rad(latitudeOrigin);
_longitudeOrigin = deg2rad(longitudeOrigin);
if (_longitudeOrigin > M_PI)
_longitudeOrigin -= 2*M_PI;
_longitudeOrigin -= M_2_PI;
_falseNorthing = falseNorthing;
_falseEasting = falseEasting;
_es = 2 * ellipsoid->flattening() - ellipsoid->flattening()
@ -85,16 +85,16 @@ PointD Mercator::ll2xy(const Coordinates &c) const
double pow_temp;
if (lon > M_PI)
lon -= 2*M_PI;
lon -= M_2_PI;
e_x_sinlat = _e * sin(lat);
tan_temp = tan(M_PI / 4.e0 + lat / 2.e0);
tan_temp = tan(M_PI_4 + lat / 2.e0);
pow_temp = pow((1.e0 - e_x_sinlat) / (1.e0 + e_x_sinlat), _e / 2.e0);
ctanz2 = tan_temp * pow_temp;
delta_lon = lon - _longitudeOrigin;
if (delta_lon > M_PI)
delta_lon -= 2 * M_PI;
delta_lon -= M_2_PI;
if (delta_lon < -M_PI)
delta_lon += 2 * M_PI;
delta_lon += M_2_PI;
return PointD(_scaleFactor * _a * delta_lon + _falseEasting,
_scaleFactor * _a * log(ctanz2) + _falseNorthing);
@ -110,13 +110,13 @@ Coordinates Mercator::xy2ll(const PointD &p) const
dy = p.y() - _falseNorthing;
dx = p.x() - _falseEasting;
lon = _longitudeOrigin + dx / (_scaleFactor * _a);
xphi = M_PI / 2.e0 - 2.e0 * atan(1.e0 / exp(dy / (_scaleFactor * _a)));
xphi = M_PI_2 - 2.e0 * atan(1.e0 / exp(dy / (_scaleFactor * _a)));
lat = xphi + _ab * sin(2.e0 * xphi) + _bb * sin(4.e0 * xphi)
+ _cb * sin(6.e0 * xphi) + _db * sin(8.e0 * xphi);
if (lon > M_PI)
lon -= 2 * M_PI;
lon -= M_2_PI;
if (lon < -M_PI)
lon += 2 * M_PI;
lon += M_2_PI;
return Coordinates(rad2deg(lon), rad2deg(lat));
}

View File

@ -12,12 +12,12 @@
static QPointF ll2m(const Coordinates &c)
{
return QPointF(c.lon(), rad2deg(log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0))));
return QPointF(c.lon(), rad2deg(log(tan(M_PI_4 + deg2rad(c.lat())/2.0))));
}
static Coordinates m2ll(const QPointF &p)
{
return Coordinates(p.x(), rad2deg(2 * atan(exp(deg2rad(p.y()))) - M_PI/2));
return Coordinates(p.x(), rad2deg(2.0 * atan(exp(deg2rad(p.y()))) - M_PI_2));
}
static QPoint mercator2tile(const QPointF &m, int z)

View File

@ -109,9 +109,9 @@ PointD TransverseMercator::ll2xy(const Coordinates &c) const
dlam = deg2rad(c.lon()) - _longitudeOrigin;
if (dlam > M_PI)
dlam -= (2 * M_PI);
dlam -= M_2_PI;
if (dlam < -M_PI)
dlam += (2 * M_PI);
dlam += M_2_PI;
if (fabs(dlam) < 2.e-10)
dlam = 0.0;
@ -237,20 +237,20 @@ Coordinates TransverseMercator::xy2ll(const PointD &p) const
lat = M_PI - lat;
lon += M_PI;
if (lon > M_PI)
lon -= (2 * M_PI);
lon -= M_2_PI;
}
while (lat < deg2rad(-90.0)) {
lat = - (lat + M_PI);
lon += M_PI;
if (lon > M_PI)
lon -= (2 * M_PI);
lon -= M_2_PI;
}
if (lon > (2 * M_PI))
lon -= (2 * M_PI);
if (lon > M_2_PI)
lon -= M_2_PI;
if (lon < -M_PI)
lon += (2 * M_PI);
lon += M_2_PI;
return Coordinates(rad2deg(lon), rad2deg(lat));
}

View File

@ -6,11 +6,11 @@
PointD WebMercator::ll2xy(const Coordinates &c) const
{
return PointD(deg2rad(c.lon()) * WGS84_RADIUS,
log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0)) * WGS84_RADIUS);
log(tan(M_PI_4 + deg2rad(c.lat())/2.0)) * WGS84_RADIUS);
}
Coordinates WebMercator::xy2ll(const PointD &p) const
{
return Coordinates(rad2deg(p.x() / WGS84_RADIUS),
rad2deg(2 * atan(exp(p.y() / WGS84_RADIUS)) - M_PI/2));
rad2deg(2.0 * atan(exp(p.y() / WGS84_RADIUS)) - M_PI_2));
}