github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/unit/velocity.go (about) 1 // Code generated by "go generate github.com/jingcheng-WU/gonum/unit”; DO NOT EDIT. 2 3 // Copyright ©2014 The Gonum Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 package unit 8 9 import ( 10 "errors" 11 "fmt" 12 "math" 13 "unicode/utf8" 14 ) 15 16 // Velocity represents a velocity in metres per second. 17 type Velocity float64 18 19 // Unit converts the Velocity to a *Unit. 20 func (v Velocity) Unit() *Unit { 21 return New(float64(v), Dimensions{ 22 LengthDim: 1, 23 TimeDim: -1, 24 }) 25 } 26 27 // Velocity allows Velocity to implement a Velocityer interface. 28 func (v Velocity) Velocity() Velocity { 29 return v 30 } 31 32 // From converts the unit into the receiver. From returns an 33 // error if there is a mismatch in dimension. 34 func (v *Velocity) From(u Uniter) error { 35 if !DimensionsMatch(u, Velocity(0)) { 36 *v = Velocity(math.NaN()) 37 return errors.New("unit: dimension mismatch") 38 } 39 *v = Velocity(u.Unit().Value()) 40 return nil 41 } 42 43 func (v Velocity) Format(fs fmt.State, c rune) { 44 switch c { 45 case 'v': 46 if fs.Flag('#') { 47 fmt.Fprintf(fs, "%T(%v)", v, float64(v)) 48 return 49 } 50 fallthrough 51 case 'e', 'E', 'f', 'F', 'g', 'G': 52 p, pOk := fs.Precision() 53 w, wOk := fs.Width() 54 const unit = " m s^-1" 55 switch { 56 case pOk && wOk: 57 fmt.Fprintf(fs, "%*.*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), p, float64(v)) 58 case pOk: 59 fmt.Fprintf(fs, "%.*"+string(c), p, float64(v)) 60 case wOk: 61 fmt.Fprintf(fs, "%*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), float64(v)) 62 default: 63 fmt.Fprintf(fs, "%"+string(c), float64(v)) 64 } 65 fmt.Fprint(fs, unit) 66 default: 67 fmt.Fprintf(fs, "%%!%c(%T=%g m s^-1)", c, v, float64(v)) 68 } 69 }