From edd4ec38d73b5a2256cc2ced4eb6ba664151baab Mon Sep 17 00:00:00 2001 From: hasufell Date: Thu, 8 Jan 2015 01:41:14 +0100 Subject: [PATCH] POLYGON: add polygon module --- Algebra/Polygon.hs | 26 ++++++++++++++++++++++++++ CG2.cabal | 9 ++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 Algebra/Polygon.hs diff --git a/Algebra/Polygon.hs b/Algebra/Polygon.hs new file mode 100644 index 0000000..46f629e --- /dev/null +++ b/Algebra/Polygon.hs @@ -0,0 +1,26 @@ +{-# OPTIONS_HADDOCK ignore-exports #-} + +module Algebra.Polygon where + +import Algebra.Vector +import MyPrelude +{- import Diagrams.Coordinates -} + + +splitPoly :: [PT] + -> Segment + -> [[PT]] +splitPoly pts (a, b) + | elem a pts && elem b pts = + [b : takeWhile (/= b) shiftedPoly, a : dropWhile (/= b) shiftedPoly] + | otherwise = [[]] + where + shiftedPoly = shiftM' a pts + + +polySegments :: [PT] -> [Segment] +polySegments p@(x':_:_:_) = go p ++ [(last p, x')] + where + go (x:y:xs) = (x, y) : go (y:xs) + go _ = [] +polySegments _ = [] diff --git a/CG2.cabal b/CG2.cabal index 6b580f3..99400e4 100644 --- a/CG2.cabal +++ b/CG2.cabal @@ -54,7 +54,8 @@ executable Gtk main-is: GtkMain.hs -- Modules included in this executable, other than Main. - other-modules: Algebra.Vector + other-modules: Algebra.Polygon + Algebra.Vector Algorithms.GrahamScan Algorithms.PolygonIntersection Algorithms.PolygonTriangulation @@ -103,7 +104,8 @@ executable Gif main-is: GifMain.hs -- Modules included in this executable, other than Main. - other-modules: Algebra.Vector + other-modules: Algebra.Polygon + Algebra.Vector Algorithms.GrahamScan Algorithms.PolygonIntersection Algorithms.PolygonTriangulation @@ -149,7 +151,8 @@ executable Test main-is: TestMain.hs -- Modules included in this executable, other than Main. - other-modules: Algebra.Vector + other-modules: Algebra.Polygon + Algebra.Vector Algorithms.GrahamScan Algorithms.PolygonIntersection Algorithms.PolygonTriangulation