From 74ac17ff427f08e079238b4a02d1ac93ed3e04e2 Mon Sep 17 00:00:00 2001 From: Daniel Warner Date: Tue, 13 Dec 2011 21:23:43 +0000 Subject: [PATCH] Updated CoordGeodetic --- CoordGeodetic.cpp | 56 ------------------------------- CoordGeodetic.h | 84 +++++++++++++++++++++++++++++++++++++++-------- Makefile | 3 +- 3 files changed, 71 insertions(+), 72 deletions(-) delete mode 100644 CoordGeodetic.cpp diff --git a/CoordGeodetic.cpp b/CoordGeodetic.cpp deleted file mode 100644 index e07a467..0000000 --- a/CoordGeodetic.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "CoordGeodetic.h" - -#include "Globals.h" - -#include -#include - -CoordGeodetic::CoordGeodetic(const CoordGeodetic& b) { - - latitude = b.latitude; - longitude = b.longitude; - altitude = b.altitude; -} - -CoordGeodetic& CoordGeodetic::operator =(const CoordGeodetic& b) { - - if (this != &b) { - latitude = b.latitude; - longitude = b.longitude; - altitude = b.altitude; - } - - return (*this); -} - -bool CoordGeodetic::operator ==(const CoordGeodetic& b) const { - - if (latitude == b.latitude && - longitude == b.longitude && - altitude == b.altitude) { - return true; - } else { - return false; - } -} - -bool CoordGeodetic::operator !=(const CoordGeodetic& b) const { - - if (latitude == b.latitude && - longitude == b.longitude && - altitude == b.altitude) { - return false; - } else { - return true; - } -} - -std::ostream& operator<< (std::ostream& stream, const CoordGeodetic& geo) { - std::stringstream out; - out << std::right << std::fixed << std::setprecision(2); - out << "Lat: " << std::setw(7) << RadiansToDegrees(geo.latitude); - out << ", Lon: " << std::setw(7) << RadiansToDegrees(geo.longitude); - out << ", Alt: " << std::setw(9) << geo.altitude; - stream << out.str(); - return stream; -} diff --git a/CoordGeodetic.h b/CoordGeodetic.h index 5060fb4..3a55d5b 100644 --- a/CoordGeodetic.h +++ b/CoordGeodetic.h @@ -1,33 +1,70 @@ #ifndef COORDGEODETIC_H_ #define COORDGEODETIC_H_ -#include +#include "Globals.h" -struct CoordGeodetic { +#include +#include +#include + +struct CoordGeodetic +{ public: - CoordGeodetic() - : latitude(0.0), longitude(0.0), altitude(0.0) { + : latitude(0.0), longitude(0.0), altitude(0.0) + { } /* * radians */ CoordGeodetic(double lat, double lon, double alt) - : latitude(lat), longitude(lon), altitude(alt) { + : latitude(lat), longitude(lon), altitude(alt) + { } - CoordGeodetic(const CoordGeodetic& g); + CoordGeodetic(const CoordGeodetic& g) + { + latitude = g.latitude; + longitude = g.longitude; + altitude = g.altitude; + } - virtual ~CoordGeodetic() { - }; + virtual ~CoordGeodetic() + { + } + + CoordGeodetic& operator=(const CoordGeodetic& g) + { + if (this != &g) + { + latitude = g.latitude; + longitude = g.longitude; + altitude = g.altitude; + } + return *this; + } + + bool operator==(const CoordGeodetic& g) const + { + return IsEqual(g); + } + + bool operator!=(const CoordGeodetic& g) const + { + return !IsEqual(g); + } + + std::string ToString() const + { + std::stringstream ss; + ss << std::right << std::fixed << std::setprecision(2); + ss << "Lat: " << std::setw(6) << RadiansToDegrees(latitude); + ss << ", Lon: " << std::setw(7) << RadiansToDegrees(longitude); + ss << ", Alt: " << std::setw(9) << altitude; + return ss.str(); + } - CoordGeodetic & operator =(const CoordGeodetic& b); - bool operator ==(const CoordGeodetic& b) const; - bool operator !=(const CoordGeodetic& b) const; - - friend std::ostream& operator<< (std::ostream& stream, const CoordGeodetic& geo); - /* * radians (north positive, south negative) */ @@ -40,7 +77,26 @@ public: * kilometers */ double altitude; + +protected: + bool IsEqual(const CoordGeodetic& g) const + { + if (latitude == g.latitude && longitude == g.longitude && + altitude == g.altitude) + { + return false; + } + else + { + return true; + } + } }; +inline std::ostream& operator<<(std::ostream& strm, const CoordGeodetic& g) +{ + return strm << g.ToString(); +} + #endif diff --git a/Makefile b/Makefile index 13826e3..5fff29f 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,7 @@ endif LDFLAGS= -SOURCES=CoordGeodetic.cpp \ - CoordTopographic.cpp \ +SOURCES=CoordTopographic.cpp \ Eci.cpp \ Globals.cpp \ Julian.cpp \