Ref T261, unify unit handling in situation altitude related values

* this is an optimization, it would work without that, but there are numerous calculations in interpolation which are faster and easier to debug in the same unit
* PQ switch unit functions use "const &PQUnit"
This commit is contained in:
Klaus Basan
2018-05-07 11:40:59 +02:00
committed by Roland Winklmeier
parent 337f661499
commit 23c54938ea
8 changed files with 107 additions and 29 deletions

View File

@@ -16,6 +16,7 @@
#include <Qt>
#include <QtGlobal>
#include <QStringBuilder>
using namespace BlackMisc::PhysicalQuantities;
@@ -34,7 +35,7 @@ namespace BlackMisc
CAltitude copy(*this);
if (!offset.isNull() && !offset.isZeroEpsilonConsidered())
{
copy += offset;
copy += offset.switchedUnit(this->getUnit());
}
return copy;
}
@@ -44,6 +45,21 @@ namespace BlackMisc
*this = this->withOffset(offset);
}
CAltitude &CAltitude::switchUnit(const CLengthUnit &newUnit)
{
if (newUnit.isNull() || this->getUnit().isNull() || this->getUnit() == newUnit) { return *this; }
CLength::switchUnit(newUnit);
return *this;
}
CAltitude CAltitude::switchedUnit(const CLengthUnit &newUnit) const
{
if (newUnit.isNull() || this->getUnit().isNull() || this->getUnit() == newUnit) { return *this; }
CAltitude copy(*this);
copy.switchUnit(newUnit);
return copy;
}
QString CAltitude::convertToQString(bool i18n) const
{
if (this->m_datum == FlightLevel)
@@ -324,6 +340,11 @@ namespace BlackMisc
return null;
}
const CLengthUnit &CAltitude::defaultUnit()
{
return CLengthUnit::ft();
}
const CPressure &CAltitude::standardISASeaLevelPressure()
{
// Average sea-level pressure is 1013.25mbar or 1013.25hPa