1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/coordinates.h

43 lines
1.1 KiB
C
Raw Normal View History

#ifndef COORDINATES_H
#define COORDINATES_H
#include <cmath>
#include <QPair>
#include <QDebug>
class Coordinates
{
public:
Coordinates() {_lon = NAN; _lat = NAN;}
Coordinates(const Coordinates &c) {_lon = c._lon; _lat = c._lat;}
Coordinates(qreal lon, qreal lat) {_lon = lon; _lat = lat;}
qreal &rlon() {return _lon;}
qreal &rlat() {return _lat;}
void setLon(qreal lon) {_lon = lon;}
void setLat(qreal lat) {_lat = lat;}
qreal lon() const {return _lon;}
qreal 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
{return (!std::isnan(_lon) && !std::isnan(_lat)
&& _lon >= -180.0 && _lon <= 180.0 && _lat >= -90.0 && _lat <= 90.0);}
2016-10-29 10:40:30 +02:00
qreal distanceTo(const Coordinates &c) const;
2016-12-06 01:48:26 +01:00
QPair<Coordinates, Coordinates> boundingRect(qreal distance) const;
private:
qreal _lat, _lon;
};
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);}
QDebug operator<<(QDebug dbg, const Coordinates &trackpoint);
#endif // COORDINATES_H