From a599cc2792f443de89c18a80275af9c438748819 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Thu, 4 Jan 2024 22:43:12 +0100 Subject: [PATCH] refactor: Remove clear() method from CInterpolator clear() was only required by a unittest to execute two tests directly after another. This can also be done in a cleaner way by creating a new CInterpolator instead of requiring a separate method for resetting the interpolator. --- src/blackmisc/simulation/interpolator.cpp | 19 ------- src/blackmisc/simulation/interpolator.h | 15 ----- .../testinterpolatorparts.cpp | 55 +++++++++++-------- 3 files changed, 31 insertions(+), 58 deletions(-) diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index 04475a9cc..8530bdae4 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -673,25 +673,6 @@ namespace BlackMisc::Simulation m_lastSituation.setNull(); } - template - void CInterpolator::clear() - { - this->resetLastInterpolation(); - m_model = CAircraftModel(); - m_currentSceneryOffset = CLength::null(); - m_pastSituationsChange = CAircraftSituationChange::null(); - m_currentSituations.clear(); - m_currentTimeMsSinceEpoch = -1; - m_situationsLastModified = -1; - m_situationsLastModifiedUsed = -1; - m_currentInterpolationStatus.reset(); - m_currentPartsStatus.reset(); - m_interpolatedSituationsCounter = 0; - m_invalidSituations = 0; - m_lastInvalidLogTs = -1; - m_interpolationMessages.clear(); - } - template bool CInterpolator::initIniterpolationStepData(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber) { diff --git a/src/blackmisc/simulation/interpolator.h b/src/blackmisc/simulation/interpolator.h index 6d6147ef2..5b99c7a67 100644 --- a/src/blackmisc/simulation/interpolator.h +++ b/src/blackmisc/simulation/interpolator.h @@ -195,16 +195,6 @@ namespace BlackMisc //! Parts and situation interpolated CInterpolationResult getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, uint32_t aircraftNumber); - //! Takes input between 0 and 1 and returns output between 0 and 1 smoothed with an S-shaped curve. - //! - //! Useful for making interpolation seem smoother, efficiently as it just uses simple arithmetic. - //! \see https://en.wikipedia.org/wiki/Smoothstep - //! \see http://sol.gfxile.net/interpolation/ - static double smootherStep(double x) - { - return x * x * x * (x * (x * 6.0 - 15.0) + 10.0); - } - //! Attach an observer to read the interpolator's state for debugging //! \remark parts logging has a \c bool \c log flag void attachLogger(CInterpolationLogger *logger) { m_logger = logger; } @@ -219,11 +209,6 @@ namespace BlackMisc //! \remark mainly needed in UNIT tests void resetLastInterpolation(); - //! Clear all data - //! \remark mainly needed in UNIT tests - //! \private - void clear(); - //! Init, or re-init the corressponding model //! \remark either by passing a model or using the provider void initCorrespondingModel(const CAircraftModel &model = {}); diff --git a/tests/blackmisc/simulation/testinterpolatorparts/testinterpolatorparts.cpp b/tests/blackmisc/simulation/testinterpolatorparts/testinterpolatorparts.cpp index a4c8c7a20..42c7548dc 100644 --- a/tests/blackmisc/simulation/testinterpolatorparts/testinterpolatorparts.cpp +++ b/tests/blackmisc/simulation/testinterpolatorparts/testinterpolatorparts.cpp @@ -46,8 +46,6 @@ namespace BlackMiscTest const CInterpolationAndRenderingSetupPerCallsign setup(cs, gSetup); CRemoteAircraftProviderDummy provider; - CInterpolatorSpline interpolator(cs, nullptr, nullptr, &provider); - interpolator.markAsUnitTest(); // fixed time so everything can be debugged const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch() @@ -70,32 +68,41 @@ namespace BlackMiscTest // Testing for a time >> last time // all on ground flags true - provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here - QVERIFY2(provider.remoteAircraftPartsCount(cs) == parts.size(), "Wrong parts size"); + { + CInterpolatorSpline interpolator(cs, nullptr, nullptr, &provider); + interpolator.markAsUnitTest(); - CInterpolationResult result = interpolator.getInterpolation(farFuture, setup); - CAircraftParts p = result; - qint64 pTs = p.getAdjustedMSecsSinceEpoch(); - QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts"); - QVERIFY2(pTs == ts, "Expect latest ts"); - result = interpolator.getInterpolation(farPast, setup); - p = result; - pTs = p.getAdjustedMSecsSinceEpoch(); - QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts"); - QVERIFY2(pTs == oldestTs, "Expect oldest ts"); + provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here + QVERIFY2(provider.remoteAircraftPartsCount(cs) == parts.size(), "Wrong parts size"); + + CInterpolationResult result = interpolator.getInterpolation(farFuture, setup, 0); + CAircraftParts p = result; + qint64 pTs = p.getAdjustedMSecsSinceEpoch(); + QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts"); + QVERIFY2(pTs == ts, "Expect latest ts"); + result = interpolator.getInterpolation(farPast, setup, 0); + p = result; + pTs = p.getAdjustedMSecsSinceEpoch(); + QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts"); + QVERIFY2(pTs == oldestTs, "Expect oldest ts"); + } // Testing for a time >> last time - // all on ground flags true - interpolator.clear(); - provider.clear(); + // all on ground flags false + { + provider.clear(); - parts.setOnGround(false); - provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here - result = interpolator.getInterpolation(farFuture, setup); - p = result; - pTs = p.getAdjustedMSecsSinceEpoch(); - QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts"); - QVERIFY2(p.getAdjustedMSecsSinceEpoch() == pTs, "Expect latest ts"); + CInterpolatorSpline interpolator(cs, nullptr, nullptr, &provider); + interpolator.markAsUnitTest(); + + parts.setOnGround(false); + provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here + CInterpolationResult result = interpolator.getInterpolation(farFuture, setup, 0); + CAircraftParts p = result; + qint64 pTs = p.getAdjustedMSecsSinceEpoch(); + QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts"); + QVERIFY2(p.getAdjustedMSecsSinceEpoch() == pTs, "Expect latest ts"); + } } void CTestInterpolatorParts::partsToSituationGndFlag()