ALGO: improve documentation

This commit is contained in:
hasufell 2015-01-09 03:58:24 +01:00
parent 54284193cd
commit 903ba85f9f
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
1 changed files with 7 additions and 1 deletions

View File

@ -98,7 +98,7 @@ isVRegular prev v next =
-- |Check if polygon is y-monotone.
-- |A polygon P is y-monotone, if it has no split and merge vertices.
isYmonotone :: [PT] -> Bool
isYmonotone poly =
not
@ -107,6 +107,7 @@ isYmonotone poly =
$ classifyList poly
-- |Partition P in y-monotone pieces.
monotonePartitioning :: [PT] -> [[PT]]
monotonePartitioning pts
| isYmonotone pts = [pts]
@ -119,6 +120,9 @@ monotonePartitioning pts
(monotoneDiagonals pts)
-- |Try to eliminate the merge and split vertices by computing the
-- diagonals we have to use for splitting the polygon. This doesn't
-- necessarily make our polygon y-monotone yet.
monotoneDiagonals :: [PT] -> [(PT, PT)]
monotoneDiagonals pts = catMaybes . go $ classifyList pts
where
@ -135,6 +139,8 @@ monotoneDiagonals pts = catMaybes . go $ classifyList pts
belowS pt pts' = reverse . takeWhile (/= pt) $ sortedYX pts'
-- |A simple polygon with n vertices can be partitioned into y-monotone pieces
-- in O(n log n).
triangulate :: [PT] -> [[PT]]
triangulate pts =
go pts . A.first reverse . splitAt 3 . reverse . sortedYX $ pts