From 505ced95bb868aeaf936541f26607b3c07cec639 Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 22 Mar 2026 13:41:45 +0000 Subject: [PATCH] Work towards convex partition of polygons --- src/Dodge/Room/Tutorial.hs | 23 ++++++++++++++++------- src/Geometry/Polygon.hs | 8 ++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Dodge/Room/Tutorial.hs b/src/Dodge/Room/Tutorial.hs index 701376fc5..73c3ac23b 100644 --- a/src/Dodge/Room/Tutorial.hs +++ b/src/Dodge/Room/Tutorial.hs @@ -238,10 +238,12 @@ sqPlatformChasm b a = sqSpitChasm :: Float -> Float -> ([[Point2]], [[Point2]]) sqSpitChasm b a = - ( [[ibr, obr, otr, itr], [itr, otr, otl, itl], [itl, otl, obl, ibl]] - , [[ibr, obr, otr, otl, obl, ibl, itl, itr]] + ( --[[ibr, obr, otr, itr], [itr, otr, otl, itl], [itl, otl, obl, ibl]] + convexPartition clfs + , [clfs] ) where + clfs = [ibr, obr, otr, otl, obl, ibl, itl, itr] obr = V2 a (-a) obl = V2 (-a) (-a) otl = V2 (-a) a @@ -250,6 +252,12 @@ sqSpitChasm b a = ibl = V2 (-b) (-a) itl = V2 (-b) b itr = V2 b b +-- otl---------otr +-- | itl-itr | +-- obr-ibl ibr-obl + +nonConvexChasm :: [Point2] -> PSType +nonConvexChasm ps = PutChasm [] [ps] midChasmSpit :: State LayoutVars Room midChasmSpit = do @@ -300,13 +308,14 @@ chasmSpitTerminal = do , [spanLightI (V2 0 128) (V2 300 128)] , [spanLightI (V2 300 0) (V2 0 300), sps0 $ putShape $ thinHighBar 95 0 300] ] - gh <- takeOne [55,97] + gh <- takeOne [55,75,97] gird <- takeOne [girderZ gh 30 10,girder gh 30 10,girderV gh 30 10] dec <- takeOne $ -- replicate 3 [] <> - [ - [sps0 $ putShape $ gird (V2 30 0) (V2 30 300) - ,sps0 $ putShape $ gird (V2 270 0) (V2 270 300)] - ,[sps0 $ putShape $ gird (V2 0 20) (V2 300 20)] + [--[] +-- ,[sps0 $ putShape $ gird (V2 30 0) (V2 30 300) +-- ,sps0 $ putShape $ gird (V2 270 0) (V2 270 300)] +-- ,[sps0 $ putShape $ gird (V2 0 20) (V2 300 20)] + [sps0 $ putShape $ gird (V2 0 200) (V2 300 200)] ] -- let y' = y & rmPmnts <>~ [l3, l4, l5] let y' = y & rmPmnts <>~ ls <> dec diff --git a/src/Geometry/Polygon.hs b/src/Geometry/Polygon.hs index 449ea5dcd..b6b7125ec 100644 --- a/src/Geometry/Polygon.hs +++ b/src/Geometry/Polygon.hs @@ -151,6 +151,14 @@ convexHull :: [Point2] -> [Point2] convexHull (x : y : z : xs) = grahamScan $ orderAroundFirst $ sortOn (\(V2 a b) -> (b, a)) (x : y : z : xs) convexHull _ = error "Tried to create the convex hull of two or fewer points" +-- assumes the points go "anticlockwise" around a non-self intersecting shape +convexPartition :: [Point2] -> [[Point2]] +convexPartition (x:y:z:[]) = [[x,y,z]] +convexPartition (x:y:z:xs) + | isLHS x y z = [x,y,z] : convexPartition (x:z:xs) + | otherwise = convexPartition (y:z:xs <> [x]) +convexPartition _ = error "unexpected shape for convexPartition" + {- | Creates the convex hull of a set of points. assumes no repetition of points: try nubbing! -}