Commit de9e42ba authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Removing nested class declaration within CoordinateConversion.

parent c2b1b377
Pipeline #12909 failed with stages
in 6 minutes and 17 seconds
...@@ -6,36 +6,36 @@ ...@@ -6,36 +6,36 @@
namespace radix namespace radix
{ {
const std::array<char, 22> CoordinateConversion::UTMZones::letters = { const std::array<char, 22> UTMZones::letters = {
{'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', {'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Z'}}; 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Z'}};
const std::array<short, 22> CoordinateConversion::UTMZones::degrees = { const std::array<short, 22> UTMZones::degrees = {
{-90, -84, -72, -64, -56, -48, -40, -32, -24, -16, -8, {-90, -84, -72, -64, -56, -48, -40, -32, -24, -16, -8,
0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84}}; 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84}};
const std::array<char, 11> CoordinateConversion::UTMZones::neg_letters = { const std::array<char, 11> UTMZones::neg_letters = {
{'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M'}}; {'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M'}};
const std::array<short, 11> CoordinateConversion::UTMZones::neg_degrees = { const std::array<short, 11> UTMZones::neg_degrees = {
{-90, -84, -72, -64, -56, -48, -40, -32, -24, -16, -8}}; {-90, -84, -72, -64, -56, -48, -40, -32, -24, -16, -8}};
const std::array<char, 11> CoordinateConversion::UTMZones::pos_letters = { const std::array<char, 11> UTMZones::pos_letters = {
{'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Z'}}; {'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Z'}};
const std::array<short, 11> CoordinateConversion::UTMZones::pos_degrees = { const std::array<short, 11> UTMZones::pos_degrees = {
{0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84}}; {0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84}};
const std::array<char, 11> const std::array<char, 11>
CoordinateConversion::UTM2LatLon::southern_hemisphere = { UTM2LatLon::southern_hemisphere = {
{'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'L', 'L', 'M'}}; {'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'L', 'L', 'M'}};
short CoordinateConversion::UTMZones::latZoneDegree(char letter) short UTMZones::latZoneDegree(char letter)
{ {
auto itr = std::find(letters.begin(), letters.end(), letter); auto itr = std::find(letters.begin(), letters.end(), letter);
if (itr == letters.end()) return -100; if (itr == letters.end()) return -100;
return *itr; return *itr;
} }
short CoordinateConversion::UTMZones::lonZone(double longitude) short UTMZones::lonZone(double longitude)
{ {
double longZone = 0; double longZone = 0;
if (longitude < 0.0) if (longitude < 0.0)
...@@ -49,7 +49,7 @@ short CoordinateConversion::UTMZones::lonZone(double longitude) ...@@ -49,7 +49,7 @@ short CoordinateConversion::UTMZones::lonZone(double longitude)
return short(longZone); return short(longZone);
} }
char CoordinateConversion::UTMZones::latZone(double latitude) char UTMZones::latZone(double latitude)
{ {
short latIndex = -2; short latIndex = -2;
short lat = short(latitude); short lat = short(latitude);
...@@ -121,7 +121,7 @@ char CoordinateConversion::UTMZones::latZone(double latitude) ...@@ -121,7 +121,7 @@ char CoordinateConversion::UTMZones::latZone(double latitude)
} }
} }
double CoordinateConversion::LatLon2UTM::northing(double latitude) const double LatLon2UTM::northing(double latitude) const
{ {
double northing = m_K1 + m_K2 * m_p * m_p + m_K3 * std::pow(m_p, 4.); double northing = m_K1 + m_K2 * m_p * m_p + m_K3 * std::pow(m_p, 4.);
if (latitude < 0.0) if (latitude < 0.0)
...@@ -131,12 +131,12 @@ double CoordinateConversion::LatLon2UTM::northing(double latitude) const ...@@ -131,12 +131,12 @@ double CoordinateConversion::LatLon2UTM::northing(double latitude) const
return northing; return northing;
} }
double CoordinateConversion::LatLon2UTM::easting() const double LatLon2UTM::easting() const
{ {
return 500000. + (m_K4 * m_p + m_K5 * std::pow(m_p, 3.)); return 500000. + (m_K4 * m_p + m_K5 * std::pow(m_p, 3.));
} }
CoordinateConversion::UTMCoordinate CoordinateConversion::LatLon2UTM::toUTM( UTMCoordinate LatLon2UTM::toUTM(
double latitude, double longitude) double latitude, double longitude)
{ {
CoordinateConversion::validate(latitude, longitude); CoordinateConversion::validate(latitude, longitude);
...@@ -150,7 +150,7 @@ CoordinateConversion::UTMCoordinate CoordinateConversion::LatLon2UTM::toUTM( ...@@ -150,7 +150,7 @@ CoordinateConversion::UTMCoordinate CoordinateConversion::LatLon2UTM::toUTM(
return utm; return utm;
} }
void CoordinateConversion::LatLon2UTM::init(double latitude, double longitude) void LatLon2UTM::init(double latitude, double longitude)
{ {
latitude = radix::toRadians(latitude); latitude = radix::toRadians(latitude);
m_rho = m_equatorialRadius * (double(1.) - m_e * m_e) / m_rho = m_equatorialRadius * (double(1.) - m_e * m_e) /
...@@ -226,8 +226,8 @@ void CoordinateConversion::validate(double latitude, double longitude) ...@@ -226,8 +226,8 @@ void CoordinateConversion::validate(double latitude, double longitude)
} }
} }
void CoordinateConversion::UTM2LatLon::init( void UTM2LatLon::init(
const CoordinateConversion::UTMCoordinate& utm) const UTMCoordinate& utm)
{ {
m_arc = utm.northing / m_k0; m_arc = utm.northing / m_k0;
m_mu = m_arc / m_mu = m_arc /
...@@ -275,7 +275,7 @@ void CoordinateConversion::UTM2LatLon::init( ...@@ -275,7 +275,7 @@ void CoordinateConversion::UTM2LatLon::init(
m_a3 = m_a2 * 180. / radix::PI; m_a3 = m_a2 * 180. / radix::PI;
} }
char CoordinateConversion::UTM2LatLon::hemisphere(char latitude_zone) char UTM2LatLon::hemisphere(char latitude_zone)
{ {
auto it = std::find(std::begin(southern_hemisphere), auto it = std::find(std::begin(southern_hemisphere),
std::end(southern_hemisphere), latitude_zone); std::end(southern_hemisphere), latitude_zone);
...@@ -289,8 +289,8 @@ char CoordinateConversion::UTM2LatLon::hemisphere(char latitude_zone) ...@@ -289,8 +289,8 @@ char CoordinateConversion::UTM2LatLon::hemisphere(char latitude_zone)
} }
} }
std::pair<double, double> CoordinateConversion::UTM2LatLon::toLatLon( std::pair<double, double> UTM2LatLon::toLatLon(
const CoordinateConversion::UTMCoordinate& c) const UTMCoordinate& c)
{ {
UTMCoordinate utm = c; UTMCoordinate utm = c;
double latitude = 0.; double latitude = 0.;
......
...@@ -15,228 +15,227 @@ namespace radix ...@@ -15,228 +15,227 @@ namespace radix
class RADIX_PUBLIC CoordinateConversion class RADIX_PUBLIC CoordinateConversion
{ {
public: public:
struct RADIX_PUBLIC UTMCoordinate /**
{ * @brief validate Validates coordinate
// earth radius is ~40million meteres * @param latitude latitude coordinate
// int will cover this * @param longitude longitude coordinate
double easting; * Throws std::out_of_range exception if latitude is outside [-90.,90.] or
double northing; * longitude must be [-180,180).
// 00 -> 60 longitude zones */
short longitude_zone; static void validate(double latitude, double longitude);
// Not officially part of UTM /**
// but frequently used with UTM * @brief validate Validates coordinate
// C - > X, (A,B,Y,Z) are not used as they cover western and eastern sides * @param point where point.first is latitutde and point.second is longitude
// of the Antarctic and Arctic regions * Throws std::out_of_range exception if latitude is outside [-90.,90.] or
char lattitude_zone; * longitude must be [-180,180).
}; */
class RADIX_PUBLIC UTMZones
{
static const std::array<char, 22> letters;
static const std::array<short, 22> degrees;
static const std::array<char, 11> neg_letters; static void validate(const std::pair<double, double>& point);
static const std::array<short, 11> neg_degrees; }; // class CoordinateConversion
struct RADIX_PUBLIC UTMCoordinate
{
// earth radius is ~40million meteres
// int will cover this
double easting;
double northing;
// 00 -> 60 longitude zones
short longitude_zone;
// Not officially part of UTM
// but frequently used with UTM
// C - > X, (A,B,Y,Z) are not used as they cover western and eastern sides
// of the Antarctic and Arctic regions
char lattitude_zone;
};
class RADIX_PUBLIC UTMZones
{
static const std::array<char, 22> letters;
static const std::array<char, 11> pos_letters; static const std::array<short, 22> degrees;
static const std::array<short, 11> pos_degrees; static const std::array<char, 11> neg_letters;
public: static const std::array<short, 11> neg_degrees;
/**
* @brief latZoneDegree Latitude
* @param letter 'A' thru 'Z' zone
* @return short -90 thru 90 latitude zone offset
*/
static short latZoneDegree(char letter);
/**
* @brief lonZone Longitude zone
* @param longitude degrees
* @return short 0 thru 60 zone
*/
static short lonZone(double longitude);
/** static const std::array<char, 11> pos_letters;
* @brief latZone Latitude zone
* @param latitude degrees
* @return 'A' thru 'Z' zone
*/
static char latZone(double latitude);
}; // UTMZone
class RADIX_PUBLIC LatLon2UTM static const std::array<short, 11> pos_degrees;
{
private:
// equatorial radius
double m_equatorialRadius = double(6378137);
// polar radius public:
double m_polarRadius = double(6356752.314); /**
* @brief latZoneDegree Latitude
* @param letter 'A' thru 'Z' zone
* @return short -90 thru 90 latitude zone offset
*/
static short latZoneDegree(char letter);
/**
* @brief lonZone Longitude zone
* @param longitude degrees
* @return short 0 thru 60 zone
*/
static short lonZone(double longitude);
// flattening /**
double m_flattening = double( * @brief latZone Latitude zone
0.00335281066474748); // (equatorialRadius-polarRadius)/equatorialRadius; * @param latitude degrees
* @return 'A' thru 'Z' zone
*/
static char latZone(double latitude);
}; // UTMZone
// inverse flattening 1/flattening class RADIX_PUBLIC LatLon2UTM
double m_inverseFlattening = double(298.257223563); // 1/flattening; {
private:
// equatorial radius
double m_equatorialRadius = double(6378137);
// Mean radius // polar radius
double m_rm = double m_polarRadius = double(6356752.314);
std::pow(m_equatorialRadius * m_polarRadius, double(1.) / double(2.0));
// scale factor // flattening
double m_k0 = double(0.9996); double m_flattening = double(
0.00335281066474748); // (equatorialRadius-polarRadius)/equatorialRadius;
// eccentricity // inverse flattening 1/flattening
double m_e = std::sqrt( double m_inverseFlattening = double(298.257223563); // 1/flattening;
double(1) - std::pow(m_polarRadius / m_equatorialRadius, double(2.)));
double m_e1sq = m_e * m_e / (double(1) - m_e * m_e); // Mean radius
double m_rm =
std::pow(m_equatorialRadius * m_polarRadius, double(1.) / double(2.0));
double m_n = (m_equatorialRadius - m_polarRadius) / // scale factor
(m_equatorialRadius + m_polarRadius); double m_k0 = double(0.9996);
// r curv 1 // eccentricity
double m_rho = double(6368573.744); double m_e = std::sqrt(
double(1) - std::pow(m_polarRadius / m_equatorialRadius, double(2.)));
// r curv 2 double m_e1sq = m_e * m_e / (double(1) - m_e * m_e);
double m_nu = double(6389236.914);
// Calculate Meridional Arc Length double m_n = (m_equatorialRadius - m_polarRadius) /
// Meridional Arc (m_equatorialRadius + m_polarRadius);
double m_S = double(5103266.421);
double m_A0 = double(6367449.146); // r curv 1
double m_rho = double(6368573.744);
double m_B0 = double(16038.42955); // r curv 2
double m_nu = double(6389236.914);
double m_C0 = double(16.83261333); // Calculate Meridional Arc Length
// Meridional Arc
double m_S = double(5103266.421);
double m_D0 = double(0.021984404); double m_A0 = double(6367449.146);
double m_E0 = double(0.000312705); double m_B0 = double(16038.42955);
// Calculation Constants double m_C0 = double(16.83261333);
// Delta Long
double m_p = double(-0.483084);
double m_sin1 = double(4.84814E-06); double m_D0 = double(0.021984404);
// Coefficients for UTM Coordinates double m_E0 = double(0.000312705);
double m_K1 = double(5101225.115);
double m_K2 = double(3750.291596); // Calculation Constants
// Delta Long
double m_p = double(-0.483084);
double m_K3 = double(1.397608151); double m_sin1 = double(4.84814E-06);
double m_K4 = double(214839.3105); // Coefficients for UTM Coordinates
double m_K1 = double(5101225.115);
double m_K5 = double(-2.995382942); double m_K2 = double(3750.291596);
double m_A6 = double(-1.00541E-07); double m_K3 = double(1.397608151);
/** double m_K4 = double(214839.3105);
* @brief init initializes internal data necessary for coordinate conversion
* @param latitude degrees
* @param longitude degrees
*/
void init(double latitude, double longitude);
public: double m_K5 = double(-2.995382942);
double northing(double latitude) const;
double easting() const;
UTMCoordinate toUTM(double latitude, double longitude);
}; // class LatLon2UTM
class RADIX_PUBLIC UTM2LatLon double m_A6 = double(-1.00541E-07);
{
private:
double m_arc;
double m_mu; /**
* @brief init initializes internal data necessary for coordinate conversion
* @param latitude degrees
* @param longitude degrees
*/
void init(double latitude, double longitude);
double m_ei; public:
double northing(double latitude) const;
double easting() const;
UTMCoordinate toUTM(double latitude, double longitude);
}; // class LatLon2UTM
double m_ca; class RADIX_PUBLIC UTM2LatLon
{
private:
double m_arc;
double m_cb; double m_mu;
double m_cc; double m_ei;
double m_cd; double m_ca;
double m_n0; double m_cb;
double m_r0; double m_cc;
double m_a1; double m_cd;
double m_dd0; double m_n0;
double m_t0; double m_r0;
double m_Q0; double m_a1;
double m_lof1; double m_dd0;
double m_lof2; double m_t0;
double m_lof3; double m_Q0;
double m_a2; double m_lof1;
double m_phi1; double m_lof2;
double m_fact1; double m_lof3;
double m_fact2; double m_a2;
double m_fact3; double m_phi1;
double m_fact4; double m_fact1;
double m_zoneCM; double m_fact2;
double m_a3; double m_fact3;
double m_b = 6356752.314; double m_fact4;
double m_a = 6378137; double m_zoneCM;
double m_e = 0.081819191; double m_a3;
double m_e1sq = 0.006739497; double m_b = 6356752.314;
double m_k0 = 0.9996; double m_a = 6378137;
void init(const UTMCoordinate& utm); double m_e = 0.081819191;
public: double m_e1sq = 0.006739497;
static const std::array<char, 11> southern_hemisphere;
static char hemisphere(char latitude_zone);
std::pair<double, double> toLatLon(const UTMCoordinate& c);
}; // class UTM2LatLon
/** double m_k0 = 0.9996;
* @brief validate Validates coordinate
* @param latitude latitude coordinate
* @param longitude longitude coordinate
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
static void validate(double latitude, double longitude);
/**
* @brief validate Validates coordinate
* @param point where point.first is latitutde and point.second is longitude
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
static void validate(const std::pair<double, double>& point); void init(const UTMCoordinate& utm);
}; // class CoordinateConversion public:
static const std::array<char, 11> southern_hemisphere;
static char hemisphere(char latitude_zone);
std::pair<double, double> toLatLon(const UTMCoordinate& c);
}; // class UTM2LatLon
} // namespace radix } // namespace radix
#endif /** RADIX_RADIXGEO_COORDINATECONVERSION_HH_ */ #endif /** RADIX_RADIXGEO_COORDINATECONVERSION_HH_ */
...@@ -124,35 +124,35 @@ TEST(Radixgeo, CoordinateRange) ...@@ -124,35 +124,35 @@ TEST(Radixgeo, CoordinateRange)
TEST(Radixgeo, UTMZones) TEST(Radixgeo, UTMZones)
{ {
// latitude // latitude
EXPECT_EQ('N', CoordinateConversion::UTMZones::latZone(0.)); EXPECT_EQ('N', UTMZones::latZone(0.));
EXPECT_EQ('N', CoordinateConversion::UTMZones::latZone(0.13)); EXPECT_EQ('N', UTMZones::latZone(0.13));
EXPECT_EQ('G', CoordinateConversion::UTMZones::latZone(-45.6456)); EXPECT_EQ('G', UTMZones::latZone(-45.6456));