From 6d105b9665201bb8cb2e58fc5ebdc9e6b667f75d Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 7 May 2018 11:43:11 +0200 Subject: [PATCH] Ref T261, make sure the unit is correct in spline altitude interpolation See slack discussion here https://swift-project.slack.com/archives/G7GD2UP9C/p1525605407000025 --- .../simulation/interpolatorspline.cpp | 23 +++++-------------- src/blackmisc/simulation/interpolatorspline.h | 3 --- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/blackmisc/simulation/interpolatorspline.cpp b/src/blackmisc/simulation/interpolatorspline.cpp index 27459f5c4..472124524 100644 --- a/src/blackmisc/simulation/interpolatorspline.cpp +++ b/src/blackmisc/simulation/interpolatorspline.cpp @@ -174,21 +174,21 @@ namespace BlackMisc // - and the elevation remains (almost) constant for a wider area // - during flying the ground elevation not really matters this->updateElevations(); - const CLength cg(this->getModelCG()); - const double a0 = m_s[0].getCorrectedAltitude(cg).value(); // oldest - const double a1 = m_s[1].getCorrectedAltitude(cg).value(); - const double a2 = m_s[2].getCorrectedAltitude(cg).value(); // latest + static const CLengthUnit altUnit = CAltitude::defaultUnit(); + const CLength cg(this->getModelCG().switchedUnit(altUnit)); + const double a0 = m_s[0].getCorrectedAltitude(cg).value(altUnit); // oldest + const double a1 = m_s[1].getCorrectedAltitude(cg).value(altUnit); + const double a2 = m_s[2].getCorrectedAltitude(cg).value(altUnit); // latest pa.a = {{ a0, a1, a2 }}; pa.gnd = {{ m_s[0].getOnGroundFactor(), m_s[1].getOnGroundFactor(), m_s[2].getOnGroundFactor() }}; pa.da = getDerivatives(pa.t, pa.a); pa.dgnd = getDerivatives(pa.t, pa.gnd); - Q_ASSERT_X(this->areAltitudeUnitsSame(), Q_FUNC_INFO, "Altitude unit mismatch"); m_prevSampleAdjustedTime = m_s[1].getAdjustedMSecsSinceEpoch(); m_nextSampleAdjustedTime = m_s[2].getAdjustedMSecsSinceEpoch(); // latest m_prevSampleTime = m_s[1].getMSecsSinceEpoch(); m_nextSampleTime = m_s[2].getMSecsSinceEpoch(); // latest - m_interpolant = CInterpolant(pa, m_s[2].getAltitudeUnit(), CInterpolatorPbh(m_s[1], m_s[2])); + m_interpolant = CInterpolant(pa, altUnit, CInterpolatorPbh(m_s[1], m_s[2])); Q_ASSERT_X(m_prevSampleAdjustedTime < m_nextSampleAdjustedTime, Q_FUNC_INFO, "Wrong time order"); } @@ -262,17 +262,6 @@ namespace BlackMisc return false; } - bool CInterpolatorSpline::areAltitudeUnitsSame(const CLengthUnit &compare) const - { - if (m_s.size() < 1) { return true; } - const CLengthUnit c = compare.isNull() ? m_s[0].getAltitudeUnit() : compare; - for (unsigned int i = 0; i < m_s.size(); i++) - { - if (m_s[i].getAltitudeUnit() != c) { return false; } - } - return true; - } - CInterpolatorSpline::CInterpolant::CInterpolant(const CInterpolatorSpline::PosArray &pa, const CLengthUnit &altitudeUnit, const CInterpolatorPbh &pbh) : m_pa(pa), m_altitudeUnit(altitudeUnit) { diff --git a/src/blackmisc/simulation/interpolatorspline.h b/src/blackmisc/simulation/interpolatorspline.h index f6f58df6f..70f1dc8f6 100644 --- a/src/blackmisc/simulation/interpolatorspline.h +++ b/src/blackmisc/simulation/interpolatorspline.h @@ -92,9 +92,6 @@ namespace BlackMisc //! Ground relevant bool isAnySituationNearGroundRelevant() const; - //! Are the altitude units all the same - bool areAltitudeUnitsSame(const PhysicalQuantities::CLengthUnit &compare = PhysicalQuantities::CLengthUnit::nullUnit()) const; - //! Fill the situations array bool fillSituationsArray();