Simplify grid/lattice creation
This commit is contained in:
+2
-28
@@ -1,39 +1,20 @@
|
||||
module Dodge.Room.Path (
|
||||
gridPoints,
|
||||
linksGridToPath,
|
||||
makeGrid,
|
||||
createPathGrid,
|
||||
-- makeGrid,
|
||||
-- createPathGrid,
|
||||
gridPoints'',
|
||||
linksGridToPath',
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
import qualified Control.Foldl as L
|
||||
import Data.Function (on)
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
import qualified Data.Set as S
|
||||
import Dodge.Data.GenWorld
|
||||
import Dodge.LevelGen.StaticWalls
|
||||
import Geometry
|
||||
import Grid
|
||||
|
||||
createPathGrid :: Room -> Room
|
||||
createPathGrid rm = rm & rmPath .~ linksGridToPath (_rmLinks rm) filterGrid
|
||||
where
|
||||
filterGrid = filter
|
||||
(\p -> pairInPolys (_rmPolys rm) p && testCrossWalls outerWalls p) grid
|
||||
grid = fromMaybe [] $ shiftedGrid <$> minx <*> maxx <*> miny <*> maxy
|
||||
outerWalls = foldr cutPoly [] $ _rmPolys rm
|
||||
outerPoints = map fst outerWalls
|
||||
(minx, maxx, miny, maxy) = L.fold theFold outerPoints
|
||||
theFold =
|
||||
(,,,)
|
||||
<$> L.premap fstV2 L.minimum
|
||||
<*> L.premap fstV2 L.maximum
|
||||
<*> L.premap sndV2 L.minimum
|
||||
<*> L.premap sndV2 L.maximum
|
||||
|
||||
-- assumes subpth is symmetric
|
||||
linksGridToPath :: [RoomLink] -> [(Point2, Point2)] -> S.Set (Point2, Point2)
|
||||
linksGridToPath lnks subpth = S.fromList subpth <> foldMap (linkClosest . (^. rlPos)) lnks
|
||||
@@ -45,10 +26,3 @@ linksGridToPath' lnks subpth' = subpth <> foldMap (linkClosest . (^. rlPos)) lnk
|
||||
where
|
||||
subpth = foldMap doublePairSet subpth'
|
||||
linkClosest p = doublePairSet (p, minimumBy (compare `on` dist p) $ S.map fst subpth)
|
||||
|
||||
testCrossWalls :: [(Point2, Point2)] -> (Point2, Point2) -> Bool
|
||||
testCrossWalls wls (a, b) = not $ any (isJust . uncurry (intersectSegSeg a b)) wls
|
||||
|
||||
--extra test whether both members of the path edge are in some poly
|
||||
pairInPolys :: [[Point2]] -> (Point2, Point2) -> Bool
|
||||
pairInPolys polys (a, b) = any (pointInPoly a) polys && any (pointInPoly b) polys
|
||||
|
||||
Reference in New Issue
Block a user