2016-10-24 00:21:40 +02:00
|
|
|
#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)
|
|
|
|
|
2016-10-24 00:21:40 +02:00
|
|
|
class Coordinates
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Coordinates() {_lon = NAN; _lat = NAN;}
|
2018-04-13 21:14:12 +02:00
|
|
|
Coordinates(double lon, double lat) {_lon = lon; _lat = lat;}
|
2017-03-29 00:17:47 +02:00
|
|
|
|
2018-04-13 21:14:12 +02:00
|
|
|
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-24 00:21:40 +02:00
|
|
|
|
2016-10-29 10:40:30 +02:00
|
|
|
bool isNull() const
|
2017-06-30 18:38:16 +02:00
|
|
|
{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
|
|
|
|
2018-04-13 21:14:12 +02:00
|
|
|
double distanceTo(const Coordinates &c) const;
|
2016-10-24 00:21:40 +02:00
|
|
|
|
|
|
|
private:
|
2018-04-13 21:14:12 +02:00
|
|
|
double _lat, _lon;
|
2016-10-24 00:21:40 +02:00
|
|
|
};
|
|
|
|
|
2018-10-05 07:10:49 +02:00
|
|
|
Q_DECLARE_TYPEINFO(Coordinates, Q_PRIMITIVE_TYPE);
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
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);}
|
2017-06-29 22:29:27 +02:00
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2017-11-26 18:54:03 +01:00
|
|
|
QDebug operator<<(QDebug dbg, const Coordinates &c);
|
2018-02-13 23:03:18 +01:00
|
|
|
#endif // QT_NO_DEBUG
|
2016-10-24 00:21:40 +02:00
|
|
|
|
|
|
|
#endif // COORDINATES_H
|