POLYGON: add polygon module

This commit is contained in:
hasufell 2015-01-08 01:41:14 +01:00
parent ddb97aa8c7
commit edd4ec38d7
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
2 changed files with 32 additions and 3 deletions

26
Algebra/Polygon.hs Normal file
View File

@ -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 _ = []

View File

@ -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