Skip to content

Commit 786593c

Browse files
committed
clamp average direction degree results to (0, 360]
1 parent 11fdbf5 commit 786593c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

libwx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func HeatIndexWarningC(heatIndex TempC) HeatIndexWarning {
282282
// AvgDirectionDeg calculates the circular mean of the given set of angles (in degrees).
283283
// This is useful to find e.g. the average wind direction.
284284
func AvgDirectionDeg(degrees []Degree) Degree {
285-
return radToDeg(circularMean(degToRadSlice(clampedDegSlice(degrees)), nil))
285+
return radToDeg(circularMean(degToRadSlice(clampedDegSlice(degrees)), nil)).Clamped()
286286
}
287287

288288
// WeightedAvgDirectionDeg calculates the weighted circular mean of the given set of angles (in degrees).
@@ -291,7 +291,7 @@ func WeightedAvgDirectionDeg(degrees []Degree, weights []float64) (Degree, error
291291
if len(degrees) != len(weights) {
292292
return 0.0, ErrMismatchedInputLength
293293
}
294-
return radToDeg(circularMean(degToRadSlice(clampedDegSlice(degrees)), weights)), nil
294+
return radToDeg(circularMean(degToRadSlice(clampedDegSlice(degrees)), weights)).Clamped(), nil
295295
}
296296

297297
// StdDevDirectionDeg calculates the circular standard deviation of the given set of angles (in degrees).

0 commit comments

Comments
 (0)