mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
Ref T275, Ref T280, avoid nan (not a number) values in PQs/elevation
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include "aircraftsituationchange.h"
|
#include "aircraftsituationchange.h"
|
||||||
#include "blackmisc/comparefunctions.h"
|
#include "blackmisc/comparefunctions.h"
|
||||||
#include "blackmisc/stringutils.h"
|
#include "blackmisc/stringutils.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
#include "blackconfig/buildconfig.h"
|
#include "blackconfig/buildconfig.h"
|
||||||
|
|
||||||
#include "QStringBuilder"
|
#include "QStringBuilder"
|
||||||
@@ -152,9 +153,16 @@ namespace BlackMisc
|
|||||||
|
|
||||||
if (situation.hasGroundElevation())
|
if (situation.hasGroundElevation())
|
||||||
{
|
{
|
||||||
|
const CLength aboveGnd = situation.getHeightAboveGround();
|
||||||
|
if (aboveGnd.isNull() || std::isnan(aboveGnd.value()))
|
||||||
|
{
|
||||||
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, "above gnd.is null");
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
const double nearGround1Ft = 300;
|
const double nearGround1Ft = 300;
|
||||||
const double nearGround2Ft = isLikelyTakeOffOrClimbing ? 500 : 1000;
|
const double nearGround2Ft = isLikelyTakeOffOrClimbing ? 500 : 1000;
|
||||||
const double aGroundFt = situation.getHeightAboveGround().value(CLengthUnit::ft());
|
const double aGroundFt = aboveGnd.value(CLengthUnit::ft());
|
||||||
static const QString detailsInfo("above ground: %1ft near grounds: %2ft %3ft likely takeoff: %4 likely landing: %5");
|
static const QString detailsInfo("above ground: %1ft near grounds: %2ft %3ft likely takeoff: %4 likely landing: %5");
|
||||||
|
|
||||||
if (details) { *details = detailsInfo.arg(aGroundFt).arg(nearGround1Ft).arg(nearGround2Ft).arg(boolToYesNo(isLikelyTakeOffOrClimbing), boolToYesNo(isLikelyLanding)); }
|
if (details) { *details = detailsInfo.arg(aGroundFt).arg(nearGround1Ft).arg(nearGround2Ft).arg(boolToYesNo(isLikelyTakeOffOrClimbing), boolToYesNo(isLikelyLanding)); }
|
||||||
@@ -325,7 +333,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CAircraftParts::guessParts(const CAircraftSituation &situation, const CAircraftSituationChange &change, const CAircraftModel &model)
|
void CAircraftParts::guessParts(const CAircraftSituation &situation, const CAircraftSituationChange &change, const CAircraftModel &model)
|
||||||
{
|
{
|
||||||
*this = guessedParts(situation, change, model);
|
*this = CAircraftParts::guessedParts(situation, change, model);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -241,8 +241,12 @@ namespace BlackMisc
|
|||||||
|
|
||||||
if (!situation.isNull())
|
if (!situation.isNull())
|
||||||
{
|
{
|
||||||
const double distanceOldNewM = (distance.isNull() ? oldSituation.calculateGreatCircleDistance(newSituation) : distance).value(CLengthUnit::m());
|
|
||||||
const double distanceSituationNewM = situation.calculateGreatCircleDistance(newSituation).value(CLengthUnit::m());
|
const double distanceSituationNewM = situation.calculateGreatCircleDistance(newSituation).value(CLengthUnit::m());
|
||||||
|
if (distanceSituationNewM < 5.0) { return newSituation.getGroundElevationPlane(); }
|
||||||
|
|
||||||
|
const double distanceOldNewM = (distance.isNull() ? oldSituation.calculateGreatCircleDistance(newSituation) : distance).value(CLengthUnit::m());
|
||||||
|
if (distanceOldNewM < 5.0) { return oldSituation.getGroundElevationPlane(); }
|
||||||
|
|
||||||
const double distRatio = distanceSituationNewM / distanceOldNewM;
|
const double distRatio = distanceSituationNewM / distanceOldNewM;
|
||||||
|
|
||||||
// very close to the situations we return tehir elevation
|
// very close to the situations we return tehir elevation
|
||||||
@@ -785,15 +789,30 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CLength CAircraftSituation::getHeightAboveGround() const
|
CLength CAircraftSituation::getHeightAboveGround() const
|
||||||
{
|
{
|
||||||
if (this->getAltitude().isNull()) { return { 0, nullptr }; }
|
if (this->getAltitude().isNull()) { return CLength::null(); }
|
||||||
if (this->getAltitude().getReferenceDatum() == CAltitude::AboveGround)
|
if (this->getAltitude().getReferenceDatum() == CAltitude::AboveGround)
|
||||||
{
|
{
|
||||||
// we have a sure value explicitly set
|
// we have a sure value explicitly set
|
||||||
return this->getAltitude();
|
return this->getAltitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CLength gh(this->getGroundElevation());
|
const CLength gh(this->getGroundElevation());
|
||||||
if (gh.isNull()) { return { 0, nullptr }; }
|
if (gh.isNull()) { return CLength::null(); }
|
||||||
return this->getAltitude() - gh;
|
|
||||||
|
// sanity checks
|
||||||
|
if (std::isnan(gh.value()))
|
||||||
|
{
|
||||||
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, "nan ground");
|
||||||
|
return CLength::null();
|
||||||
|
}
|
||||||
|
if (std::isnan(this->getAltitude().value()))
|
||||||
|
{
|
||||||
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, "nan altitude");
|
||||||
|
return CLength::null();
|
||||||
|
}
|
||||||
|
|
||||||
|
const CLength ag = this->getAltitude() - gh;
|
||||||
|
return ag;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CLengthUnit &CAircraftSituation::getAltitudeOrDefaultUnit() const
|
const CLengthUnit &CAircraftSituation::getAltitudeOrDefaultUnit() const
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CElevationPlane::CElevationPlane(double latDeg, double lngDeg, double altitudeMSLft, const CLength &radius) :
|
CElevationPlane::CElevationPlane(double latDeg, double lngDeg, double altitudeMSLft, const CLength &radius) :
|
||||||
CCoordinateGeodetic(latDeg, lngDeg, altitudeMSLft), m_radius(radius)
|
CCoordinateGeodetic(latDeg, lngDeg, altitudeMSLft), m_radius(radius)
|
||||||
{ }
|
{
|
||||||
|
Q_ASSERT_X(!std::isnan(altitudeMSLft), Q_FUNC_INFO, "elv.nan");
|
||||||
|
}
|
||||||
|
|
||||||
void CElevationPlane::setRadiusOrMinimum(const CLength &radius)
|
void CElevationPlane::setRadiusOrMinimum(const CLength &radius)
|
||||||
{
|
{
|
||||||
@@ -93,7 +95,7 @@ namespace BlackMisc
|
|||||||
bool CElevationPlane::isWithinRange(const ICoordinateGeodetic &coordinate) const
|
bool CElevationPlane::isWithinRange(const ICoordinateGeodetic &coordinate) const
|
||||||
{
|
{
|
||||||
if (coordinate.isNull()) { return false; }
|
if (coordinate.isNull()) { return false; }
|
||||||
if (isNull()) { return false; }
|
if (this->isNull()) { return false; }
|
||||||
const CLength d = this->calculateGreatCircleDistance(coordinate);
|
const CLength d = this->calculateGreatCircleDistance(coordinate);
|
||||||
const bool inRange = (m_radius >= d);
|
const bool inRange = (m_radius >= d);
|
||||||
return inRange;
|
return inRange;
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ namespace BlackMisc
|
|||||||
template <class MU, class PQ>
|
template <class MU, class PQ>
|
||||||
CPhysicalQuantity<MU, PQ>::CPhysicalQuantity(double value, MU unit) :
|
CPhysicalQuantity<MU, PQ>::CPhysicalQuantity(double value, MU unit) :
|
||||||
m_value(unit.isNull() ? 0.0 : value), m_unit(unit)
|
m_value(unit.isNull() ? 0.0 : value), m_unit(unit)
|
||||||
{ }
|
{
|
||||||
|
Q_ASSERT_X(!std::isnan(value), Q_FUNC_INFO, "nan value");
|
||||||
|
}
|
||||||
|
|
||||||
template <class MU, class PQ>
|
template <class MU, class PQ>
|
||||||
CPhysicalQuantity<MU, PQ>::CPhysicalQuantity(const QString &unitString) :
|
CPhysicalQuantity<MU, PQ>::CPhysicalQuantity(const QString &unitString) :
|
||||||
|
|||||||
@@ -311,6 +311,7 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if model has been thru model matching
|
// check if model has been thru model matching
|
||||||
|
Q_ASSERT_X(!m_lastSituation.isNull(), Q_FUNC_INFO, "null situations");
|
||||||
parts.guessParts(m_lastSituation, m_pastSituationsChange, m_model);
|
parts.guessParts(m_lastSituation, m_pastSituationsChange, m_model);
|
||||||
this->logParts(parts, 0, false);
|
this->logParts(parts, 0, false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user