gps 0.6.2 → 0.7
raw patch · 2 files changed
+39/−37 lines, 2 files
Files
- Data/GPS.hs +38/−36
- gps.cabal +1/−1
Data/GPS.hs view
@@ -4,36 +4,36 @@ -- are in meters and time is in seconds. Speed is thus meters/second module Data.GPS- ( -- * Types- Distance- , Heading- , Speed- , Vector- , Trail- -- * Constants- , north- , south- , east- , west- , radiusOfEarth- -- * Coordinate Functions- , heading- , distance- , speed- , addVector- , getRadianPair- , getDMSPair- , divideArea- -- * Trail Functions- , totalDistance- , restLocations- , closestDistance- , filterByMaxSpeed- , convexHull- -- * Other helpers- , readGPX- , module Data.Geo.GPX- ) where+ ( -- * Types+ Distance+ , Heading+ , Speed+ , Vector+ , Trail+ -- * Constants+ , north+ , south+ , east+ , west+ , radiusOfEarth+ -- * Coordinate Functions+ , heading+ , distance+ , speed+ , addVector+ , getRadianPair+ , getDMSPair+ , divideArea+ -- * Trail Functions+ , totalDistance+ , restLocations+ , closestDistance+ , filterByMaxSpeed+ , convexHull+ -- * Other helpers+ , readGPX+ , module Data.Geo.GPX+ ) where import Data.Function (on) import Data.Ord (comparing)@@ -69,7 +69,7 @@ distance :: (Lat a, Lon a, Lat b, Lon b) => a -> b -> Distance distance a b =- let x = sin lat1 * sin lat2 + cos lat1 * cos lat2 * cos (lon2 - lon1)+ let x = sin lat1 * sin lat2 + cos lat1 * cos lat2 * cos (lon2 - lon1) x' = if x > 1 then 1 else x in radiusOfEarth * acos x' where@@ -96,12 +96,14 @@ -- | Speed in meters per second, only if a 'Time' was recorded for each waypoint. speed :: (Lat loc, Lon loc, Time loc, Lat b, Lon b, Time b) => loc -> b -> Maybe Speed speed a b = - case (getUTCTime b, getUTCTime a) of- (Just x, Just y) -> Just $ realToFrac (diffUTCTime x y) / (distance a b)- _ -> Nothing+ case (getUTCTime b, getUTCTime a) of+ (Just x, Just y) -> + let timeDiff = realToFrac (diffUTCTime x y)+ in if timeDiff == 0 then Nothing else Just $ (distance a b) / timeDiff+ _ -> Nothing --- |Filter out all points that result in a speed greater than a given value--- (the second point is dropped)+-- |Filter out all points that result in a speed greater than a given+-- value (the second point is dropped) filterByMaxSpeed :: (Lat loc, Lon loc, Time loc) => Speed -> Trail loc -> Trail loc filterByMaxSpeed mx xs = let ss = zipWith speed xs (drop 1 xs)
gps.cabal view
@@ -1,5 +1,5 @@ name: gps-version: 0.6.2+version: 0.7 license: BSD3 license-file: LICENSE author: Thomas DuBuisson <thomas.dubuisson@gmail.com>