ALGO: simplify monotoneDiagonals

This commit is contained in:
hasufell 2015-01-12 22:27:43 +01:00
parent f383cc65b2
commit ba3cfb879e
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020

View File

@ -129,16 +129,16 @@ monotoneDiagonals :: [PT] -> [(PT, PT)]
monotoneDiagonals pts = catMaybes . go $ classifyList pts monotoneDiagonals pts = catMaybes . go $ classifyList pts
where where
go (x:xs) = case snd x of go (x:xs) = case snd x of
VMerge -> getSeg (belowS (fst x) pts) (fst x) pts : go xs VMerge -> getSeg (belowS . fst $ x) (fst x) : go xs
VSplit -> getSeg (aboveS (fst x) pts) (fst x) pts : go xs VSplit -> getSeg (aboveS . fst $ x) (fst x) : go xs
_ -> [] ++ go xs _ -> [] ++ go xs
go [] = [] go [] = []
getSeg [] _ _ = Nothing getSeg [] _ = Nothing
getSeg (z:zs) pt pts' getSeg (z:zs) pt
| isInsidePoly pts (z, pt) = Just (z, pt) | isInsidePoly pts (z, pt) = Just (z, pt)
| otherwise = getSeg zs pt pts' | otherwise = getSeg zs pt
aboveS pt pts' = tail . dropWhile (/= pt) $ sortedYX pts' aboveS pt = tail . dropWhile (/= pt) $ sortedYX pts
belowS pt pts' = reverse . takeWhile (/= pt) $ sortedYX pts' belowS pt = reverse . takeWhile (/= pt) $ sortedYX pts
-- |Triangulate a y-monotone polygon. -- |Triangulate a y-monotone polygon.