aboutsummaryrefslogtreecommitdiffstats
path: root/pressure
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2022-05-04 22:52:06 -0230
committerSam Anthony <sam@samanthony.xyz>2022-05-04 22:52:06 -0230
commitb94fef3b581133ddf6807d113422062acafde717 (patch)
tree52ff762e5af9a59d7f836a4c9c47d568e735bf8b /pressure
parentbb8d0c77cbd620ccc7521961df59c1f2f812125b (diff)
downloadvolute-b94fef3b581133ddf6807d113422062acafde717.zip
improve unit conversions
Diffstat (limited to 'pressure')
-rw-r--r--pressure/pressure.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/pressure/pressure.go b/pressure/pressure.go
index 2948c72..b3063cc 100644
--- a/pressure/pressure.go
+++ b/pressure/pressure.go
@@ -44,15 +44,17 @@ func UnitFromString(s string) (unit, error) {
}
type Pressure struct {
- Val float32
- Unit unit
+ val float32
+}
+
+func New(i float32, u unit) Pressure {
+ return Pressure{i * float32(u)}
}
func (p Pressure) AsUnit(u unit) float32 {
- pa := p.Val * float32(p.Unit) // Convert to pascals.
- return pa / float32(u) // Convert to desired unit.
+ return p.val / float32(u)
}
func Atmospheric() Pressure {
- return Pressure{1, Bar}
+ return Pressure{float32(1 * Bar)}
}