summaryrefslogtreecommitdiff
path: root/ride/climb.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2024-07-28 17:59:10 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2024-07-28 17:59:10 +0200
commit406625f7074233b381c3e01de751250d05b04f9d (patch)
tree80946d3621f875fb25501482ee9c620cf86c98e0 /ride/climb.go
parent203b9bdf17bd4742b5aab2c35df47b59af0652f1 (diff)
fix: Fix climb finder when climb is not highest
Diffstat (limited to 'ride/climb.go')
-rw-r--r--ride/climb.go16
1 files changed, 12 insertions, 4 deletions
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)