[PATCH] Planner: ascent and descent rates should be rounded rather than truncated

Rick Walsh rickmwalsh at gmail.com
Mon Mar 13 00:35:38 PDT 2017


As reported on the mailing list, the ascent/descent rates are sometimes not
what is expected. E.g. setting the ascent rate to 10m/min results in an actual
ascent rate of 9m/min.  This is due to truncating the ascent rate preference,
then effectively rounding up the time to reach each stop to 2s intervals. The
result being that setting the ascent rate to 10m/min results in 20s to ascend
3m (9m/min), when it should be exactly 18s. Rounding the ascent/descent rate
(stored in mm/s), by adding + 0.5 before truncating the integer, results in
better behaviour.

Reported-by: John Smith <noseygit at hotmail.com>
Signed-off-by: Rick Walsh <rickmwalsh at gmail.com>
---
 desktop-widgets/diveplanner.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp
index 4fc38cd..bb295a9 100644
--- a/desktop-widgets/diveplanner.cpp
+++ b/desktop-widgets/diveplanner.cpp
@@ -478,27 +478,27 @@ void PlannerSettingsWidget::printDecoPlan()
 
 void PlannerSettingsWidget::setAscRate75(int rate)
 {
-	SettingsObjectWrapper::instance()->planner_settings->setAscrate75(rate * UNIT_FACTOR);
+	SettingsObjectWrapper::instance()->planner_settings->setAscrate75(rate * UNIT_FACTOR + 0.5);
 }
 
 void PlannerSettingsWidget::setAscRate50(int rate)
 {
-	SettingsObjectWrapper::instance()->planner_settings->setAscrate50(rate * UNIT_FACTOR);
+	SettingsObjectWrapper::instance()->planner_settings->setAscrate50(rate * UNIT_FACTOR + 0.5);
 }
 
 void PlannerSettingsWidget::setAscRateStops(int rate)
 {
-	SettingsObjectWrapper::instance()->planner_settings->setAscratestops(rate * UNIT_FACTOR);
+	SettingsObjectWrapper::instance()->planner_settings->setAscratestops(rate * UNIT_FACTOR + 0.5);
 }
 
 void PlannerSettingsWidget::setAscRateLast6m(int rate)
 {
-	SettingsObjectWrapper::instance()->planner_settings->setAscratelast6m(rate * UNIT_FACTOR);
+	SettingsObjectWrapper::instance()->planner_settings->setAscratelast6m(rate * UNIT_FACTOR + 0.5);
 }
 
 void PlannerSettingsWidget::setDescRate(int rate)
 {
-	SettingsObjectWrapper::instance()->planner_settings->setDescrate(rate * UNIT_FACTOR);
+	SettingsObjectWrapper::instance()->planner_settings->setDescrate(rate * UNIT_FACTOR + 0.5);
 }
 
 void PlannerSettingsWidget::sacFactorChanged(const double factor)
-- 
2.9.3



More information about the subsurface mailing list