T37 Avoid division by zero in case time offset is zero.

This commit is contained in:
Mathew Sutcliffe
2017-08-15 23:46:36 +01:00
parent 98e0f8c875
commit f9ae3efaa3

View File

@@ -20,6 +20,7 @@
#include "blackmisc/pq/units.h"
#include "blackmisc/pq/length.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/verify.h"
#include <QDateTime>
#include <QStringBuilder>
@@ -228,6 +229,10 @@ namespace BlackMisc
Q_ASSERT(secondsSinceTakeoff >= 0.0);
Q_ASSERT(secondsUntilLanding >= 0.0);
//! \fixme In future, will we need to be able to support time offsets of zero?
BLACK_VERIFY(predictableFutureSecs != 0);
if (predictableFutureSecs == 0) { break; } // avoid divide by zero
const double takeoffFactor = secondsSinceTakeoff / significantPastSecs;
const double landingFactor = secondsUntilLanding / predictableFutureSecs;
const double airborneFactor = std::min(std::min(takeoffFactor, landingFactor), 1.0);