Ref T668, clamp time fraction [0,1]

This commit is contained in:
Klaus Basan
2019-05-16 14:43:11 +02:00
parent 2c53846a96
commit 848f54d4a7
3 changed files with 18 additions and 8 deletions

View File

@@ -21,6 +21,12 @@ namespace BlackMisc
return timeFraction >= 0.0 && timeFraction <= 1.0; return timeFraction >= 0.0 && timeFraction <= 1.0;
} }
//! Valid time fraction [0,1], this allows minor overshooting
inline bool isAcceptableTimeFraction(double timeFraction)
{
return timeFraction >= 0.0 && timeFraction <= 1.01;
}
//! Clamp time fraction [0,1] //! Clamp time fraction [0,1]
inline double clampValidTimeFraction(double timeFraction) inline double clampValidTimeFraction(double timeFraction)
{ {

View File

@@ -66,14 +66,15 @@ namespace BlackMisc
{ {
BLACK_VERIFY_X(CAircraftSituation::isValidVector(oldVec), Q_FUNC_INFO, "Invalid old vector"); BLACK_VERIFY_X(CAircraftSituation::isValidVector(oldVec), Q_FUNC_INFO, "Invalid old vector");
BLACK_VERIFY_X(CAircraftSituation::isValidVector(newVec), Q_FUNC_INFO, "Invalid new vector"); BLACK_VERIFY_X(CAircraftSituation::isValidVector(newVec), Q_FUNC_INFO, "Invalid new vector");
BLACK_VERIFY_X(isValidTimeFraction(m_simulationTimeFraction), Q_FUNC_INFO, "Invalid fraction"); BLACK_VERIFY_X(isAcceptableTimeFraction(m_simulationTimeFraction), Q_FUNC_INFO, "Invalid fraction");
} }
// Interpolate position: pos = (posB - posA) * t + posA // Interpolate position: pos = (posB - posA) * t + posA
CCoordinateGeodetic newPosition; CCoordinateGeodetic newPosition;
newPosition.setNormalVector((newVec[0] - oldVec[0]) * m_simulationTimeFraction + oldVec[0], const double tf = clampValidTimeFraction(m_simulationTimeFraction);
(newVec[1] - oldVec[1]) * m_simulationTimeFraction + oldVec[1], newPosition.setNormalVector((newVec[0] - oldVec[0]) * tf + oldVec[0],
(newVec[2] - oldVec[2]) * m_simulationTimeFraction + oldVec[2]); (newVec[1] - oldVec[1]) * tf + oldVec[1],
(newVec[2] - oldVec[2]) * tf + oldVec[2]);
if (CBuildConfig::isLocalDeveloperDebugBuild()) if (CBuildConfig::isLocalDeveloperDebugBuild())
{ {
@@ -86,7 +87,7 @@ namespace BlackMisc
const CAltitude newAlt(m_newSituation.getCorrectedAltitude()); const CAltitude newAlt(m_newSituation.getCorrectedAltitude());
Q_ASSERT_X(oldAlt.getReferenceDatum() == CAltitude::MeanSeaLevel && oldAlt.getReferenceDatum() == newAlt.getReferenceDatum(), Q_FUNC_INFO, "mismatch in reference"); // otherwise no calculation is possible Q_ASSERT_X(oldAlt.getReferenceDatum() == CAltitude::MeanSeaLevel && oldAlt.getReferenceDatum() == newAlt.getReferenceDatum(), Q_FUNC_INFO, "mismatch in reference"); // otherwise no calculation is possible
const CAltitude altitude((newAlt - oldAlt) const CAltitude altitude((newAlt - oldAlt)
* m_simulationTimeFraction * tf
+ oldAlt, + oldAlt,
oldAlt.getReferenceDatum()); oldAlt.getReferenceDatum());
@@ -103,7 +104,7 @@ namespace BlackMisc
{ {
if (CAircraftSituation::isGfEqualAirborne(oldGroundFactor, newGroundFactor)) { newSituation.setOnGround(false); break; } if (CAircraftSituation::isGfEqualAirborne(oldGroundFactor, newGroundFactor)) { newSituation.setOnGround(false); break; }
if (CAircraftSituation::isGfEqualOnGround(oldGroundFactor, newGroundFactor)) { newSituation.setOnGround(true); break; } if (CAircraftSituation::isGfEqualOnGround(oldGroundFactor, newGroundFactor)) { newSituation.setOnGround(true); break; }
const double groundFactor = (newGroundFactor - oldGroundFactor) * m_simulationTimeFraction + oldGroundFactor; const double groundFactor = (newGroundFactor - oldGroundFactor) * tf + oldGroundFactor;
newSituation.setOnGroundFactor(groundFactor); newSituation.setOnGroundFactor(groundFactor);
newSituation.setOnGroundFromGroundFactorFromInterpolation(groundInterpolationFactor()); newSituation.setOnGroundFromGroundFactorFromInterpolation(groundInterpolationFactor());
} }

View File

@@ -32,9 +32,12 @@ namespace BlackMisc
if (CBuildConfig::isLocalDeveloperDebugBuild()) if (CBuildConfig::isLocalDeveloperDebugBuild())
{ {
BLACK_VERIFY_X(isValidTimeFraction(timeFraction0to1), Q_FUNC_INFO, "0..1 fraction needed"); BLACK_VERIFY_X(isAcceptableTimeFraction(timeFraction0to1), Q_FUNC_INFO, "0..1 fraction needed");
} }
//! make sure to not end up we extrapolation
if (timeFraction0to1 >= 1.0) { return begin + CAngle(deltaDeg, CAngleUnit::deg()); }
if (timeFraction0to1 <= 0.0) { return begin; }
return begin + CAngle(timeFraction0to1 * deltaDeg, CAngleUnit::deg()); return begin + CAngle(timeFraction0to1 * deltaDeg, CAngleUnit::deg());
} }