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 @@
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',
'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,
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'}};
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}};
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'}};
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}};
const std::array<char, 11>
CoordinateConversion::UTM2LatLon::southern_hemisphere = {
UTM2LatLon::southern_hemisphere = {
{'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);
if (itr == letters.end()) return -100;
return *itr;
}
short CoordinateConversion::UTMZones::lonZone(double longitude)
short UTMZones::lonZone(double longitude)
{
double longZone = 0;
if (longitude < 0.0)
......@@ -49,7 +49,7 @@ short CoordinateConversion::UTMZones::lonZone(double longitude)
return short(longZone);
}
char CoordinateConversion::UTMZones::latZone(double latitude)
char UTMZones::latZone(double latitude)
{
short latIndex = -2;
short lat = short(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.);
if (latitude < 0.0)
......@@ -131,12 +131,12 @@ double CoordinateConversion::LatLon2UTM::northing(double latitude) const
return northing;
}
double CoordinateConversion::LatLon2UTM::easting() const
double LatLon2UTM::easting() const
{
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)
{
CoordinateConversion::validate(latitude, longitude);
......@@ -150,7 +150,7 @@ CoordinateConversion::UTMCoordinate CoordinateConversion::LatLon2UTM::toUTM(
return utm;
}
void CoordinateConversion::LatLon2UTM::init(double latitude, double longitude)
void LatLon2UTM::init(double latitude, double longitude)
{
latitude = radix::toRadians(latitude);
m_rho = m_equatorialRadius * (double(1.) - m_e * m_e) /
......@@ -226,8 +226,8 @@ void CoordinateConversion::validate(double latitude, double longitude)
}
}
void CoordinateConversion::UTM2LatLon::init(
const CoordinateConversion::UTMCoordinate& utm)
void UTM2LatLon::init(
const UTMCoordinate& utm)
{
m_arc = utm.northing / m_k0;
m_mu = m_arc /
......@@ -275,7 +275,7 @@ void CoordinateConversion::UTM2LatLon::init(
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),
std::end(southern_hemisphere), latitude_zone);
......@@ -289,8 +289,8 @@ char CoordinateConversion::UTM2LatLon::hemisphere(char latitude_zone)
}
}
std::pair<double, double> CoordinateConversion::UTM2LatLon::toLatLon(
const CoordinateConversion::UTMCoordinate& c)
std::pair<double, double> UTM2LatLon::toLatLon(
const UTMCoordinate& c)
{
UTMCoordinate utm = c;
double latitude = 0.;
......
......@@ -15,8 +15,26 @@ namespace radix
class RADIX_PUBLIC CoordinateConversion
{
public:
struct RADIX_PUBLIC UTMCoordinate
{
/**
* @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);
}; // class CoordinateConversion
struct RADIX_PUBLIC UTMCoordinate
{
// earth radius is ~40million meteres
// int will cover this
double easting;
......@@ -28,10 +46,10 @@ class RADIX_PUBLIC CoordinateConversion
// 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
{
class RADIX_PUBLIC UTMZones
{
static const std::array<char, 22> letters;
static const std::array<short, 22> degrees;
......@@ -64,10 +82,10 @@ class RADIX_PUBLIC CoordinateConversion
* @return 'A' thru 'Z' zone
*/
static char latZone(double latitude);
}; // UTMZone
}; // UTMZone
class RADIX_PUBLIC LatLon2UTM
{
class RADIX_PUBLIC LatLon2UTM
{
private:
// equatorial radius
double m_equatorialRadius = double(6378137);
......@@ -148,10 +166,10 @@ class RADIX_PUBLIC CoordinateConversion
double northing(double latitude) const;
double easting() const;
UTMCoordinate toUTM(double latitude, double longitude);
}; // class LatLon2UTM
}; // class LatLon2UTM
class RADIX_PUBLIC UTM2LatLon
{
class RADIX_PUBLIC UTM2LatLon
{
private:
double m_arc;
......@@ -217,26 +235,7 @@ class RADIX_PUBLIC CoordinateConversion
static const std::array<char, 11> southern_hemisphere;
static char hemisphere(char latitude_zone);
std::pair<double, double> toLatLon(const UTMCoordinate& c);
}; // class UTM2LatLon
/**
* @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);
}; // class CoordinateConversion
}; // class UTM2LatLon
} // namespace radix
#endif /** RADIX_RADIXGEO_COORDINATECONVERSION_HH_ */
......@@ -124,35 +124,35 @@ TEST(Radixgeo, CoordinateRange)
TEST(Radixgeo, UTMZones)
{
// latitude
EXPECT_EQ('N', CoordinateConversion::UTMZones::latZone(0.));
EXPECT_EQ('N', CoordinateConversion::UTMZones::latZone(0.13));
EXPECT_EQ('G', CoordinateConversion::UTMZones::latZone(-45.6456));
EXPECT_EQ('L', CoordinateConversion::UTMZones::latZone(-12.7650));
EXPECT_EQ('C', CoordinateConversion::UTMZones::latZone(-80.5434));
EXPECT_EQ('Z', CoordinateConversion::UTMZones::latZone(90.0000));
EXPECT_EQ('A', CoordinateConversion::UTMZones::latZone(-90.0000));
EXPECT_EQ('Q', CoordinateConversion::UTMZones::latZone(23.4578));
EXPECT_EQ('X', CoordinateConversion::UTMZones::latZone(77.3450));
EXPECT_EQ('A', CoordinateConversion::UTMZones::latZone(-89.3454));
EXPECT_EQ('N', UTMZones::latZone(0.));
EXPECT_EQ('N', UTMZones::latZone(0.13));
EXPECT_EQ('G', UTMZones::latZone(-45.6456));
EXPECT_EQ('L', UTMZones::latZone(-12.7650));
EXPECT_EQ('C', UTMZones::latZone(-80.5434));
EXPECT_EQ('Z', UTMZones::latZone(90.0000));
EXPECT_EQ('A', UTMZones::latZone(-90.0000));
EXPECT_EQ('Q', UTMZones::latZone(23.4578));
EXPECT_EQ('X', UTMZones::latZone(77.3450));
EXPECT_EQ('A', UTMZones::latZone(-89.3454));
// longitude
EXPECT_EQ(31, CoordinateConversion::UTMZones::lonZone(0.));
EXPECT_EQ(30, CoordinateConversion::UTMZones::lonZone(-0.2324));
EXPECT_EQ(34, CoordinateConversion::UTMZones::lonZone(23.3545));
EXPECT_EQ(25, CoordinateConversion::UTMZones::lonZone(-33.8765));
EXPECT_EQ(02, CoordinateConversion::UTMZones::lonZone(-170.6540));
EXPECT_EQ(60, CoordinateConversion::UTMZones::lonZone(177.0000));
EXPECT_EQ(01, CoordinateConversion::UTMZones::lonZone(-177.0000));
EXPECT_EQ(31, CoordinateConversion::UTMZones::lonZone(3.0000));
EXPECT_EQ(8, CoordinateConversion::UTMZones::lonZone(-135.4545));
EXPECT_EQ(57, CoordinateConversion::UTMZones::lonZone(156.9876));
EXPECT_EQ(22, CoordinateConversion::UTMZones::lonZone(-48.9306));
EXPECT_EQ(31, UTMZones::lonZone(0.));
EXPECT_EQ(30, UTMZones::lonZone(-0.2324));
EXPECT_EQ(34, UTMZones::lonZone(23.3545));
EXPECT_EQ(25, UTMZones::lonZone(-33.8765));
EXPECT_EQ(02, UTMZones::lonZone(-170.6540));
EXPECT_EQ(60, UTMZones::lonZone(177.0000));
EXPECT_EQ(01, UTMZones::lonZone(-177.0000));
EXPECT_EQ(31, UTMZones::lonZone(3.0000));
EXPECT_EQ(8, UTMZones::lonZone(-135.4545));
EXPECT_EQ(57, UTMZones::lonZone(156.9876));
EXPECT_EQ(22, UTMZones::lonZone(-48.9306));
}
TEST(Radixgeo, LatLon2UTM)
{
double fuzzy = 1;
CoordinateConversion::LatLon2UTM conv;
CoordinateConversion::UTMCoordinate utm = conv.toUTM(0.0000, 0.0000);
LatLon2UTM conv;
UTMCoordinate utm = conv.toUTM(0.0000, 0.0000);
EXPECT_EQ(31, utm.longitude_zone);
EXPECT_EQ('N', utm.lattitude_zone);
EXPECT_NEAR(166021.329, utm.easting, fuzzy);
......@@ -228,14 +228,14 @@ TEST(Radixgeo, LatLon2UTM)
TEST(Radixgeo, UTM2LatLon)
{
double fuzzy = 1e-2;
EXPECT_EQ('S', CoordinateConversion::UTM2LatLon::hemisphere('A'));
EXPECT_EQ('S', CoordinateConversion::UTM2LatLon::hemisphere('M'));
EXPECT_EQ('N', CoordinateConversion::UTM2LatLon::hemisphere('N'));
EXPECT_EQ('N', CoordinateConversion::UTM2LatLon::hemisphere('Z'));
CoordinateConversion::LatLon2UTM latLonConv;
CoordinateConversion::UTM2LatLon utmConv;
CoordinateConversion::UTMCoordinate utm = latLonConv.toUTM(0.0000, 0.0000);
EXPECT_EQ('S', UTM2LatLon::hemisphere('A'));
EXPECT_EQ('S', UTM2LatLon::hemisphere('M'));
EXPECT_EQ('N', UTM2LatLon::hemisphere('N'));
EXPECT_EQ('N', UTM2LatLon::hemisphere('Z'));
LatLon2UTM latLonConv;
UTM2LatLon utmConv;
UTMCoordinate utm = latLonConv.toUTM(0.0000, 0.0000);
std::pair<double, double> latLong = utmConv.toLatLon(utm);
EXPECT_NEAR(0., latLong.first, fuzzy);
EXPECT_NEAR(0., latLong.second, fuzzy);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment