Add check for negative number of iterations

This commit is contained in:
Dimitri Lozeve 2018-01-17 17:13:53 +00:00
parent 60b9596b53
commit e71eda7c5e

View file

@ -43,6 +43,7 @@ iterateLSystem :: (Eq a, Integral t) => t -> LSystem a -> LSystem a
iterateLSystem 0 lsystem = lsystem iterateLSystem 0 lsystem = lsystem
iterateLSystem n (LSystem a ax r ang dist rep) = iterateLSystem n (LSystem a ax r ang dist rep) =
iterateLSystem (n-1) $ LSystem a ax' r ang dist rep iterateLSystem (n-1) $ LSystem a ax' r ang dist rep
iterateLSystem n lsystem | n < 0 = iterateLSystem (-n) lsystem
where ax' = concat $ map f ax where ax' = concat $ map f ax
f x = case lookup x r of f x = case lookup x r of
Just xs -> xs Just xs -> xs