aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-25 11:32:57 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-25 11:32:57 +0200
commit708f5428968b7c1526f257b683d0146ef5dae418 (patch)
tree8b4fb6a4e020d79c8a3e62e11defe4cbdc7a3896 /web
parentff3cd6248f2b78dc76f1ce8cc2337907188fd401 (diff)
Make mountain pass and web consumers take ride components instead of a whole Ride
rideBounds, nearestCrossing and DetectCrossings now accept the coordinate, distance and elevation component slices they read. LoadMountainPassesAroundRide takes the coords slice only. Web ride view builders and the official climb creation path iterate ride components (Coords, Distances, Elevations) rather than per-index accessors on Ride.
Diffstat (limited to 'web')
-rw-r--r--web/rides.go9
-rw-r--r--web/views.go18
2 files changed, 15 insertions, 12 deletions
diff --git a/web/rides.go b/web/rides.go
index 81017d9..71ab3fd 100644
--- a/web/rides.go
+++ b/web/rides.go
@@ -65,7 +65,7 @@ func (s *Server) handleRide(w http.ResponseWriter, r *http.Request) {
}), w)
return
}
- passes, err := mountain_pass.LoadMountainPassesAroundRide(s.db, parsed, rideDetailMountainPassMarginM)
+ passes, err := mountain_pass.LoadMountainPassesAroundRide(s.db, parsed.Coords(), rideDetailMountainPassMarginM)
if err != nil {
slog.Warn("Failed to load nearby mountain passes for ride detail", "ride_id", id, "error", err)
}
@@ -144,14 +144,15 @@ func (s *Server) handleCreateOfficialClimb(w http.ResponseWriter, r *http.Reques
http.Error(w, "the recorded route is unavailable", http.StatusBadRequest)
return
}
- if startIndex >= endIndex || endIndex >= parsed.Len() {
+ bounds := parsed.Coords()
+ if startIndex >= endIndex || endIndex >= len(bounds) {
http.Error(w, "the official climb boundaries must be ordered route points", http.StatusBadRequest)
return
}
created, err := official_climb.Create(s.db, official_climb.OfficialClimb{
Name: r.FormValue("name"),
- StartCoord: parsed.Coord(startIndex),
- EndCoord: parsed.Coord(endIndex),
+ StartCoord: bounds[startIndex],
+ EndCoord: bounds[endIndex],
})
if err != nil {
slog.Warn("Failed to create official climb", "ride_id", id, "error", err)
diff --git a/web/views.go b/web/views.go
index cfb31e5..8df860c 100644
--- a/web/views.go
+++ b/web/views.go
@@ -280,9 +280,9 @@ func officialClimbCreateURL(id int64) string {
}
func buildRideDetailView(item ride.StoredRide, parsed ride.Ride, passes []mountain_pass.MountainPass, officialClimbs []official_climb.OfficialClimb, matchPolicy official_climb.MatchPolicy) RideDetailView {
- coordinates := make([][]float64, parsed.Len())
- for i := 0; i < parsed.Len(); i++ {
- coordinate := parsed.Coord(i)
+ coords := parsed.Coords()
+ coordinates := make([][]float64, len(coords))
+ for i, coordinate := range coords {
coordinates[i] = []float64{coordinate.Lon, coordinate.Lat}
}
profile := buildRideProfile(parsed, passes, officialClimbs, matchPolicy)
@@ -321,16 +321,18 @@ func buildRideMapPasses(passes []mountain_pass.MountainPass) []RideMapPass {
}
func buildRideProfile(parsed ride.Ride, passes []mountain_pass.MountainPass, officialClimbs []official_climb.OfficialClimb, matchPolicy official_climb.MatchPolicy) RideProfile {
+ coords := parsed.Coords()
+ distances := parsed.Distances()
+ elevations := parsed.Elevations()
profile := RideProfile{
- Points: make([]RideProfilePoint, parsed.Len()),
+ Points: make([]RideProfilePoint, len(coords)),
Climbs: make([]RideProfileClimb, 0),
Crossings: make([]RideProfileCrossing, 0),
}
- for i := 0; i < parsed.Len(); i++ {
- coordinate := parsed.Coord(i)
+ for i, coordinate := range coords {
profile.Points[i] = RideProfilePoint{
- DistanceKm: parsed.DistanceM(i) / 1000,
- ElevationM: parsed.ElevationM(i),
+ DistanceKm: distances[i] / 1000,
+ ElevationM: elevations[i],
Latitude: coordinate.Lat,
Longitude: coordinate.Lon,
}