-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjerk.go
48 lines (38 loc) · 1.11 KB
/
jerk.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
45
46
47
48
package unit
import (
"encoding"
"fmt"
)
// Jerk is the rate at which an object's acceleration changes with respect to time.
type Jerk float64
var _ encoding.TextUnmarshaler = (*Jerk)(nil)
// MeterPerSecondCubed is the SI unit for measuring Jerk.
const MeterPerSecondCubed Jerk = 1.0
const metersPerSecondCubedSymbol = "m/s³"
// MetersPerSecondCubed returns j with the unit of m/s³.
func (j Jerk) MetersPerSecondCubed() float64 {
return float64(j)
}
// Get returns j with the unit of as.
func (j Jerk) Get(as Jerk) float64 {
return float64(j) / float64(as)
}
// String implements fmt.Stringer.
func (j Jerk) String() string {
return format(float64(j), metersPerSecondCubedSymbol)
}
// UnmarshalString sets *j from s.
func (j *Jerk) UnmarshalString(s string) error {
parsed, err := parse(s, map[string]float64{
metersPerSecondCubedSymbol: float64(MeterPerSecondCubed),
})
if err != nil {
return fmt.Errorf("unmarshal jerk: %w", err)
}
*j = Jerk(parsed)
return nil
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (j *Jerk) UnmarshalText(text []byte) error {
return j.UnmarshalString(string(text))
}