swift
Loading...
Searching...
No Matches
elevationplane.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
7#include "misc/pq/length.h"
9
10using namespace swift::misc::aviation;
11using namespace swift::misc::physical_quantities;
12
13namespace swift::misc::geo
14{
16 {
17 const QString coordinate = CCoordinateGeodetic::toQString(i18n);
18 return QStringLiteral("%1 radius: %2").arg(coordinate, m_radius.valueRoundedWithUnit(2, i18n));
19 }
20
22 : CCoordinateGeodetic(coordinate)
23 {
24 this->setRadiusOrMinimumRadius(this->calculateGreatCircleDistance(rangeCoordinate));
25 }
26
28 : CCoordinateGeodetic(coordinate), m_radius(radius)
29 {}
30
32 const CLength &radius)
33 : CCoordinateGeodetic(coordinate), m_radius(radius)
34 {
35 this->setGeodeticHeight(altitude);
36 }
37
38 CElevationPlane::CElevationPlane(const ICoordinateGeodetic &coordinate, double altitudeMSLft, const CLength &radius)
39 : CCoordinateGeodetic(coordinate), m_radius(radius)
40 {
42 }
43
44 CElevationPlane::CElevationPlane(double latDeg, double lngDeg, double altitudeMSLft, const CLength &radius)
45 : CCoordinateGeodetic(latDeg, lngDeg, altitudeMSLft), m_radius(radius)
46 {
47 Q_ASSERT_X(!std::isnan(altitudeMSLft), Q_FUNC_INFO, "elv.nan");
48 }
49
50 CElevationPlane::CElevationPlane(const CLatitude &lat, const CLongitude &lng, const CAltitude &altitude,
51 const CLength &radius)
52 : CCoordinateGeodetic(lat, lng, altitude), m_radius(radius)
53 {
54 Q_ASSERT_X(altitude.isMeanSeaLevel(), Q_FUNC_INFO, "Need MSL");
55 }
56
58 {
59 if (m_radius.isNull() || m_radius < CElevationPlane::singlePointRadius())
60 {
62 }
63 return m_radius;
64 }
65
67 {
68 m_radius = ((radius.isNull() || radius < CElevationPlane::singlePointRadius())) ?
70 radius;
71 }
72
74 {
75 if (m_radius.isNull() || m_radius < CElevationPlane::singlePointRadius())
76 {
78 }
79 }
80
82 {
83 if (offset.isNull() || offset.isZeroEpsilonConsidered())
84 {
85 return;
86 }
87 const CAltitude newAlt = this->getAltitude().withOffset(offset);
88 this->setGeodeticHeight(newAlt);
89 }
90
92 {
93 if (unit.isNull() || this->getAltitudeUnit().isNull())
94 {
95 return;
96 }
97 if (this->getAltitudeUnit() == unit)
98 {
99 return;
100 }
101 this->setGeodeticHeight(this->getAltitude().switchedUnit(unit));
102 }
103
105 {
106 return (isWithinRange(coordinate)) ? geodeticHeight() : CAltitude::null();
107 }
108
110 {
111 CAltitude a = this->geodeticHeight();
112 a.switchUnit(unit);
113 return a;
114 }
115
116 double CElevationPlane::getAltitudeValue(const CLengthUnit &unit) const { return this->getAltitude().value(unit); }
117
118 bool CElevationPlane::isNull() const { return m_radius.isNull() || CCoordinateGeodetic::isNull(); }
119
121 {
122 if (coordinate.isNull())
123 {
124 return false;
125 }
126 if (this->isNull())
127 {
128 return false;
129 }
130 const CLength d = this->calculateGreatCircleDistance(coordinate);
131 const bool inRange = (m_radius >= d);
132 return inRange;
133 }
134
135 bool CElevationPlane::isWithinRange(const ICoordinateGeodetic &coordinate, const CLength &radius) const
136 {
137 if (coordinate.isNull())
138 {
139 return false;
140 }
141 if (radius.isNull())
142 {
143 return false;
144 }
145 if (this->isNull())
146 {
147 return false;
148 }
149 const CLength d = this->calculateGreatCircleDistance(coordinate);
150 const bool inRange = (radius >= d);
151 return inRange;
152 }
153
155
157
159
161 {
162 if (index.isMyself())
163 {
164 return QVariant::fromValue(*this);
165 }
166 const auto i = index.frontCasted<ColumnIndex>();
167 switch (i)
168 {
169 case IndexRadius: return m_radius.propertyByIndex(index.copyFrontRemoved());
170 default: break;
171 }
173 }
174
176 {
177 if (index.isMyself())
178 {
179 (*this) = variant.value<CElevationPlane>();
180 return;
181 }
182 const auto i = index.frontCasted<ColumnIndex>();
183 switch (i)
184 {
185 case IndexRadius: m_radius.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
186 default: CCoordinateGeodetic::setPropertyByIndex(index, variant); break;
187 }
188 }
189
191 {
192 Q_UNUSED(index)
193 return this->getAltitude().compare(elevationPlane.getAltitude());
194 }
195
196 // distance per second distance per 5 secs (taxi speeds)
197 // 100km/h 27,8m/s 10kts 51m/5secs
198 // 50km/h 13,9m/s 20kts 102m/5secs
199 // 100kts 51,4m/s
201 {
202 static const CLength l(50.0, CLengthUnit::m());
203 return l;
204 }
205
207 {
208 static const CLength l(500.0, CLengthUnit::m());
209 return l;
210 }
211
213 {
214 static const CLength l(1000.0, CLengthUnit::m());
215 return l;
216 }
217
219 {
220 static const CElevationPlane p;
221 return p;
222 }
223} // namespace swift::misc::geo
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
Altitude as used in aviation, can be AGL or MSL altitude.
Definition altitude.h:52
bool isMeanSeaLevel() const
MSL Mean sea level?
Definition altitude.h:139
CAltitude withOffset(const CLength &offset) const
Altitude with offset.
Definition altitude.cpp:61
CAltitude & switchUnit(const physical_quantities::CLengthUnit &newUnit)
Value in switched unit.
Definition altitude.cpp:77
int compare(const CAltitude &otherAltitude) const
Return negative, zero, or positive if a is less than, equal to, or greater than b.
Definition altitude.cpp:471
static const CAltitude & null()
Null altitude (MSL).
Definition altitude.cpp:511
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
void setGeodeticHeight(const aviation::CAltitude &height)
Set height (ellipsoidal or geodetic height).
const aviation::CAltitude & geodeticHeight() const
Height, ellipsoidal or geodetic height (used in GPS).
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setMinorAirportRadius()
Treat as elevation of a small airport.
static const physical_quantities::CLength & singlePointRadius()
Radius for single point.
const physical_quantities::CLengthUnit & getAltitudeUnit() const
Altitude (synonym for geodetic height) unit.
static const physical_quantities::CLength & majorAirportRadius()
Radius for major airport.
void addAltitudeOffset(const physical_quantities::CLength &offset)
Add offset to altitude.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void switchAltitudeUnit(const physical_quantities::CLengthUnit &unit)
Switch altitude unit.
bool isWithinRange(const ICoordinateGeodetic &coordinate) const
Check if elevation is within radius and can be used.
bool isNull() const
Existing value?
const aviation::CAltitude & getAltitudeIfWithinRadius(const ICoordinateGeodetic &coordinate) const
Altitude when within radius, else null.
QString convertToQString(bool i18n=false) const
Cast as QString.
CCoordinateGeodetic()=default
Constructors from CCoordinateGeodetic.
void setRadiusOrMinimumRadius(const physical_quantities::CLength &radius)
Radius or minimum CElevationPlane::singlePointRadius.
void fixRadius()
Set minimum radius if not having radius.
static const physical_quantities::CLength & minorAirportRadius()
Radius for minor airport.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
double getAltitudeValue(const physical_quantities::CLengthUnit &unit) const
Altitude (synonym for geodetic height).
const physical_quantities::CLength & getRadiusOrMinimumRadius() const
Radius or minimum radius.
const aviation::CAltitude & getAltitude() const
Altitude (synonym for geodetic height).
aviation::CAltitude getAltitudeInUnit(const physical_quantities::CLengthUnit &unit) const
Altitude (synonym for geodetic height).
CElevationPlane()=default
Default constructor.
static const CElevationPlane & null()
NULL plane.
void setMajorAirportRadius()
Treat as elevation of a small airport.
int comparePropertyByIndex(CPropertyIndexRef index, const CElevationPlane &elevationPlane) const
Compare for index.
void setSinglePointRadius()
Treat as single point as obtained from simulator.
Geodetic coordinate, a position in 3D space relative to the reference geoid.
virtual bool isNull() const
Is null, means vector x, y, z == 0.
QString toQString(bool i18n=false) const
Definition mixinstring.h:74
Physical unit length (length).
Definition length.h:18
Specialized class for distance units (meter, foot, nautical miles).
Definition units.h:95
static CLengthUnit m()
Meter m.
Definition units.h:140
static CLengthUnit ft()
Foot ft.
Definition units.h:157
double value(MU unit) const
Value in given unit.
bool isZeroEpsilonConsidered() const
Quantity value <= epsilon.
QVariant fromValue(T &&value)
T value() const &const