From 0f2cdd16dcf40e9c4b0f55ec7e0678976ce63e83 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Sat, 4 Jun 2022 13:58:33 +0200 Subject: [PATCH] Deal with negative variation times When computing plan variations, deco can get shorter when staying longer when the last step is actually already at off gasing depth. FRACTION forces unsiged, so this introduces a sign aware version of FRACTION that returns a sign character in addition. Reported-by: Patrick Naujoks Signed-off-by: Robert C. Helling --- core/units.h | 1 + qt-models/diveplannermodel.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/units.h b/core/units.h index a67f4aa6f..61d1a3e50 100644 --- a/core/units.h +++ b/core/units.h @@ -14,6 +14,7 @@ extern "C" { #endif #define FRACTION(n, x) ((unsigned)(n) / (x)), ((unsigned)(n) % (x)) +#define SIGNED_FRAC(n, x) ((n) >= 0 ? '+': '-'), ((n) >= 0 ? (unsigned)(n) / (x) : (-(n) / (x))), ((unsigned)((n) >= 0 ? (n) : -(n)) % (x)) #define O2_IN_AIR 209 // permille #define N2_IN_AIR 781 diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index b952202d3..1f77ab5ca 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -1258,9 +1258,9 @@ void DivePlannerPointsModel::computeVariations(struct diveplan *original_plan, c restore_deco_state(save, &ds, false); char buf[200]; - sprintf(buf, ", %s: + %d:%02d /%s + %d:%02d /min", qPrintable(tr("Stop times")), - FRACTION(analyzeVariations(shallower, original, deeper, qPrintable(depth_units)), 60), qPrintable(depth_units), - FRACTION(analyzeVariations(shorter, original, longer, qPrintable(time_units)), 60)); + sprintf(buf, ", %s: %c %d:%02d /%s %c %d:%02d /min", qPrintable(tr("Stop times")), + SIGNED_FRAC(analyzeVariations(shallower, original, deeper, qPrintable(depth_units)), 60), qPrintable(depth_units), + SIGNED_FRAC(analyzeVariations(shorter, original, longer, qPrintable(time_units)), 60)); // By using a signal, we can transport the variations to the main thread. emit variationsComputed(QString(buf));