From c96474e6fd39f2a9e3ae3b2b7efd0375e269f117 Mon Sep 17 00:00:00 2001 From: hasufell Date: Fri, 9 Jan 2015 03:20:13 +0100 Subject: [PATCH] ALGO: use isInsidePoly --- Algebra/Polygon.hs | 9 +++++++++ Algorithms/PolygonTriangulation.hs | 6 +----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Algebra/Polygon.hs b/Algebra/Polygon.hs index 46f629e..70f1421 100644 --- a/Algebra/Polygon.hs +++ b/Algebra/Polygon.hs @@ -24,3 +24,12 @@ polySegments p@(x':_:_:_) = go p ++ [(last p, x')] go (x:y:xs) = (x, y) : go (y:xs) go _ = [] polySegments _ = [] + + +isInsidePoly :: [PT] -> Segment -> Bool +isInsidePoly pts seg = + null + . catMaybes + . fmap (intersectSeg'' seg) + $ polySegments pts + diff --git a/Algorithms/PolygonTriangulation.hs b/Algorithms/PolygonTriangulation.hs index 91e1e50..ffd3142 100644 --- a/Algorithms/PolygonTriangulation.hs +++ b/Algorithms/PolygonTriangulation.hs @@ -131,11 +131,7 @@ monotoneDiagonals pts = catMaybes . go $ classifyList pts go [] = [] getSeg [] _ _ = Nothing getSeg (z:zs) pt pts' - | null - . catMaybes - . fmap (intersectSeg'' (z, pt)) - $ polySegments pts - = Just (z, pt) + | isInsidePoly pts (z, pt) = Just (z, pt) | otherwise = getSeg zs pt pts' aboveS pt pts' = tail . dropWhile (/= pt) $ sortedYX pts' belowS pt pts' = reverse . takeWhile (/= pt) $ sortedYX pts'