From 211731af0cfab01dd901dd6e41ed8e70c7faf162 Mon Sep 17 00:00:00 2001 From: hasufell Date: Wed, 7 Jan 2015 19:16:12 +0100 Subject: [PATCH] ALGO: add isYmonotone function --- Algorithms/PolygonTriangulation.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Algorithms/PolygonTriangulation.hs b/Algorithms/PolygonTriangulation.hs index d9c8232..a2a7732 100644 --- a/Algorithms/PolygonTriangulation.hs +++ b/Algorithms/PolygonTriangulation.hs @@ -12,7 +12,7 @@ data VCategory = VStart | VRegular | VSplit | VMerge - deriving (Show) + deriving (Show, Eq) -- |Classify all vertices on a polygon into five categories (see VCategory). @@ -108,3 +108,12 @@ above :: PT -- ^ is this one above the other? -> PT -> Bool above = flip below + + +-- |Check if polygon is y-monotone. +isYmonotone :: [PT] -> Bool +isYmonotone poly = + not + . any (\x -> x == VSplit || x == VMerge) + . fmap snd + $ classifyList poly