From b2ce6fa1654536488ac3a375806a86b1cb386501 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Sat, 16 Mar 2019 12:45:47 -0400 Subject: [PATCH] Switch from String to Int for degree, #249. --- igc/library/Flight/Igc/Parse.hs | 4 ++-- igc/library/Flight/Igc/Record.hs | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/igc/library/Flight/Igc/Parse.hs b/igc/library/Flight/Igc/Parse.hs index 1c317a859..7fcbb1d41 100644 --- a/igc/library/Flight/Igc/Parse.hs +++ b/igc/library/Flight/Igc/Parse.hs @@ -48,7 +48,7 @@ timeHHMMSS = do -- 33° 21.354' S lat :: ParsecT Void String Identity Lat lat = do - degs <- Degree <$> count 2 digitChar + degs <- Degree . read <$> count 2 digitChar mins <- Minute <$> count 5 digitChar f <- const LatN <$> char 'N' <|> const LatS <$> char 'S' return $ f degs mins @@ -58,7 +58,7 @@ lat = do -- 147° 56.057' E lng :: ParsecT Void String Identity Lng lng = do - degs <- Degree <$> count 3 digitChar + degs <- Degree . read <$> count 3 digitChar mins <- Minute <$> count 5 digitChar f <- const LngW <$> char 'W' <|> const LngE <$> char 'E' return $ f degs mins diff --git a/igc/library/Flight/Igc/Record.hs b/igc/library/Flight/Igc/Record.hs index 3acaec57c..2fd3249c3 100644 --- a/igc/library/Flight/Igc/Record.hs +++ b/igc/library/Flight/Igc/Record.hs @@ -45,7 +45,7 @@ newtype Second = Second Int deriving (Eq, Ord) -- | A whole degree of angle. May have leading zeros. Has no decimal part. -newtype Degree = Degree String +newtype Degree = Degree Int deriving (Eq, Ord) -- | A time with hours, minutes and seconds. @@ -240,28 +240,31 @@ addHoursIgc :: Hour -> IgcRecord -> IgcRecord addHoursIgc h x@B{hms} = x{hms = addHoursHms h hms} addHoursIgc _ x = x -showDegree :: String -> String -showDegree d = d ++ "°" +showDegreeOfLat :: Degree -> String +showDegreeOfLat (Degree d) = printf "%02d°" d + +showDegreeOfLng :: Degree -> String +showDegreeOfLng (Degree d) = printf "%03d°" d showMinute :: String -> String showMinute (m0 : m1 : m) = [m0, m1] ++ "." ++ m ++ "'" -showMinute m = m +showMinute m = m showHMS :: HMS -> String showHMS (HMS (Hour hh) (Minute mm) (Second ss)) = printf "%02d:%02d:%02d" hh (read mm :: Int) ss showLat :: Lat -> String -showLat (LatN (Degree d) (Minute m)) = - showDegree d ++ " " ++ showMinute m ++ " N" -showLat (LatS (Degree d) (Minute m)) = - showDegree d ++ " " ++ showMinute m ++ " S" +showLat (LatN d (Minute m)) = + showDegreeOfLat d ++ " " ++ showMinute m ++ " N" +showLat (LatS d (Minute m)) = + showDegreeOfLat d ++ " " ++ showMinute m ++ " S" showLng :: Lng -> String -showLng (LngW (Degree d) (Minute m)) = - showDegree d ++ " " ++ showMinute m ++ " W" -showLng (LngE (Degree d) (Minute m)) = - showDegree d ++ " " ++ showMinute m ++ " E" +showLng (LngW d (Minute m)) = + showDegreeOfLng d ++ " " ++ showMinute m ++ " W" +showLng (LngE d (Minute m)) = + showDegreeOfLng d ++ " " ++ showMinute m ++ " E" ltrimZero :: String -> String ltrimZero ('-' : s) =