Add function for cutting polygons

This commit is contained in:
2026-04-14 16:37:51 +01:00
parent 431e64fbfb
commit ce8ddc6414
6 changed files with 237 additions and 163 deletions
+9
View File
@@ -4,6 +4,7 @@
{- Testing for and finding intersection points. -}
module Geometry.Intersect where
import Data.List (sortOn)
import Control.Applicative
import Control.Lens
import Control.Monad
@@ -264,6 +265,14 @@ intersectSegPolyFirst a b xs = foldr (<|>) Nothing $ zipWith lineColl xs (tail x
where
lineColl = intersectSegSeg a b
-- orders intersecting points according to the line
intersectLinePoly :: Point2 -> Point2 -> [Point2] -> [Point2]
intersectLinePoly a b (p:ps) = sortOn (dotV (b - a))
. catMaybes
$ zipWith (\x y -> intersectSegLine x y a b) (p:ps) (ps ++[p])
intersectLinePoly _ _ [] = error "intersectLinePoly empty polygon"
{- | Given a line and a point return the point on the line closest to the
point.
-}