aboutsummaryrefslogtreecommitdiff
path: root/climb/route.go
blob: 4ef34651560bccdcbf50af6afc08f05dfdf46fa6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

package climb

import "github.com/jftuga/geodist"

type Route struct {
	Distances  []float64
	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
}