Apply clang-format

This commit is contained in:
Martchus 2017-05-01 03:40:44 +02:00
parent 6576f88608
commit 868f0fd2bd
7 changed files with 247 additions and 241 deletions

3
.gitignore vendored
View File

@ -39,3 +39,6 @@ Makefile*
# documentation # documentation
/doc /doc
# clang-format
/.clang-format

View File

@ -3,10 +3,10 @@
#include <c++utilities/application/failure.h> #include <c++utilities/application/failure.h>
#include <c++utilities/conversion/stringconversion.h> #include <c++utilities/conversion/stringconversion.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath> #include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#ifndef M_PI #ifndef M_PI
#define M_PI 3.14159265359 #define M_PI 3.14159265359
@ -16,16 +16,15 @@ using namespace std;
using namespace ApplicationUtilities; using namespace ApplicationUtilities;
using namespace ConversionUtilities; using namespace ConversionUtilities;
Angle::Angle() : Angle::Angle()
m_val(0) : m_val(0)
{ {
} }
Angle::Angle(double value, AngularMeasure measure) : Angle::Angle(double value, AngularMeasure measure)
m_val(0) : m_val(0)
{
switch(measure)
{ {
switch (measure) {
case AngularMeasure::Radian: case AngularMeasure::Radian:
m_val = value; m_val = value;
break; break;
@ -34,15 +33,14 @@ Angle::Angle(double value, AngularMeasure measure) :
} }
} }
Angle::Angle(const string &value, AngularMeasure measure) : Angle::Angle(const string &value, AngularMeasure measure)
m_val(0) : m_val(0)
{ {
switch (measure) { switch (measure) {
case AngularMeasure::Radian: case AngularMeasure::Radian:
m_val += stringToNumber<double>(value); m_val += stringToNumber<double>(value);
break; break;
case AngularMeasure::Degree: case AngularMeasure::Degree: {
{
string::size_type mpos, spos = string::npos; string::size_type mpos, spos = string::npos;
mpos = value.find(':'); mpos = value.find(':');
if (mpos == string::npos) if (mpos == string::npos)
@ -83,14 +81,18 @@ bool Angle::isNull() const
void Angle::adjust0To360() void Angle::adjust0To360()
{ {
while(m_val < 0) m_val += 2.0 * M_PI; while (m_val < 0)
while(m_val > 2.0 * M_PI) m_val -= 2.0 * M_PI; m_val += 2.0 * M_PI;
while (m_val > 2.0 * M_PI)
m_val -= 2.0 * M_PI;
} }
void Angle::adjust180To180() void Angle::adjust180To180()
{ {
while(m_val > M_PI) m_val -= 2.0 * M_PI; while (m_val > M_PI)
while(m_val < -M_PI) m_val += 2.0 * M_PI; m_val -= 2.0 * M_PI;
while (m_val < -M_PI)
m_val += 2.0 * M_PI;
} }
void Angle::reverse() void Angle::reverse()

18
angle.h
View File

@ -3,22 +3,11 @@
#include <string> #include <string>
class Angle class Angle {
{
public: public:
enum class AngularMeasure enum class AngularMeasure { Radian, Degree };
{
Radian,
Degree
};
enum class OutputForm enum class OutputForm { Degrees, Minutes, Seconds, Radians };
{
Degrees,
Minutes,
Seconds,
Radians
};
Angle(); Angle();
Angle(double value, AngularMeasure measure = AngularMeasure::Radian); Angle(double value, AngularMeasure measure = AngularMeasure::Radian);
@ -38,6 +27,7 @@ public:
Angle operator-(const Angle &other) const; Angle operator-(const Angle &other) const;
Angle &operator+=(const Angle &other); Angle &operator+=(const Angle &other);
Angle &operator-=(const Angle &other); Angle &operator-=(const Angle &other);
private: private:
double m_val; double m_val;
}; };

View File

@ -3,9 +3,9 @@
#include <c++utilities/application/failure.h> #include <c++utilities/application/failure.h>
#include <c++utilities/conversion/stringconversion.h> #include <c++utilities/conversion/stringconversion.h>
#include <sstream>
#include <iomanip>
#include <cmath> #include <cmath>
#include <iomanip>
#include <sstream>
using namespace std; using namespace std;
using namespace ApplicationUtilities; using namespace ApplicationUtilities;
@ -28,26 +28,29 @@ using namespace ConversionUtilities;
#define UTM_E6 (UTM_E4 * UTM_E2) // e^6 #define UTM_E6 (UTM_E4 * UTM_E2) // e^6
#define UTM_EP2 (UTM_E2 / (1 - UTM_E2)) // e'^2 #define UTM_EP2 (UTM_E2 / (1 - UTM_E2)) // e'^2
Location::Location() : Location::Location()
m_lat(0.0), : m_lat(0.0)
m_lon(0.0), , m_lon(0.0)
m_ele(0.0) , m_ele(0.0)
{} {
}
Location::Location(const Angle &latitude, const Angle &lon) : Location::Location(const Angle &latitude, const Angle &lon)
m_lat(latitude), : m_lat(latitude)
m_lon(lon), , m_lon(lon)
m_ele(0.0) , m_ele(0.0)
{} {
}
Location::Location(const string &lat, const string &lon, Angle::AngularMeasure measure) : Location::Location(const string &lat, const string &lon, Angle::AngularMeasure measure)
m_lat(Angle(lat, measure)), : m_lat(Angle(lat, measure))
m_lon(Angle(lon, measure)), , m_lon(Angle(lon, measure))
m_ele(0.0) , m_ele(0.0)
{} {
}
Location::Location(const string &latitudeAndLongitude, Angle::AngularMeasure measure) : Location::Location(const string &latitudeAndLongitude, Angle::AngularMeasure measure)
m_ele(0.0) : m_ele(0.0)
{ {
string::size_type dpos = latitudeAndLongitude.find(','); string::size_type dpos = latitudeAndLongitude.find(',');
if (dpos == string::npos) if (dpos == string::npos)
@ -61,7 +64,8 @@ Location::Location(const string &latitudeAndLongitude, Angle::AngularMeasure mea
} }
Location::~Location() Location::~Location()
{} {
}
string Location::toString(Angle::OutputForm form) const string Location::toString(Angle::OutputForm form) const
{ {
@ -142,12 +146,15 @@ void Location::computeUtmWgs4Coordinates(int &zone, char &zoneDesignator, double
zone = 32; zone = 32;
// Special zones for Svalbard // Special zones for Svalbard
if(latd >= 72.0 && latd < 84.0) if (latd >= 72.0 && latd < 84.0) {
{ if (lond >= 0.0 && lond < 9.0)
if(lond >= 0.0 && lond < 9.0) zone = 31; zone = 31;
else if(lond >= 9.0 && lond < 21.0) zone = 33; else if (lond >= 9.0 && lond < 21.0)
else if(lond >= 21.0 && lond < 33.0) zone = 35; zone = 33;
else if(lond >= 33.0 && lond < 42.0) zone = 37; else if (lond >= 21.0 && lond < 33.0)
zone = 35;
else if (lond >= 33.0 && lond < 42.0)
zone = 37;
} }
zoneDesignator = computeUtmZoneDesignator(); zoneDesignator = computeUtmZoneDesignator();
@ -160,22 +167,17 @@ void Location::computeUtmWgs4Coordinates(int &zone, char &zoneDesignator, double
double T = tan(latr) * tan(latr); double T = tan(latr) * tan(latr);
double C = eccPrimeSquared * cos(latr) * cos(latr); double C = eccPrimeSquared * cos(latr) * cos(latr);
double A = cos(latr) * (lonr - lonOriginr); double A = cos(latr) * (lonr - lonOriginr);
double M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 double M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * latr
- 5 * eccSquared * eccSquared * eccSquared / 256) * latr - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * sin(2 * latr)
- (3 * eccSquared / 8 + 3 * eccSquared*eccSquared / 32 + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * sin(4 * latr)
+ 45 * eccSquared * eccSquared * eccSquared / 1024)*sin(2 * latr)
+ (15 * eccSquared * eccSquared / 256
+ 45 * eccSquared * eccSquared*eccSquared / 1024) * sin(4 * latr)
- (35 * eccSquared * eccSquared * eccSquared / 3072) * sin(6 * latr)); - (35 * eccSquared * eccSquared * eccSquared / 3072) * sin(6 * latr));
east = static_cast<double> east = static_cast<double>(
(k0 * N * (A + (1 - T + C) * A * A * A / 6 k0 * N * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120) + 500000.0);
+ (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120)
+ 500000.0);
north = static_cast<double> north = static_cast<double>(
(k0 * (M + N * tan(latr) k0 * (M
* (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A *A / 24 + N * tan(latr) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24
+ (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720))); + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720)));
if (latd < 0) if (latd < 0)
@ -191,9 +193,7 @@ Location Location::midpoint(const Location &location1, const Location &location2
double lond = lon2 - lon1; double lond = lon2 - lon1;
double x = cos(lat2) * cos(lond); double x = cos(lat2) * cos(lond);
double y = cos(lat2) * sin(lond); double y = cos(lat2) * sin(lond);
return Location( return Location(Angle(atan2(sin(lat1) + sin(lat2), sqrt((cos(lat1) + x) * (cos(lat1) + x) + y * y))), Angle(lon1 + atan2(y, cos(lat1) + x)));
Angle(atan2(sin(lat1) + sin(lat2), sqrt((cos(lat1) + x) * (cos(lat1) + x) + y * y))),
Angle(lon1 + atan2(y, cos(lat1) + x)));
} }
double Location::trackLength(const std::vector<Location> &track, bool circle) double Location::trackLength(const std::vector<Location> &track, bool circle)
@ -230,27 +230,48 @@ Angle Location::angularDistance(double distance)
char Location::computeUtmZoneDesignator() const char Location::computeUtmZoneDesignator() const
{ {
double l = m_lat.degreeValue(); double l = m_lat.degreeValue();
if ((84 >= l) && (l >= 72)) return 'X'; if ((84 >= l) && (l >= 72))
else if ((72 > l) && (l >= 64)) return 'W'; return 'X';
else if ((64 > l) && (l >= 56)) return 'V'; else if ((72 > l) && (l >= 64))
else if ((56 > l) && (l >= 48)) return 'U'; return 'W';
else if ((48 > l) && (l >= 40)) return 'T'; else if ((64 > l) && (l >= 56))
else if ((40 > l) && (l >= 32)) return 'S'; return 'V';
else if ((32 > l) && (l >= 24)) return 'R'; else if ((56 > l) && (l >= 48))
else if ((24 > l) && (l >= 16)) return 'Q'; return 'U';
else if ((16 > l) && (l >= 8)) return 'P'; else if ((48 > l) && (l >= 40))
else if (( 8 > l) && (l >= 0)) return 'N'; return 'T';
else if (( 0 > l) && (l >= -8)) return 'M'; else if ((40 > l) && (l >= 32))
else if ((-8 > l) && (l >= -16)) return 'L'; return 'S';
else if((-16 > l) && (l >= -24)) return 'K'; else if ((32 > l) && (l >= 24))
else if((-24 > l) && (l >= -32)) return 'J'; return 'R';
else if((-32 > l) && (l >= -40)) return 'H'; else if ((24 > l) && (l >= 16))
else if((-40 > l) && (l >= -48)) return 'G'; return 'Q';
else if((-48 > l) && (l >= -56)) return 'F'; else if ((16 > l) && (l >= 8))
else if((-56 > l) && (l >= -64)) return 'E'; return 'P';
else if((-64 > l) && (l >= -72)) return 'D'; else if ((8 > l) && (l >= 0))
else if((-72 > l) && (l >= -80)) return 'C'; return 'N';
else return '\0'; else if ((0 > l) && (l >= -8))
return 'M';
else if ((-8 > l) && (l >= -16))
return 'L';
else if ((-16 > l) && (l >= -24))
return 'K';
else if ((-24 > l) && (l >= -32))
return 'J';
else if ((-32 > l) && (l >= -40))
return 'H';
else if ((-40 > l) && (l >= -48))
return 'G';
else if ((-48 > l) && (l >= -56))
return 'F';
else if ((-56 > l) && (l >= -64))
return 'E';
else if ((-64 > l) && (l >= -72))
return 'D';
else if ((-72 > l) && (l >= -80))
return 'C';
else
return '\0';
} }
void Location::setValueByProvidedUtmWgs4Coordinates(const string &utmWgs4Coordinates) void Location::setValueByProvidedUtmWgs4Coordinates(const string &utmWgs4Coordinates)
@ -290,11 +311,9 @@ void Location::setValueByProvidedUtmWgs4Coordinates(int zone, char zoneDesignato
eccPrimeSquared = (eccSquared) / (1 - eccSquared); eccPrimeSquared = (eccSquared) / (1 - eccSquared);
double M = y / k0; double M = y / k0;
double mu = M / (a * (1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 double mu = M / (a * (1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256));
-5 * eccSquared * eccSquared * eccSquared / 256));
double phi1Rad = mu + ((3 * e1 / 2 - 27 * e1 * e1 * e1 / 32) * sin(2 * mu) double phi1Rad = mu + ((3 * e1 / 2 - 27 * e1 * e1 * e1 / 32) * sin(2 * mu) + (21 * e1 * e1 / 16 - 55 * e1 * e1 * e1 * e1 / 32) * sin(4 * mu)
+ (21 * e1 * e1 / 16 - 55 * e1 * e1 * e1 * e1 / 32) * sin(4 * mu)
+ (151 * e1 * e1 * e1 / 96) * sin(6 * mu)); + (151 * e1 * e1 * e1 / 96) * sin(6 * mu));
double N1 = a / sqrt(1 - eccSquared * sin(phi1Rad) * sin(phi1Rad)); double N1 = a / sqrt(1 - eccSquared * sin(phi1Rad) * sin(phi1Rad));
@ -303,16 +322,14 @@ void Location::setValueByProvidedUtmWgs4Coordinates(int zone, char zoneDesignato
double R1 = a * (1 - eccSquared) / pow(1 - eccSquared * sin(phi1Rad) * sin(phi1Rad), 1.5); double R1 = a * (1 - eccSquared) / pow(1 - eccSquared * sin(phi1Rad) * sin(phi1Rad), 1.5);
double D = x / (N1 * k0); double D = x / (N1 * k0);
m_lat = Angle(phi1Rad - ((N1 * tan(phi1Rad) / R1) m_lat = Angle(phi1Rad - ((N1 * tan(phi1Rad) / R1) * (D * D / 2 - (5 + 3 * T1 + 10 * C1 - 4 * C1 * C1 - 9 * eccPrimeSquared) * D * D * D * D / 24
* (D * D / 2 + (61 + 90 * T1 + 298 * C1 + 45 * T1 * T1 - 252 * eccPrimeSquared - 3 * C1 * C1) * D * D
-(5 + 3 * T1 + 10 * C1 - 4 * C1 * C1 - 9 * eccPrimeSquared) * D * D * D * D / 24 * D * D * D * D / 720)));
+(61 + 90 * T1 + 298 * C1 + 45 * T1 * T1 - 252 * eccPrimeSquared
-3 * C1 * C1) * D * D * D * D * D * D / 720)));
m_lat.adjust180To180(); m_lat.adjust180To180();
m_lon = Angle(((D - (1 + 2 * T1 + C1) * D * D * D / 6 m_lon = Angle(
+(5 - 2 * C1 + 28 * T1 - 3 * C1 * C1 + 8 * eccPrimeSquared + 24 * T1 * T1) ((D - (1 + 2 * T1 + C1) * D * D * D / 6 + (5 - 2 * C1 + 28 * T1 - 3 * C1 * C1 + 8 * eccPrimeSquared + 24 * T1 * T1) * D * D * D * D * D / 120)
* D * D * D * D * D / 120) / cos(phi1Rad))
/ cos(phi1Rad)) + longOriginr); + longOriginr);
m_lon.adjust180To180(); m_lon.adjust180To180();
} }

View File

@ -3,17 +3,12 @@
#include "./angle.h" #include "./angle.h"
#include <vector>
#include <string> #include <string>
#include <vector>
class Location class Location {
{
public: public:
enum class GeographicCoordinateSystem enum class GeographicCoordinateSystem { LatitudeAndLongitude, UTMWGS84 };
{
LatitudeAndLongitude,
UTMWGS84
};
Location(); Location();
Location(const Angle &lat, const Angle &lon); Location(const Angle &lat, const Angle &lon);
@ -42,6 +37,7 @@ public:
static double trackLength(const std::vector<Location> &track, bool circle = false); static double trackLength(const std::vector<Location> &track, bool circle = false);
static double earthRadius(); static double earthRadius();
static Angle angularDistance(double distance); static Angle angularDistance(double distance);
protected: protected:
private: private:
Angle m_lat; Angle m_lat;

View File

@ -8,9 +8,9 @@
#include <c++utilities/conversion/stringconversion.h> #include <c++utilities/conversion/stringconversion.h>
#include <c++utilities/io/catchiofailure.h> #include <c++utilities/io/catchiofailure.h>
#include <iostream>
#include <fstream>
#include <cstring> #include <cstring>
#include <fstream>
#include <iostream>
using namespace std; using namespace std;
using namespace ConversionUtilities; using namespace ConversionUtilities;
@ -37,20 +37,24 @@ int main(int argc, char *argv[])
distance.appendValueName("location 1"); distance.appendValueName("location 1");
distance.appendValueName("location 2"); distance.appendValueName("location 2");
Argument trackLength("track-length", 't', "Computes the approximate length in meters of a track given by a file containing trackpoints separated by new lines."); Argument trackLength("track-length", 't',
"Computes the approximate length in meters of a track given by a file containing trackpoints separated by new lines.");
Argument fileArg("file", 'f', "Specifies the file containing the track points"); Argument fileArg("file", 'f', "Specifies the file containing the track points");
fileArg.setRequiredValueCount(1); fileArg.setRequiredValueCount(1);
fileArg.appendValueName("path"); fileArg.appendValueName("path");
fileArg.setRequired(true); fileArg.setRequired(true);
Argument circle("circle", '\0', "If present the distance between the first and the last trackpoints will be added to the total track length."); Argument circle(
"circle", '\0', "If present the distance between the first and the last trackpoints will be added to the total track length.");
trackLength.setSubArguments({ &fileArg, &circle }); trackLength.setSubArguments({ &fileArg, &circle });
Argument bearing("bearing", 'b', "Computes the approximate initial bearing East of true North when traveling along the shortest path between the given locations."); Argument bearing("bearing", 'b',
"Computes the approximate initial bearing East of true North when traveling along the shortest path between the given locations.");
bearing.setRequiredValueCount(2); bearing.setRequiredValueCount(2);
bearing.appendValueName("location 1"); bearing.appendValueName("location 1");
bearing.appendValueName("location 2"); bearing.appendValueName("location 2");
Argument fbearing("final-bearing", '\0', "Computes the approximate final bearing East of true North when traveling along the shortest path between the given locations."); Argument fbearing("final-bearing", '\0',
"Computes the approximate final bearing East of true North when traveling along the shortest path between the given locations.");
fbearing.setRequiredValueCount(2); fbearing.setRequiredValueCount(2);
fbearing.appendValueName("location 1"); fbearing.appendValueName("location 1");
fbearing.appendValueName("location 2"); fbearing.appendValueName("location 2");
@ -66,26 +70,31 @@ int main(int argc, char *argv[])
destination.appendValueName("distance"); destination.appendValueName("distance");
destination.appendValueName("bearing"); destination.appendValueName("bearing");
Argument gmapsLink("gmaps-link", '\0', "Generates a Google Maps link for all locations given by a file containing locations separated by new lines."); Argument gmapsLink(
"gmaps-link", '\0', "Generates a Google Maps link for all locations given by a file containing locations separated by new lines.");
gmapsLink.setRequiredValueCount(1); gmapsLink.setRequiredValueCount(1);
gmapsLink.appendValueName("path"); gmapsLink.appendValueName("path");
Argument inputAngularMeasureArg("input-angular-measure", 'i', "Use this option to specify the angular measure you use to provide angles (degree or radian; default is degree)."); Argument inputAngularMeasureArg("input-angular-measure", 'i',
"Use this option to specify the angular measure you use to provide angles (degree or radian; default is degree).");
inputAngularMeasureArg.setRequiredValueCount(1); inputAngularMeasureArg.setRequiredValueCount(1);
inputAngularMeasureArg.appendValueName("angular measure"); inputAngularMeasureArg.appendValueName("angular measure");
inputAngularMeasureArg.setCombinable(true); inputAngularMeasureArg.setCombinable(true);
Argument outputFormForAnglesArg("output-angle-form", 'o', "Use this option to specify the output form for angles (degrees, minutes, seconds or radians; default is degrees)."); Argument outputFormForAnglesArg("output-angle-form", 'o',
"Use this option to specify the output form for angles (degrees, minutes, seconds or radians; default is degrees).");
outputFormForAnglesArg.setRequiredValueCount(1); outputFormForAnglesArg.setRequiredValueCount(1);
outputFormForAnglesArg.appendValueName("form"); outputFormForAnglesArg.appendValueName("form");
outputFormForAnglesArg.setCombinable(true); outputFormForAnglesArg.setCombinable(true);
Argument inputSystemForLocationsArg("input-location-system", '\0', "Use this option to specify the geographic system you use to provide locations (latitude&longitue or UTM-WGS84)."); Argument inputSystemForLocationsArg("input-location-system", '\0',
"Use this option to specify the geographic system you use to provide locations (latitude&longitue or UTM-WGS84).");
inputSystemForLocationsArg.setRequiredValueCount(1); inputSystemForLocationsArg.setRequiredValueCount(1);
inputSystemForLocationsArg.appendValueName("system"); inputSystemForLocationsArg.appendValueName("system");
inputSystemForLocationsArg.setCombinable(true); inputSystemForLocationsArg.setCombinable(true);
Argument outputSystemForLocationsArg("output-location-system", '\0', "Use this option to specify which geographic system is used to display locations (latitude&longitue or UTM-WGS84)."); Argument outputSystemForLocationsArg("output-location-system", '\0',
"Use this option to specify which geographic system is used to display locations (latitude&longitue or UTM-WGS84).");
outputSystemForLocationsArg.setRequiredValueCount(1); outputSystemForLocationsArg.setRequiredValueCount(1);
outputSystemForLocationsArg.appendValueName("system"); outputSystemForLocationsArg.appendValueName("system");
outputSystemForLocationsArg.setCombinable(true); outputSystemForLocationsArg.setCombinable(true);
@ -93,7 +102,8 @@ int main(int argc, char *argv[])
HelpArgument help(argparser); HelpArgument help(argparser);
Argument version("version", 'v', "Shows the version of this application."); Argument version("version", 'v', "Shows the version of this application.");
argparser.setMainArguments({&help, &convert, &distance, &trackLength, &bearing, &fbearing, &midpoint, &destination, &gmapsLink, &inputAngularMeasureArg, &outputFormForAnglesArg, &inputSystemForLocationsArg, &outputSystemForLocationsArg, &version}); argparser.setMainArguments({ &help, &convert, &distance, &trackLength, &bearing, &fbearing, &midpoint, &destination, &gmapsLink,
&inputAngularMeasureArg, &outputFormForAnglesArg, &inputSystemForLocationsArg, &outputSystemForLocationsArg, &version });
argparser.parseArgs(argc, argv); argparser.parseArgs(argc, argv);
if (inputAngularMeasureArg.isPresent()) { if (inputAngularMeasureArg.isPresent()) {
@ -190,7 +200,6 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
Location locationFromString(const string &userInput) Location locationFromString(const string &userInput)
{ {
switch (inputSystemForLocations) { switch (inputSystemForLocations) {
@ -198,7 +207,8 @@ Location locationFromString(const string &userInput)
Location l; Location l;
l.setValueByProvidedUtmWgs4Coordinates(userInput); l.setValueByProvidedUtmWgs4Coordinates(userInput);
return l; return l;
} default: }
default:
return Location(userInput, inputAngularMeasure); return Location(userInput, inputAngularMeasure);
} }
} }
@ -230,7 +240,8 @@ void printAngleFormatInfo(ostream &os)
os << "[+-]DDD.DDDDD\n"; os << "[+-]DDD.DDDDD\n";
os << "[+-]DDD:MM.MMMMM\n"; os << "[+-]DDD:MM.MMMMM\n";
os << "[+-]DDD:MM:SS.SSSSS\n"; os << "[+-]DDD:MM:SS.SSSSS\n";
os << "D indicates degrees, M indicates minutes of arc, and S indicates seconds of arc (1 minute = 1/60th of a degree, 1 second = 1/3600th of a degree).\n"; os << "D indicates degrees, M indicates minutes of arc, and S indicates seconds of arc (1 minute = 1/60th of a degree, 1 second = 1/3600th of a "
"degree).\n";
os << "You can use the following form where R indicates radians, if you use --input-angle-measure radian:\n"; os << "You can use the following form where R indicates radians, if you use --input-angle-measure radian:\n";
os << "[+-]RRR.RRRRR"; os << "[+-]RRR.RRRRR";
@ -246,8 +257,7 @@ void printConversion(const string &coordinates)
void printDistance(const std::string &locationstr1, const std::string &locationstr2) void printDistance(const std::string &locationstr1, const std::string &locationstr2)
{ {
printDistance(locationFromString(locationstr1) printDistance(locationFromString(locationstr1).distanceTo(locationFromString(locationstr2)));
.distanceTo(locationFromString(locationstr2)));
} }
void printDistance(double distance) void printDistance(double distance)
@ -272,23 +282,17 @@ void printTrackLength(const string &filePath, bool circle)
void printBearing(const string &locationstr1, const string &locationstr2) void printBearing(const string &locationstr1, const string &locationstr2)
{ {
cout << locationFromString(locationstr1).initialBearingTo( cout << locationFromString(locationstr1).initialBearingTo(locationFromString(locationstr2)).toString(outputFormForAngles) << endl;
locationFromString(locationstr2))
.toString(outputFormForAngles) << endl;
} }
void printFinalBearing(const string &locationstr1, const string &locationstr2) void printFinalBearing(const string &locationstr1, const string &locationstr2)
{ {
cout << locationFromString(locationstr1).finalBearingTo( cout << locationFromString(locationstr1).finalBearingTo(locationFromString(locationstr2)).toString(outputFormForAngles) << endl;
locationFromString(locationstr2))
.toString(outputFormForAngles) << endl;
} }
void printMidpoint(const string &locationstr1, const string &locationstr2) void printMidpoint(const string &locationstr1, const string &locationstr2)
{ {
printLocation(Location::midpoint( printLocation(Location::midpoint(locationFromString(locationstr1), locationFromString(locationstr2)));
locationFromString(locationstr1),
locationFromString(locationstr2)));
} }
void printDestination(const string &locationstr, const string &distancestr, const string &bearingstr) void printDestination(const string &locationstr, const string &distancestr, const string &bearingstr)
@ -311,7 +315,6 @@ void printLocation(const Location &location)
} }
} }
void printMapsLink(const string &filePath) void printMapsLink(const string &filePath)
{ {
try { try {

7
main.h
View File

@ -8,11 +8,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
enum class SystemForLocations enum class SystemForLocations { LatitudeLongitude, UTMWGS84 };
{
LatitudeLongitude,
UTMWGS84
};
extern Angle::AngularMeasure inputAngularMeasure; extern Angle::AngularMeasure inputAngularMeasure;
extern Angle::OutputForm outputFormForAngles; extern Angle::OutputForm outputFormForAngles;
@ -35,5 +31,4 @@ void printDestination(const std::string &locationstr, const std::string &distanc
void printLocation(const Location &location); void printLocation(const Location &location);
void printMapsLink(const std::string &filePath); void printMapsLink(const std::string &filePath);
#endif // MAIN_H_INCLUDED #endif // MAIN_H_INCLUDED