Skip to content

Commit

Permalink
Switch from String to Int for altitude, #249.
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Mar 16, 2019
1 parent 679a30b commit e3356cb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
4 changes: 2 additions & 2 deletions igc/library/Flight/Igc/Parse.hs
Expand Up @@ -77,7 +77,7 @@ lng = do
-- -1m
altBaro :: ParsecT Void String Identity AltBaro
altBaro =
AltBaro . Altitude
AltBaro . Altitude . read
<$>
( count 5 digitChar
<|> (char '-' >> (("-" ++) <$> count 4 digitChar))
Expand All @@ -97,7 +97,7 @@ altBaro =
-- -1m
altGps :: ParsecT Void String Identity AltGps
altGps =
AltGps . Altitude
AltGps . Altitude . read
<$>
( count 5 digitChar
<|> (char '-' >> (("-" ++) <$> count 4 digitChar))
Expand Down
18 changes: 4 additions & 14 deletions igc/library/Flight/Igc/Record.hs
Expand Up @@ -27,8 +27,8 @@ import Text.Printf (printf)
import Data.List (partition)
import Test.Tasty.QuickCheck (Arbitrary(..), frequency, oneof)

-- | An altitude in metres
newtype Altitude = Altitude String
-- | An altitude in metres.
newtype Altitude = Altitude Int
deriving (Eq, Ord)

-- | An hour of time.
Expand Down Expand Up @@ -273,16 +273,6 @@ showLng (LngW d m) =
showLng (LngE d m) =
showDegreeOfLng d ++ " " ++ showMinute m ++ " E"

ltrimZero :: String -> String
ltrimZero ('-' : s) =
case '-' : ltrimZero s of
"-0" -> "0"
s' -> s'
ltrimZero s =
case dropWhile ('0' ==) s of
"" -> "0"
s' -> s'

instance Show HMS where
show = showHMS

Expand All @@ -293,10 +283,10 @@ instance Show Lng where
show = showLng

instance Show AltBaro where
show (AltBaro (Altitude x)) = ltrimZero x ++ "m"
show (AltBaro (Altitude x)) = show x ++ "m"

instance Show AltGps where
show (AltGps (Altitude x)) = ltrimZero x ++ "m"
show (AltGps (Altitude x)) = show x ++ "m"

showIgc :: [ IgcRecord ] -> String
showIgc xs =
Expand Down
4 changes: 2 additions & 2 deletions track/library/Flight/TrackLog.hs
Expand Up @@ -240,7 +240,7 @@ readLng (LngE d m) = K.Longitude $ readDegMin d m
readLng (LngW d m) = K.Longitude . negate $ readDegMin d m

readAltBaro :: AltBaro -> K.Altitude
readAltBaro (AltBaro (Altitude alt)) = K.Altitude (read alt :: Integer)
readAltBaro (AltBaro (Altitude alt)) = K.Altitude $ fromIntegral alt

readAltGps :: AltGps -> K.Altitude
readAltGps (AltGps (Altitude alt)) = K.Altitude (read alt :: Integer)
readAltGps (AltGps (Altitude alt)) = K.Altitude $ fromIntegral alt

0 comments on commit e3356cb

Please sign in to comment.