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
/doc
# clang-format
/.clang-format

View File

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

18
angle.h
View File

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

View File

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

View File

@ -3,17 +3,12 @@
#include "./angle.h"
#include <vector>
#include <string>
#include <vector>
class Location
{
class Location {
public:
enum class GeographicCoordinateSystem
{
LatitudeAndLongitude,
UTMWGS84
};
enum class GeographicCoordinateSystem { LatitudeAndLongitude, UTMWGS84 };
Location();
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 earthRadius();
static Angle angularDistance(double distance);
protected:
private:
Angle m_lat;

View File

@ -8,9 +8,9 @@
#include <c++utilities/conversion/stringconversion.h>
#include <c++utilities/io/catchiofailure.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <fstream>
#include <iostream>
using namespace std;
using namespace ConversionUtilities;
@ -37,20 +37,24 @@ int main(int argc, char *argv[])
distance.appendValueName("location 1");
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");
fileArg.setRequiredValueCount(1);
fileArg.appendValueName("path");
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 });
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.appendValueName("location 1");
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.appendValueName("location 1");
fbearing.appendValueName("location 2");
@ -66,26 +70,31 @@ int main(int argc, char *argv[])
destination.appendValueName("distance");
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.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.appendValueName("angular measure");
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.appendValueName("form");
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.appendValueName("system");
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.appendValueName("system");
outputSystemForLocationsArg.setCombinable(true);
@ -93,7 +102,8 @@ int main(int argc, char *argv[])
HelpArgument help(argparser);
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);
if (inputAngularMeasureArg.isPresent()) {
@ -190,7 +200,6 @@ int main(int argc, char *argv[])
return 0;
}
Location locationFromString(const string &userInput)
{
switch (inputSystemForLocations) {
@ -198,7 +207,8 @@ Location locationFromString(const string &userInput)
Location l;
l.setValueByProvidedUtmWgs4Coordinates(userInput);
return l;
} default:
}
default:
return Location(userInput, inputAngularMeasure);
}
}
@ -230,7 +240,8 @@ void printAngleFormatInfo(ostream &os)
os << "[+-]DDD.DDDDD\n";
os << "[+-]DDD:MM.MMMMM\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 << "[+-]RRR.RRRRR";
@ -246,8 +257,7 @@ void printConversion(const string &coordinates)
void printDistance(const std::string &locationstr1, const std::string &locationstr2)
{
printDistance(locationFromString(locationstr1)
.distanceTo(locationFromString(locationstr2)));
printDistance(locationFromString(locationstr1).distanceTo(locationFromString(locationstr2)));
}
void printDistance(double distance)
@ -272,23 +282,17 @@ void printTrackLength(const string &filePath, bool circle)
void printBearing(const string &locationstr1, const string &locationstr2)
{
cout << locationFromString(locationstr1).initialBearingTo(
locationFromString(locationstr2))
.toString(outputFormForAngles) << endl;
cout << locationFromString(locationstr1).initialBearingTo(locationFromString(locationstr2)).toString(outputFormForAngles) << endl;
}
void printFinalBearing(const string &locationstr1, const string &locationstr2)
{
cout << locationFromString(locationstr1).finalBearingTo(
locationFromString(locationstr2))
.toString(outputFormForAngles) << endl;
cout << locationFromString(locationstr1).finalBearingTo(locationFromString(locationstr2)).toString(outputFormForAngles) << endl;
}
void printMidpoint(const string &locationstr1, const string &locationstr2)
{
printLocation(Location::midpoint(
locationFromString(locationstr1),
locationFromString(locationstr2)));
printLocation(Location::midpoint(locationFromString(locationstr1), locationFromString(locationstr2)));
}
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)
{
try {

7
main.h
View File

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