1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00
GPXSee/src/common/coordinates.h

47 lines
1.1 KiB
C
Raw Normal View History

#ifndef COORDINATES_H
#define COORDINATES_H
#include <cmath>
#include <QDebug>
2017-11-26 18:54:03 +01:00
#define deg2rad(d) (((d)*M_PI)/180.0)
#define rad2deg(d) (((d)*180.0)/M_PI)
class Coordinates
{
public:
Coordinates() {_lon = NAN; _lat = NAN;}
Coordinates(double lon, double lat) {_lon = lon; _lat = lat;}
double &rlon() {return _lon;}
double &rlat() {return _lat;}
void setLon(double lon) {_lon = lon;}
void setLat(double lat) {_lat = lat;}
double lon() const {return _lon;}
double lat() const {return _lat;}
2016-10-29 10:40:30 +02:00
bool isNull() const
{return std::isnan(_lon) && std::isnan(_lat);}
2016-10-29 10:40:30 +02:00
bool isValid() const
2017-07-02 09:39:31 +02:00
{return (_lon >= -180.0 && _lon <= 180.0
&& _lat >= -90.0 && _lat <= 90.0);}
2016-10-29 10:40:30 +02:00
double distanceTo(const Coordinates &c) const;
private:
double _lat, _lon;
};
2018-10-05 07:10:49 +02:00
Q_DECLARE_TYPEINFO(Coordinates, Q_PRIMITIVE_TYPE);
inline bool operator==(const Coordinates &c1, const Coordinates &c2)
{return (c1.lat() == c2.lat() && c1.lon() == c2.lon());}
inline bool operator!=(const Coordinates &c1, const Coordinates &c2)
{return !(c1 == c2);}
#ifndef QT_NO_DEBUG
2017-11-26 18:54:03 +01:00
QDebug operator<<(QDebug dbg, const Coordinates &c);
#endif // QT_NO_DEBUG
#endif // COORDINATES_H