cga/Util.hs

48 lines
1.2 KiB
Haskell
Raw Normal View History

{-# OPTIONS_HADDOCK ignore-exports #-}
2014-09-30 22:05:29 +00:00
module Util where
2014-10-05 16:09:24 +00:00
-- |Checks whether the Coordinates are in a given dimension.
inRange :: (Double, Double) -- ^ X dimension
-> (Double, Double) -- ^ Y dimension
-> (Double, Double) -- ^ Coordinates
2014-09-30 22:05:29 +00:00
-> Bool -- ^ result
2014-10-05 16:09:24 +00:00
inRange (xlD, xuD) (ylD, yuD) (x,y)
| x <= xuD && x >= xlD &&
y <= yuD && y >= ylD = True
| otherwise = False
2014-09-30 22:05:29 +00:00
2014-10-01 21:02:43 +00:00
-- |Compare the extension of a file with the given String.
cmpExt :: String -> FilePath -> Bool
cmpExt checkExt = (==) checkExt . getExt
2014-10-01 21:02:43 +00:00
-- |Get the extension of a file.
getExt :: FilePath -> String
getExt fp
| hasExt fp = last .
splitBy (== '.') .
last .
splitBy (== '/') $
fp
| otherwise = ""
-- |Check if the file has an extension.
hasExt :: FilePath -> Bool
hasExt fp
| (<= 1) . length . splitBy (== '.') $ fp = False
| otherwise = True
2014-10-01 21:02:43 +00:00
-- |Split an array into subarrays depending on a given condition.
splitBy :: (a -> Bool) -- ^ condition
-> [a] -- ^ array to split
-> [[a]] -- ^ splitted array
splitBy f s = case dropWhile f s of
[] -> []
s' -> w : splitBy f s''
where (w, s'') = break f s'