Skip to content

Commit

Permalink
add meters
Browse files Browse the repository at this point in the history
  • Loading branch information
cdzombak committed Sep 2, 2023
1 parent 69bd3bf commit cab689e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions distance_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ func (mi Mile) NauticalMiles() NauticalMile {
return NauticalMile(mi / 1.15078)
}

// Meters returns the distance in meters.
func (mi Mile) Meters() Meter {
return Meter(mi * 1609.34)
}

// Miles returns the distance in miles.
func (km Km) Miles() Mile {
return Mile(km / 1.60934)
Expand All @@ -20,6 +25,11 @@ func (km Km) NauticalMiles() NauticalMile {
return NauticalMile(km / 1.852)
}

// Meters returns the distance in meters.
func (km Km) Meters() Meter {
return Meter(km * 1000)
}

// Miles returns the distance in miles.
func (nm NauticalMile) Miles() Mile {
return Mile(nm * 1.15078)
Expand All @@ -29,3 +39,23 @@ func (nm NauticalMile) Miles() Mile {
func (nm NauticalMile) Km() Km {
return Km(nm * 1.852)
}

// Meters returns the distance in meters.
func (nm NauticalMile) Meters() Meter {
return Meter(nm * 1852)
}

// Miles returns the distance in miles.
func (m Meter) Miles() Mile {
return Mile(m / 1609.34)
}

// Km returns the distance in kilometers.
func (m Meter) Km() Km {
return Km(m / 1000)
}

// NauticalMiles returns the distance in nautical miles.
func (m Meter) NauticalMiles() NauticalMile {
return NauticalMile(m / 1852)
}
4 changes: 4 additions & 0 deletions distance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package libwx
// Mile represents distance in miles.
type Mile float64

// Meter represents distance in meters.
type Meter float64

// Km represents distance in kilometers.
type Km float64

// NauticalMile represents distance in nautical miles.
type NauticalMile float64

func (mi Mile) Unwrap() float64 { return float64(mi) }
func (m Meter) Unwrap() float64 { return float64(m) }
func (km Km) Unwrap() float64 { return float64(km) }
func (nm NauticalMile) Unwrap() float64 { return float64(nm) }

0 comments on commit cab689e

Please sign in to comment.