aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-09-25 08:57:10 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-09-25 08:57:10 +0200
commit0eadc1fde03153ff4b60655f15ed86367dc6a3d3 (patch)
tree00e8f42b983b665992a514bc715d92a96b4331c7
parent077aa1700fbcaf3f499c2178e0e58e89ae9dcaf8 (diff)
Apply go fix modernizations
Embedded composite literals and min/max clamp idioms, as rewritten by the go fix step of mise check.
-rw-r--r--official_climb/aggregate_test.go5
-rw-r--r--ride/elevation_outlier.go8
-rw-r--r--ride/fit.go20
3 files changed, 9 insertions, 24 deletions
diff --git a/official_climb/aggregate_test.go b/official_climb/aggregate_test.go
index 2e051ce..7149494 100644
--- a/official_climb/aggregate_test.go
+++ b/official_climb/aggregate_test.go
@@ -49,10 +49,9 @@ func TestAggregateAttemptsEmpty(t *testing.T) {
}
func TestNormalizeProfileLinearSegment(t *testing.T) {
- segment := climb.Climb{Route: climb.Route{
+ segment := climb.Climb{
Distances: []float64{0, 500, 1000},
- Elevations: []float64{100, 150, 200},
- }}
+ Elevations: []float64{100, 150, 200}}
samples := NormalizeProfile(segment)
require.Len(t, samples, profileSteps)
assert.InDelta(t, 100, samples[0], 0.01)
diff --git a/ride/elevation_outlier.go b/ride/elevation_outlier.go
index aa4c7ab..76896cd 100644
--- a/ride/elevation_outlier.go
+++ b/ride/elevation_outlier.go
@@ -231,11 +231,9 @@ func EncodeGPX(r Ride, w io.Writer) error {
}
for i := 0; i < r.Len(); i++ {
segment.Points[i] = gpx.GPXPoint{
- Point: gpx.Point{
- Latitude: r.Coords[i].Lat,
- Longitude: r.Coords[i].Lon,
- Elevation: *gpx.NewNullableFloat64(r.Elevations[i]),
- },
+ Latitude: r.Coords[i].Lat,
+ Longitude: r.Coords[i].Lon,
+ Elevation: *gpx.NewNullableFloat64(r.Elevations[i]),
Timestamp: r.timestamps[i],
}
}
diff --git a/ride/fit.go b/ride/fit.go
index 760cec1..db9c0b6 100644
--- a/ride/fit.go
+++ b/ride/fit.go
@@ -157,36 +157,24 @@ func EncodeFIT(ride Ride, w io.Writer) error {
rec.PositionLong = fit.NewLongitudeDegrees(coord.Lon)
// Altitude: scaled (value+500)*5, invalid 0xFFFF
elev := ride.Elevations[i]
- scaled := max(int((elev+500)*5), 0)
- if scaled > 0xFFFE {
- scaled = 0xFFFE
- }
+ scaled := min(max(int((elev+500)*5), 0), 0xFFFE)
rec.Altitude = uint16(scaled)
rec.EnhancedAltitude = 0xFFFFFFFF
if hasHR {
- v := max(int(heartRates[i]), 0)
- if v > 254 {
- v = 254
- }
+ v := min(max(int(heartRates[i]), 0), 254)
rec.HeartRate = uint8(v)
} else {
rec.HeartRate = 0xFF
}
if hasCad {
- v := max(int(cadences[i]), 0)
- if v > 254 {
- v = 254
- }
+ v := min(max(int(cadences[i]), 0), 254)
rec.Cadence = uint8(v)
} else {
rec.Cadence = 0xFF
}
if hasPower {
- v := max(int(powers[i]), 0)
- if v > 65534 {
- v = 65534
- }
+ v := min(max(int(powers[i]), 0), 65534)
rec.Power = uint16(v)
} else {
rec.Power = 0xFFFF