From f383cc65b2807303826ab46383f511a55cae209e Mon Sep 17 00:00:00 2001 From: hasufell Date: Mon, 12 Jan 2015 22:27:17 +0100 Subject: [PATCH] ALGO: rewrite monotonePartitioning to avoid polygon duplicates --- Algorithms/PolygonTriangulation.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Algorithms/PolygonTriangulation.hs b/Algorithms/PolygonTriangulation.hs index 376860c..cea7ec1 100644 --- a/Algorithms/PolygonTriangulation.hs +++ b/Algorithms/PolygonTriangulation.hs @@ -5,7 +5,6 @@ module Algorithms.PolygonTriangulation where import Algebra.Polygon import Algebra.Vector import qualified Control.Arrow as A -import Data.List import Data.Maybe import Safe @@ -111,13 +110,16 @@ isYmonotone poly = monotonePartitioning :: [PT] -> [[PT]] monotonePartitioning pts | isYmonotone pts = [pts] - | and . fmap isYmonotone $ maybeMonotone = maybeMonotone - | otherwise = (\(x, y) -> x ++ (concat . fmap monotonePartitioning $ y)) - (partition isYmonotone maybeMonotone) + | otherwise = go (monotoneDiagonals pts) pts where - maybeMonotone = foldr (\x y -> splitPoly pts x ++ y) - [] - (monotoneDiagonals pts) + go [] _ = [[]] + go _ [] = [[]] + go (x:xs) pts' + | isYmonotone a && isYmonotone b = [a, b] + | isYmonotone b = b : go xs a + | otherwise = a : go xs b + where + [a, b] = splitPoly pts' x -- |Try to eliminate the merge and split vertices by computing the