POLYGON: improve documentation
This commit is contained in:
parent
903ba85f9f
commit
9917a7efd3
@ -7,6 +7,8 @@ import Data.Maybe
|
|||||||
import MyPrelude
|
import MyPrelude
|
||||||
|
|
||||||
|
|
||||||
|
-- |Split a polygon by a given segment which must be vertices of the
|
||||||
|
-- polygon (returns empty array otherwise).
|
||||||
splitPoly :: [PT]
|
splitPoly :: [PT]
|
||||||
-> Segment
|
-> Segment
|
||||||
-> [[PT]]
|
-> [[PT]]
|
||||||
@ -18,6 +20,7 @@ splitPoly pts (a, b)
|
|||||||
shiftedPoly = shiftM' a pts
|
shiftedPoly = shiftM' a pts
|
||||||
|
|
||||||
|
|
||||||
|
-- |Get all edges of a polygon.
|
||||||
polySegments :: [PT] -> [Segment]
|
polySegments :: [PT] -> [Segment]
|
||||||
polySegments p@(x':_:_:_) = go p ++ [(last p, x')]
|
polySegments p@(x':_:_:_) = go p ++ [(last p, x')]
|
||||||
where
|
where
|
||||||
@ -26,6 +29,9 @@ polySegments p@(x':_:_:_) = go p ++ [(last p, x')]
|
|||||||
polySegments _ = []
|
polySegments _ = []
|
||||||
|
|
||||||
|
|
||||||
|
-- |Check whether the given segment is inside the polygon.
|
||||||
|
-- This doesn't check for segments that are completely outside
|
||||||
|
-- of the polygon yet.
|
||||||
isInsidePoly :: [PT] -> Segment -> Bool
|
isInsidePoly :: [PT] -> Segment -> Bool
|
||||||
isInsidePoly pts seg =
|
isInsidePoly pts seg =
|
||||||
null
|
null
|
||||||
@ -34,18 +40,22 @@ isInsidePoly pts seg =
|
|||||||
$ polySegments pts
|
$ polySegments pts
|
||||||
|
|
||||||
|
|
||||||
|
-- |Check whether two points are adjacent vertices of a polygon.
|
||||||
adjacent :: PT -> PT -> [PT] -> Bool
|
adjacent :: PT -> PT -> [PT] -> Bool
|
||||||
adjacent u v = any (\x -> x == (u, v) || x == (v, u)) . polySegments
|
adjacent u v = any (\x -> x == (u, v) || x == (v, u)) . polySegments
|
||||||
|
|
||||||
|
|
||||||
|
-- |Check whether the polygon is a triangle polygon.
|
||||||
isTrianglePoly :: [PT] -> Bool
|
isTrianglePoly :: [PT] -> Bool
|
||||||
isTrianglePoly [_, _, _] = True
|
isTrianglePoly [_, _, _] = True
|
||||||
isTrianglePoly _ = False
|
isTrianglePoly _ = False
|
||||||
|
|
||||||
|
|
||||||
|
-- |Get all triangle polygons.
|
||||||
triangleOnly :: [[PT]] -> [[PT]]
|
triangleOnly :: [[PT]] -> [[PT]]
|
||||||
triangleOnly = filter isTrianglePoly
|
triangleOnly = filter isTrianglePoly
|
||||||
|
|
||||||
|
|
||||||
|
-- |Get all non-triangle polygons.
|
||||||
nonTriangleOnly :: [[PT]] -> [[PT]]
|
nonTriangleOnly :: [[PT]] -> [[PT]]
|
||||||
nonTriangleOnly = filter (not . isTrianglePoly)
|
nonTriangleOnly = filter (not . isTrianglePoly)
|
||||||
|
Loading…
Reference in New Issue
Block a user