aboutsummaryrefslogtreecommitdiff
path: root/climb
diff options
context:
space:
mode:
Diffstat (limited to 'climb')
-rw-r--r--climb/route.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/climb/route.go b/climb/route.go
index 80a9a43..4ef3465 100644
--- a/climb/route.go
+++ b/climb/route.go
@@ -7,3 +7,20 @@ type Route struct {
Elevations []float64
Coords []geodist.Coord
}
+
+// SegmentSample is a recorded passage: the length and elevation gain ridden between two route points.
+type SegmentSample struct {
+ DistanceM float64
+ ElevationGainM float64
+}
+
+// Sample returns the recorded length and elevation gain of the route slice between start and end (inclusive), counting only upward steps in the gain.
+func (route Route) Sample(start, end int) SegmentSample {
+ sample := SegmentSample{DistanceM: route.Distances[end] - route.Distances[start]}
+ for i := start + 1; i <= end; i++ {
+ if diff := route.Elevations[i] - route.Elevations[i-1]; diff > 0 {
+ sample.ElevationGainM += diff
+ }
+ }
+ return sample
+}