refactor class route add a struct to hold coords

This commit is contained in:
2022-12-27 13:11:03 +01:00
parent a09cfe9b04
commit b9840bccf8
2 changed files with 60 additions and 20 deletions
+21 -8
View File
@@ -30,6 +30,15 @@
*/
class Point{
public:
struct Coordinates {
double lon;
double lat;
bool operator==(const Coordinates rhs) const {
return ( this->lon == rhs.lon ) && ( this->lon == rhs.lon );
}
};
enum PointAccuracy {
none,
fourDigOfCM,
@@ -42,15 +51,14 @@ class Point{
/**
* @brief Construct a new Point object
*
* @param lat latidude
* @param lat latitude
* @param lon longitude
*/
Point(double lat, double lon, uint32_t horizontalAccuracy = 0);
Point(int32_t lat, int32_t lon, uint32_t horizontalAccuracy = 0);
Point(Coordinates coords, uint32_t horizontalAccuracy = 0);
Point();
double lat = 0;
double lon = 0;
/**
* @brief checks if to points are equal
*
@@ -58,9 +66,7 @@ class Point{
* @return true
* @return false
*/
bool operator==(const Point& rhs) const {
return this->lat == rhs.lat && this->lon == rhs.lon;
}
bool operator==(const Point& rhs) const;
/**
* @brief Checks if the Point is initalized.
@@ -68,18 +74,25 @@ class Point{
* @return true
* @return false
*/
bool isInit() const { return this->lat + this->lon; }
bool isInit() const { return this->coordinates.lat + this->coordinates.lon; }
bool isValid() const { return (this->accuracy > 0) ? true : false; }
double distanceTo(const Coordinates& point) const;
double distanceTo(const Point& point) const;
double courseTo(const Coordinates& point) const;
double courseTo(const Point& point) const;
double getLongitude() const { return this->coordinates.lon; }
double getLatitude() const { return this->coordinates.lat; }
Coordinates getCoordinates() const { return this->coordinates; }
PointAccuracy getAccuracy() { return this->accuracy; }
private:
void init(uint32_t horizontalAccuracy);
PointAccuracy accuracy = PointAccuracy::none;
Coordinates coordinates;
uint32_t creationTime = 0;
};