This repository was archived by the owner on Dec 2, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
main/kotlin/be/yellowduck/gpx
test/kotlin/be/yellowduck/gpx Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,23 @@ data class Segment(
2525 return Distance (distance)
2626 }
2727
28+ /* *
29+ * Returns the total elevation gain of the segment
30+ */
31+ val elevationGain: Double
32+ get() {
33+ var total = 0.0
34+ points.forEachIndexed { index, point ->
35+ if (index > 0 ) {
36+ val ele = points[index].ele - points[index - 1 ].ele
37+ if (ele > 0 ) {
38+ total + = ele
39+ }
40+ }
41+ }
42+ return total
43+ }
44+
2845 /* *
2946 * Returns the segment as an encoded polyline string.
3047 *
Original file line number Diff line number Diff line change @@ -21,6 +21,14 @@ data class Track(
2121 return Distance (segments.sumOf { it.distance.meters })
2222 }
2323
24+ /* *
25+ * Returns the total elevation gain of the track
26+ */
27+ val elevationGain: Double
28+ get() {
29+ return segments.sumOf { it.elevationGain }
30+ }
31+
2432 /* *
2533 * Returns the segment as an encoded polyline string.
2634 *
Original file line number Diff line number Diff line change 1+ package be.yellowduck.gpx
2+
3+ import org.assertj.core.api.Assertions.assertThat
4+ import org.junit.jupiter.api.Test
5+
6+ class TrackTests {
7+ @Test
8+ fun testElevationGain () {
9+ val path = " src/test/resources/Gravelgrinders_Gent_4.gpx"
10+ val gpx = GPX .parse(path)
11+ assertThat(gpx.tracks.firstOrNull()?.elevationGain).isEqualTo(469.7999999999836 )
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments