aboutsummaryrefslogtreecommitdiffstats
path: root/temperature.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-02-16 11:52:23 -0500
committerSam Anthony <sam@samanthony.xyz>2025-02-16 11:52:23 -0500
commit4ba873caba1d725aa72a135e4bd5fc69a9b7ef64 (patch)
tree57f7c9646b78dfa13ddfc225a5ae5b1f750ff408 /temperature.go
parent6498718bd0ea27606dc0a4e67d4a966ffe1abfdf (diff)
downloadvolute-4ba873caba1d725aa72a135e4bd5fc69a9b7ef64.zip
microui
Diffstat (limited to 'temperature.go')
-rw-r--r--temperature.go60
1 files changed, 0 insertions, 60 deletions
diff --git a/temperature.go b/temperature.go
deleted file mode 100644
index ac8cae0..0000000
--- a/temperature.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package main
-
-import (
- "errors"
- "fmt"
-)
-
-type TemperatureUnit int
-
-const (
- Celcius TemperatureUnit = iota
- Kelvin
- Fahrenheit
-)
-
-var TemperatureUnits = []string{"°C", "°K", "°F"}
-
-func ParseTemperatureUnit(s string) (TemperatureUnit, error) {
- // Each case corresponds to a value in UnitStrings().
- switch s {
- case "°C":
- return Celcius, nil
- case "°K":
- return Kelvin, nil
- case "°F":
- return Fahrenheit, nil
- default:
- return *new(TemperatureUnit), errors.New(fmt.Sprintf("invalid unit: '%s'", s))
- }
-}
-
-type Temperature struct {
- Val float32
- Unit TemperatureUnit
-}
-
-func (t Temperature) AsUnit(u TemperatureUnit) (float32, error) {
- // Convert to celcius
- var c float32
- switch t.Unit {
- case Celcius:
- c = t.Val
- case Kelvin:
- c = t.Val - 272.15
- case Fahrenheit:
- c = (t.Val - 32.0) * (5.0 / 9.0)
- }
-
- // Convert to desired unit
- switch u {
- case Celcius:
- return c, nil
- case Kelvin:
- return c + 272.15, nil
- case Fahrenheit:
- return c*(9.0/5.0) + 32.0, nil
- default:
- return 0, errors.New(fmt.Sprintf("invalid unit: '%v'", u))
- }
-}