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 } // Slice returns the sub-route covering the given point indices (inclusive). A route without coords // (a resampled profile) keeps them empty. func (route Route) Slice(start, end int) Route { sliced := Route{Distances: route.Distances[start : end+1], Elevations: route.Elevations[start : end+1]} if len(route.Coords) == len(route.Distances) { sliced.Coords = route.Coords[start : end+1] } return sliced } // 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 }