forked from OlivierDelbeke/MapGraphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosition.cpp
More file actions
188 lines (153 loc) · 4.49 KB
/
Copy pathPosition.cpp
File metadata and controls
188 lines (153 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "Position.h"
#include "guts/Conversions.h"
#include <QtGlobal>
#include <cmath>
Position::Position()
{
_lonLat = QPointF(0.0,0.0);
_altitude = 0;
}
Position::Position(qreal longitude, qreal latitude, qreal altitude)
{
_lonLat = QPointF(longitude,latitude);
_altitude = altitude;
}
Position::Position(const QPointF &lonLat, qreal altitude)
{
_lonLat = lonLat;
_altitude = altitude;
}
Position::Position(const Position &other)
{
_lonLat = other._lonLat;
_altitude = other._altitude;
}
Position::~Position()
{
}
bool Position::operator ==(const Position &other) const
{
return ((other._lonLat == this->_lonLat)
&& (other._altitude == this->_altitude));
}
bool Position::operator !=(const Position &other) const
{
return !(*this == other);
}
Position &Position::operator =(const Position &other)
{
if (&other != this)
{
_lonLat = other._lonLat;
_altitude = other._altitude;
}
return *this;
}
qreal Position::longitude() const
{
return _lonLat.x();
}
qreal Position::latitude() const
{
return _lonLat.y();
}
qreal Position::altitude() const
{
return _altitude;
}
QPointF Position::lonLat() const
{
return _lonLat;
}
void Position::setLongitude(const qreal &longitude)
{
_lonLat.setX(longitude);
}
void Position::setLatitude(const qreal &latitude)
{
_lonLat.setY(latitude);
}
void Position::setAltitude(const qreal &altitude)
{
_altitude = altitude;
}
qreal Position::flatDistanceEstimate(const Position &other) const
{
const QVector2D offsetMeters = this->flatOffsetMeters(other);
return offsetMeters.length();
}
QVector2D Position::flatOffsetMeters(const Position &dest) const
{
const qreal avgLat = (this->latitude() + dest.latitude()) / 2.0;
const qreal lonPerMeter = Conversions::degreesLonPerMeter(avgLat);
const qreal latPerMeter = Conversions::degreesLatPerMeter(avgLat);
const qreal lonDiffMeters = (dest.longitude() - this->longitude()) / lonPerMeter;
const qreal latDiffMeters = (dest.latitude() - this->latitude()) / latPerMeter;
return QVector2D(lonDiffMeters, latDiffMeters);
}
Position Position::flatOffsetToPosition(const QPointF& offset) const
{
const qreal lonPerMeter = Conversions::degreesLonPerMeter(this->latitude());
const qreal latPerMeter = Conversions::degreesLatPerMeter(this->latitude());
return Position(this->longitude() + offset.x() * lonPerMeter,
this->latitude() + offset.y() * latPerMeter);
}
qreal Position::flatManhattanEstimate(const Position &other) const
{
const QVector2D offsetMeters = this->flatOffsetMeters(other);
return qAbs<qreal>(offsetMeters.x()) + qAbs<qreal>(offsetMeters.y());
}
qreal Position::angleTo(const Position &dest) const
{
const QVector2D offsetMeters = this->flatOffsetMeters(dest);
return atan2(offsetMeters.y(), offsetMeters.x());
}
//static
QVector3D Position::Position2ENU(const Position &refPos, const Position &pos)
{
return Conversions::lla2enu(pos.latitude(),
pos.longitude(),
pos.altitude(),
refPos.latitude(),
refPos.longitude(),
refPos.altitude());
}
//static
Position Position::fromENU(const Position &refPos, const QVector3D &enu)
{
Position cPos = Conversions::enu2lla(enu,
refPos.latitude(),
refPos.longitude(),
refPos.altitude());
return cPos;
}
//Non-member method for streaming to qDebug
QDebug operator<<(QDebug dbg, const Position& pos)
{
dbg.nospace() << "(" << QString::number(pos.longitude(),'g',10) << "," << QString::number(pos.latitude(),'g',10) << ")";
return dbg.space();
}
//Non-member methods for serializing and de-serializing
QDataStream& operator<<(QDataStream& stream, const Position& pos)
{
stream << pos.longitude() << pos.latitude() << pos.altitude();
return stream;
}
QDataStream& operator>>(QDataStream& stream, Position& pos)
{
qreal longitude;
qreal latitude;
qreal altitude;
stream >> longitude;
stream >> latitude;
stream >> altitude;
pos.setLongitude(longitude);
pos.setLatitude(latitude);
pos.setAltitude(altitude);
return stream;
}
//Non-member method for hashing
uint qHash(const Position& pos)
{
return pos.lonLat().x() + pos.lonLat().y() + pos.altitude();
}