From 0d488cb9ead6bd14a6982e4c5bb2dba82ae871c2 Mon Sep 17 00:00:00 2001 From: Sean Rhea Date: Fri, 25 Dec 2009 10:09:56 -0500 Subject: [PATCH] fix neg alt bug in ElevationGain metric --- src/BasicRideMetrics.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/BasicRideMetrics.cpp b/src/BasicRideMetrics.cpp index 9ee9250ba..5a716a2dd 100644 --- a/src/BasicRideMetrics.cpp +++ b/src/BasicRideMetrics.cpp @@ -126,15 +126,13 @@ class ElevationGain : public RideMetric { } void compute(const RideFile *ride, const Zones *, int, const QHash &) { + bool first = true; foreach (const RideFilePoint *point, ride->dataPoints()) { - if (prevalt <= 0) { - prevalt = point->alt; - } else if (prevalt <= point->alt) { - elegain += (point->alt-prevalt); - prevalt = point->alt; - } else { - prevalt = point->alt; - } + if (first) + first = false; + else if (point->alt > prevalt) + elegain += point->alt - prevalt; + prevalt = point->alt; } } bool canAggregate() const { return true; }