Allow generating gifs vor visualizing steps of the graham algo

TODO: this still requires us to hack on Main.hs, because
it isn't compatible with the GUI.
Also see https://github.com/diagrams/diagrams-cairo/issues/55
This commit is contained in:
2014-10-09 03:10:21 +02:00
parent 8949d05b3b
commit 1fd0b9f27f
4 changed files with 72 additions and 5 deletions

View File

@@ -64,3 +64,20 @@ grahamGetCH vs = f . grahamSort $ vs
| ccw x y z = x : f (y:z:xs)
| otherwise = f (x:z:xs)
f xs = xs
-- |Only compute steps of the graham scan algorithm to allow
-- visualizing it.
grahamGetCHSteps :: [PT] -> [[PT]]
grahamGetCHSteps vs = reverse . g $ (length . grahamGetCH $ vs)
where
vs' = grahamSort vs
g c
| c >= 0 = f 0 vs' : g (c - 1)
| otherwise = []
where
f c' (x:y:z:xs)
| c' >= c = [x,y]
| ccw x y z = x : f (c' + 1) (y:z:xs)
| otherwise = f (c' + 1) (x:z:xs)
f _ xs = xs