2014-09-30 22:05:29 +00:00
|
|
|
module Util where
|
|
|
|
|
|
|
|
|
|
|
|
-- |Checks whether the Coordinates are in a given range.
|
2014-10-01 18:17:59 +00:00
|
|
|
inRange :: Double -- ^ min
|
2014-09-30 22:05:29 +00:00
|
|
|
-> Double -- ^ max
|
2014-10-01 18:17:59 +00:00
|
|
|
-> (Double, Double) -- ^ Coordinates to check
|
2014-09-30 22:05:29 +00:00
|
|
|
-> Bool -- ^ result
|
2014-10-01 18:17:59 +00:00
|
|
|
inRange min' max' (x, y)
|
2014-09-30 22:05:29 +00:00
|
|
|
| x <= max' && x >= min' && y <= max' && y >= min' = True
|
|
|
|
| otherwise = False
|
|
|
|
|
|
|
|
|
2014-10-01 21:02:43 +00:00
|
|
|
-- |Compare the extension of a file with the given String.
|
2014-10-01 18:18:45 +00:00
|
|
|
cmpExt :: String -> FilePath -> Bool
|
|
|
|
cmpExt _ [] = False
|
2014-10-01 21:03:09 +00:00
|
|
|
cmpExt checkExt fp
|
|
|
|
| actualExt == fp = False
|
|
|
|
| otherwise = checkExt == actualExt
|
|
|
|
where
|
|
|
|
actualExt = getExt fp
|
2014-10-01 18:18:45 +00:00
|
|
|
|
|
|
|
|
2014-10-01 21:02:43 +00:00
|
|
|
-- |Get the extension of a file.
|
2014-10-01 18:18:45 +00:00
|
|
|
getExt :: FilePath -> String
|
|
|
|
getExt = last .
|
|
|
|
splitBy (== '.') .
|
|
|
|
last .
|
|
|
|
splitBy (== '/')
|
|
|
|
|
|
|
|
|
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
|
2014-10-01 18:18:45 +00:00
|
|
|
splitBy f s = case dropWhile f s of
|
|
|
|
[] -> []
|
|
|
|
s' -> w : splitBy f s''
|
|
|
|
where (w, s'') = break f s'
|