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