summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2017-03-10 07:22:31 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-03-11 08:03:25 -0800
commit295b1b78d888b528f7a5a23411b1a82d4b39eed1 (patch)
treee41ef5bb9fcfbdec3c536be1cb653faac047d81e
parentaf96ec5d04b09a87696b3f292bc5ad5378d26f75 (diff)
downloadsubsurface-295b1b78d888b528f7a5a23411b1a82d4b39eed1.tar.gz
Make depth conversion work for negative depths
This is needed in the altitude pressure conversion as there negative altitudes are possible (for diving in the netherlands or the Dead Sea). Signed-off-by: Robert C. Helling <helling@atdotde.de>
-rw-r--r--core/dive.c12
-rw-r--r--core/dive.h2
-rw-r--r--desktop-widgets/configuredivecomputerdialog.cpp2
-rw-r--r--desktop-widgets/diveplanner.cpp4
-rw-r--r--qt-models/diveplannermodel.cpp2
5 files changed, 13 insertions, 9 deletions
diff --git a/core/dive.c b/core/dive.c
index 48dd929f4..b091e2bc7 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -248,11 +248,15 @@ int units_to_sac(double volume)
return rint(volume * 1000);
}
-unsigned int units_to_depth(double depth)
+depth_t units_to_depth(double depth)
{
- if (get_units()->length == METERS)
- return rint(depth * 1000);
- return feet_to_mm(depth);
+ depth_t internaldepth;
+ if (get_units()->length == METERS) {
+ internaldepth.mm = rint(depth * 1000);
+ } else {
+ internaldepth.mm = feet_to_mm(depth);
+ }
+ return internaldepth;
}
double get_depth_units(int mm, int *frac, const char **units)
diff --git a/core/dive.h b/core/dive.h
index ba92e1083..194cb978c 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -131,7 +131,7 @@ extern double get_temp_units(unsigned int mk, const char **units);
extern double get_weight_units(unsigned int grams, int *frac, const char **units);
extern double get_vertical_speed_units(unsigned int mms, int *frac, const char **units);
-extern unsigned int units_to_depth(double depth);
+extern depth_t units_to_depth(double depth);
extern int units_to_sac(double volume);
/* Volume in mliter of a cylinder at pressure 'p' */
diff --git a/desktop-widgets/configuredivecomputerdialog.cpp b/desktop-widgets/configuredivecomputerdialog.cpp
index 8b3a9a5e9..f322ccdde 100644
--- a/desktop-widgets/configuredivecomputerdialog.cpp
+++ b/desktop-widgets/configuredivecomputerdialog.cpp
@@ -750,7 +750,7 @@ void ConfigureDiveComputerDialog::populateDeviceDetailsSuuntoVyper()
deviceDetails->lightEnabled = ui.lightCheckBox->isChecked();
deviceDetails->light = ui.lightSpinBox->value();
deviceDetails->alarmDepthEnabled = ui.alarmDepthCheckBox->isChecked();
- deviceDetails->alarmDepth = units_to_depth(ui.alarmDepthDoubleSpinBox->value());
+ deviceDetails->alarmDepth = units_to_depth(ui.alarmDepthDoubleSpinBox->value()).mm;
deviceDetails->alarmTimeEnabled = ui.alarmTimeCheckBox->isChecked();
deviceDetails->alarmTime = ui.alarmTimeSpinBox->value();
}
diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp
index 82b83c3ad..207d1208a 100644
--- a/desktop-widgets/diveplanner.cpp
+++ b/desktop-widgets/diveplanner.cpp
@@ -217,7 +217,7 @@ void DivePlannerWidget::atmPressureChanged(const int pressure)
void DivePlannerWidget::heightChanged(const int height)
{
- int pressure = (int) (1013.0 * exp(- (double) units_to_depth((double) height) / 7800000.0));
+ int pressure = (int) (1013.0 * exp(- (double) units_to_depth((double) height).mm / 7800000.0));
ui.ATMPressure->blockSignals(true);
ui.ATMPressure->setValue(pressure);
ui.ATMPressure->blockSignals(false);
@@ -525,7 +525,7 @@ void PlannerSettingsWidget::setDecoPo2(double po2)
void PlannerSettingsWidget::setBestmixEND(int depth)
{
- SettingsObjectWrapper::instance()->planner_settings->setBestmixend(units_to_depth(depth));
+ SettingsObjectWrapper::instance()->planner_settings->setBestmixend(units_to_depth(depth).mm);
}
void PlannerSettingsWidget::setBackgasBreaks(bool dobreaks)
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 4a33b15c3..0327a6f6f 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -288,7 +288,7 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v
switch (index.column()) {
case DEPTH:
if (value.toInt() >= 0) {
- p.depth = units_to_depth(value.toInt());
+ p.depth = units_to_depth(value.toInt()).mm;
if (updateMaxDepth())
CylindersModel::instance()->updateBestMixes();
}