(distM float32)
| 142 | } |
| 143 | |
| 144 | func (u UnitSystem) Distance(distM float32) (res float32, unit string) { |
| 145 | if u == UnitsMetric || u == UnitsSi || u == UnitsMetricMs { |
| 146 | if distM < 1 { |
| 147 | return distM * 1000, "mm" |
| 148 | } else if distM < 1000 { |
| 149 | return distM, "m" |
| 150 | } else { |
| 151 | return distM / 1000, "km" |
| 152 | } |
| 153 | } else if u == UnitsImperial { |
| 154 | res, unit = distM/0.0254, "in" |
| 155 | if res < 3*12 { // 1yd = 3ft, 1ft = 12in |
| 156 | return |
| 157 | } else if res < 8*10*22*36 { //1mi = 8fur, 1fur = 10ch, 1ch = 22yd |
| 158 | return res / 36, "yd" |
| 159 | } else { |
| 160 | return res / 8 / 10 / 22 / 36, "mi" |
| 161 | } |
| 162 | } |
| 163 | log.Fatalln("Unknown unit system:", u) |
| 164 | return |
| 165 | } |
| 166 | |
| 167 | type Backend interface { |
| 168 | Setup() |
no outgoing calls
no test coverage detected