refactor: Move PBH interpolator to inidivdual Interpolants

This allows each interpolant to specify on its own which PBH
interpolator should be used. Currently only the linear PBH interpolator
is available, but another PBH interpolator will be added for velocity.

This removes some protected data from the IInterpolator interface as well,
which conforms to C++ Core Guideline C.113 ("Avoid protected data").
This commit is contained in:
Lars Toenning
2024-01-09 22:14:14 +01:00
parent e247f20482
commit 2f3e4fee1e
5 changed files with 13 additions and 11 deletions

View File

@@ -17,9 +17,6 @@ namespace BlackMisc::Simulation
//! "Real time" representing the interpolated situation
qint64 getInterpolatedTime() const { return m_interpolatedTime; }
//! Interpolator for pitch, bank, heading, groundspeed
const CInterpolatorPbh &pbh() const { return m_pbh; }
//! Situations available
int getSituationsAvailable() const { return m_situationsAvailable; }
@@ -37,17 +34,16 @@ namespace BlackMisc::Simulation
protected:
//! Default ctor
IInterpolant() {}
IInterpolant() = default;
//! Constructor
IInterpolant(int situationsAvailable, const CInterpolatorPbh &pbh) : m_situationsAvailable(situationsAvailable), m_pbh(pbh) {}
explicit IInterpolant(int situationsAvailable) : m_situationsAvailable(situationsAvailable) {}
//! Constructor
IInterpolant(qint64 interpolatedTime, int situationsAvailable) : m_interpolatedTime(interpolatedTime), m_situationsAvailable(situationsAvailable) {}
qint64 m_interpolatedTime = -1; //!< "Real time "of interpolated situation
int m_situationsAvailable = 0; //!< used situations
CInterpolatorPbh m_pbh; //!< the used PBH interpolator
bool m_valid = true; //!< valid?
bool m_recalculated = false; //!< recalculated interpolant
};

View File

@@ -245,12 +245,12 @@ namespace BlackMisc::Simulation
do
{
if (!isValidInterpolant) { break; }
const CInterpolatorPbh pbh = interpolant.pbh();
// init interpolated situation
currentSituation = this->initInterpolatedSituation(pbh.getStartSituation(), pbh.getEndSituation());
// Pitch bank heading first, so follow up steps could use those values
const auto pbh = interpolant.pbh();
currentSituation.setHeading(pbh.getHeading());
currentSituation.setPitch(pbh.getPitch());
currentSituation.setBank(pbh.getBank());

View File

@@ -23,12 +23,12 @@ using namespace BlackMisc::Simulation;
namespace BlackMisc::Simulation
{
CInterpolatorLinear::CInterpolant::CInterpolant(const CAircraftSituation &startSituation) : IInterpolant(1, CInterpolatorPbh(0, startSituation, startSituation)),
m_startSituation(startSituation)
CInterpolatorLinear::CInterpolant::CInterpolant(const CAircraftSituation &startSituation) : IInterpolant(1),
m_startSituation(startSituation), m_pbh(0, startSituation, startSituation)
{}
CInterpolatorLinear::CInterpolant::CInterpolant(const CAircraftSituation &startSituation, const CInterpolatorPbh &pbh) : IInterpolant(1, pbh),
m_startSituation(startSituation)
CInterpolatorLinear::CInterpolant::CInterpolant(const CAircraftSituation &startSituation, const CInterpolatorPbh &pbh) : IInterpolant(1),
m_startSituation(startSituation), m_pbh(pbh)
{}
CInterpolatorLinear::CInterpolant::CInterpolant(const CAircraftSituation &startSituation, const CAircraftSituation &endSituation, double timeFraction, qint64 interpolatedTime) : IInterpolant(interpolatedTime, 2),

View File

@@ -60,10 +60,13 @@ namespace BlackMisc
//! End situation
const Aviation::CAircraftSituation &getEndSituation() const { return m_endSituation; }
CInterpolatorPbh pbh() const { return m_pbh; }
private:
Aviation::CAircraftSituation m_startSituation;
Aviation::CAircraftSituation m_endSituation;
double m_simulationTimeFraction = 0.0; //!< 0..1
CInterpolatorPbh m_pbh;
};
//! Get the interpolant for the given time point

View File

@@ -77,10 +77,13 @@ namespace BlackMisc::Simulation
//! \private UNIT tests/ASSERT only
const PosArray &getPa() const { return m_pa; }
CInterpolatorPbh pbh() const { return m_pbh; }
private:
PosArray m_pa; //!< current positions array, latest values last
PhysicalQuantities::CLengthUnit m_altitudeUnit;
qint64 m_currentTimeMsSinceEpoc { -1 };
CInterpolatorPbh m_pbh; //!< the used PBH interpolator
};
//! Strategy used by CInterpolator::getInterpolatedSituation