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 <p.naujoks@me.com>

Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
Robert C. Helling 2022-06-04 13:58:33 +02:00 committed by Dirk Hohndel
parent 404365c24a
commit 0f2cdd16dc
2 changed files with 4 additions and 3 deletions

View file

@ -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

View file

@ -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));