Skip to content

Commit 09b2417

Browse files
Remove clamping functionality from AbsHumidity type
- Remove ClampedAbsHumidity function and Clamped() method - Remove clamping call in RelHumidityFromAbsC function - Update Test_AbsHumidity_EdgeCases to remove clamping tests - Update README to remove references to clamping for AbsHumidity - Addresses feedback from maintainer that clamping is only needed for bounded values like percentages Co-Authored-By: Chris Dzombak <chris@dzombak.com>
1 parent d91d23d commit 09b2417

4 files changed

Lines changed: 1 addition & 27 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ An [`Unwrap()`](https://pkg.go.dev/github.com/cdzombak/libwx#RelHumidity.Unwrap)
9090

9191
### Absolute humidity type and conversions
9292

93-
The [`AbsHumidity`](https://pkg.go.dev/github.com/cdzombak/libwx#AbsHumidity) type represents absolute humidity in grams per cubic meter (g/m³). A clamping [method](https://pkg.go.dev/github.com/cdzombak/libwx#AbsHumidity.Clamped) and [function](https://pkg.go.dev/github.com/cdzombak/libwx#ClampedAbsHumidity) for a reasonable atmospheric range (0-50 g/m³) are provided.
93+
The [`AbsHumidity`](https://pkg.go.dev/github.com/cdzombak/libwx#AbsHumidity) type represents absolute humidity in grams per cubic meter (g/m³).
9494

9595
An [`Unwrap()`](https://pkg.go.dev/github.com/cdzombak/libwx#AbsHumidity.Unwrap) method also exists to get the raw value as a `float64`.
9696

humidity_types.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,3 @@ func (rh RelHumidity) Clamped() RelHumidity {
2727
type AbsHumidity float64
2828

2929
func (ah AbsHumidity) Unwrap() float64 { return float64(ah) }
30-
31-
// ClampedAbsHumidity returns an AbsHumidity from the given float64, guaranteed
32-
// to be within a reasonable range (0-50 g/m³).
33-
func ClampedAbsHumidity(ah float64) AbsHumidity {
34-
return AbsHumidity(ah).Clamped()
35-
}
36-
37-
// Clamped returns an absolute humidity guaranteed to be within
38-
// a reasonable atmospheric range (0-50 g/m³).
39-
func (ah AbsHumidity) Clamped() AbsHumidity {
40-
if ah < 0 {
41-
return 0
42-
}
43-
if ah > 50 {
44-
return 50
45-
}
46-
return ah
47-
}

libwx.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@ func RelHumidityFromAbsF(temp TempF, ah AbsHumidity) RelHumidity {
347347
}
348348

349349
func RelHumidityFromAbsC(temp TempC, ah AbsHumidity) RelHumidity {
350-
ah = ah.Clamped()
351-
352350
pSat := saturationVaporPressureC(temp)
353351
if pSat == 0 {
354352
return 0

libwx_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,4 @@ func Test_AbsHumidity_EdgeCases(t *testing.T) {
206206

207207
result = AbsHumidityFromRelC(TempC(110), RelHumidity(50))
208208
r.Equal(AbsHumidity(0), result, "Should return 0 for temperature out of range")
209-
210-
ah := AbsHumidity(100).Clamped()
211-
r.Equal(AbsHumidity(50), ah, "Should clamp to maximum")
212-
213-
ah = AbsHumidity(-5).Clamped()
214-
r.Equal(AbsHumidity(0), ah, "Should clamp to minimum")
215209
}

0 commit comments

Comments
 (0)