From 406625f7074233b381c3e01de751250d05b04f9d Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 28 Jul 2024 17:59:10 +0200 Subject: fix: Fix climb finder when climb is not highest --- ride/climb.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'ride/climb.go') diff --git a/ride/climb.go b/ride/climb.go index a337a15..bf1dfc9 100644 --- a/ride/climb.go +++ b/ride/climb.go @@ -59,7 +59,7 @@ func Category(score float64) string { } } -func bestClimbUntilEnd(points []Point, start int, end int) Climb { +func bestClimbBetween(points []Point, start int, end int) Climb { kcore.Assert(end > start, "empty points") bestScore := Score(points, start, end) @@ -71,7 +71,15 @@ func bestClimbUntilEnd(points []Point, start int, end int) Climb { bestScore = score } } - climb := Climb{bestStart, end} + bestEnd := end + for i := end; i > bestStart; i-- { + score := Score(points, bestStart, i) + if score > bestScore { + bestEnd = i + bestScore = score + } + } + climb := Climb{bestStart, bestEnd} kcore.Assert(climb.start < climb.end, "empty climb") return climb @@ -84,7 +92,7 @@ func climbsBetween(points []Point, start int, end int) []Climb { } fmt.Printf("Searching climbs between %.1fkm and %.1fkm\n", points[start].distance/1000, points[end].distance/1000) highest := start - for i := start; i < end; i++ { + for i := start; i <= end; i++ { if points[i].elevation > points[highest].elevation { highest = i } @@ -93,7 +101,7 @@ func climbsBetween(points []Point, start int, end int) []Climb { if highest == start { return climbsBetween(points, start+1, end) } - climb := bestClimbUntilEnd(points, start, highest) + climb := bestClimbBetween(points, start, highest) if Score(points, climb.start, climb.end) >= 35 { fmt.Printf("Found climb between %.1fkm and %.1fkm\n", points[climb.start].distance/1000, points[climb.end].distance/1000) climbs = append(climbs, climb) -- cgit v1.2.3