diff options
| author | sam-anthony <samanthony6@protonmail.com> | 2022-03-31 20:27:39 -0230 |
|---|---|---|
| committer | sam-anthony <samanthony6@protonmail.com> | 2022-03-31 20:27:39 -0230 |
| commit | 6634b3ff6bcdffbab38a049460ae6ea3cd68944f (patch) | |
| tree | 4cbcb7829060883afe074854a2ffc82b4ab2e31b /pressure.go | |
| parent | cc0d171c5cd1057693960b7f63aee29e7f70ee8e (diff) | |
| download | volute-6634b3ff6bcdffbab38a049460ae6ea3cd68944f.zip | |
refactor and compressor map image widget
Diffstat (limited to 'pressure.go')
| -rw-r--r-- | pressure.go | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/pressure.go b/pressure.go deleted file mode 100644 index a6665dc..0000000 --- a/pressure.go +++ /dev/null @@ -1,58 +0,0 @@ -package main - -import ( - "errors" - "fmt" -) - -type pressureUnit float32 - -const ( - pascal pressureUnit = 1 - kilopascal pressureUnit = 1_000 - bar pressureUnit = 100_000 - poundsPerSquareInch pressureUnit = 6_894.757 -) - -// pressureUnitStrings returns a slice of strings, each representing a -// pressureUnit. -// This is necessary because giu.Combo only works with strings. -func pressureUnitStrings() []string { - return []string{"Pa", "kPa", "bar", "psi"} -} - -const ( - defaultPressureUnit pressureUnit = kilopascal - // Used to index pressureUnitStrings - defaultPressureUnitIndex int32 = 1 // kPa -) - -func pressureUnitFromString(s string) (pressureUnit, error) { - // Each case corresponds to a value in pressureUnitStrings - switch s { - case "Pa": - return pascal, nil - case "kPa": - return kilopascal, nil - case "bar": - return bar, nil - case "psi": - return poundsPerSquareInch, nil - default: - return *new(pressureUnit), errors.New(fmt.Sprintf("invalid pressureUnit: '%s'", s)) - } -} - -type pressure struct { - val float32 - unit pressureUnit -} - -func (p pressure) asUnit(u pressureUnit) float32 { - pa := p.val * float32(p.unit) // Convert to pascals. - return pa / float32(u) // Convert to desired unit. -} - -func atmosphericPressure() pressure { - return pressure{1, bar} -} |