-
Notifications
You must be signed in to change notification settings - Fork 22
/
speed.go
44 lines (36 loc) · 1.08 KB
/
speed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package unit
// Speed represents a unit of speed (in meters per second, m/s)
type Speed Unit
// ...
const (
MetersPerSecond Speed = 1e0
KilometersPerHour = MetersPerSecond * 0.277778
FeetPerSecond = MetersPerSecond * 0.3048
MilesPerHour = MetersPerSecond * 0.44704
Knot = MetersPerSecond * 0.514444
SpeedOfLight = MetersPerSecond * 299792458
)
// MetersPerSecond returns the speed in m/s
func (s Speed) MetersPerSecond() float64 {
return float64(s)
}
// KilometersPerHour returns the speed in km/h
func (s Speed) KilometersPerHour() float64 {
return float64(s / KilometersPerHour)
}
// FeetPerSecond returns the speed in ft/s
func (s Speed) FeetPerSecond() float64 {
return float64(s / FeetPerSecond)
}
// MilesPerHour returns the speed in mph
func (s Speed) MilesPerHour() float64 {
return float64(s / MilesPerHour)
}
// Knots returns the speed in knots
func (s Speed) Knots() float64 {
return float64(s / Knot)
}
// SpeedOfLight returns the speed in c
func (s Speed) SpeedOfLight() float64 {
return float64(s / SpeedOfLight)
}