module RSAGL.Math.ListUtils
(doubles,
loopedDoubles,
consecutives,
loopedConsecutives,
zeroToOne)
where
import RSAGL.Math.Types
import Debug.Trace
doubles :: [a] -> [(a,a)]
doubles [] = []
doubles [_] = []
doubles (x:y:zs) = (x,y) : doubles (y:zs)
loopedDoubles :: [a] -> [(a,a)]
loopedDoubles as = loopedDoubles_ (head as) as
where loopedDoubles_ _ [] = []
loopedDoubles_ a [x] = [(x,a)]
loopedDoubles_ a (x:y:zs) = (x,y) : loopedDoubles_ a (y:zs)
consecutives :: Int -> [a] -> [[a]]
consecutives n xs = let taken = take n xs
in if (length taken == n)
then (taken : (consecutives n $ tail xs))
else []
loopedConsecutives :: Int -> [a] -> [[a]]
loopedConsecutives n xs = consecutives n $ take (n + length xs 1) $ cycle xs
zeroToOne :: Integer -> [RSdouble]
zeroToOne n | n > 100000 = trace ("Warning: zeroToOne was asked for " ++ show n ++ " subdivisions, which seems high. Using 100,000 instead.") zeroToOne 100000
zeroToOne n = map (*x) [0..(fromInteger $ n1)]
where x = recip (fromInteger $ n 1)