Simplify room link functions
This commit is contained in:
+11
-7
@@ -1,12 +1,12 @@
|
||||
module Dodge.Room.Path (
|
||||
gridPoints,
|
||||
linksAndPath,
|
||||
linksAndPath',
|
||||
makeGrid,
|
||||
createPathGrid,
|
||||
gridPoints'',
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
import qualified Control.Foldl as L
|
||||
import Data.Function (on)
|
||||
import Data.List
|
||||
@@ -21,7 +21,7 @@ import Grid
|
||||
createPathGrid :: Room -> Room
|
||||
createPathGrid rm =
|
||||
rm
|
||||
{ _rmPath = linksAndPath (map lnkPosDir $ _rmLinks rm) filterGrid
|
||||
{ _rmPath = linksAndPath' (_rmLinks rm) filterGrid
|
||||
}
|
||||
where
|
||||
filterGrid = filter (\p -> pairInPolys (_rmPolys rm) p && testCrossWalls outerWalls p) grid
|
||||
@@ -36,13 +36,17 @@ createPathGrid rm =
|
||||
<*> L.premap sndV2 L.minimum
|
||||
<*> L.premap sndV2 L.maximum
|
||||
|
||||
linksAndPath :: [(Point2, Float)] -> [(Point2, Point2)] -> S.Set (Point2, Point2)
|
||||
linksAndPath lnks subpth = S.fromList subpth <> foldMap linkClosest lnks
|
||||
where
|
||||
linkClosest (p, _) = doublePairSet (p, minimumBy (compare `on` dist p) $ map fst subpth)
|
||||
--linksAndPath :: [(Point2, Float)] -> [(Point2, Point2)] -> S.Set (Point2, Point2)
|
||||
--linksAndPath lnks subpth = S.fromList subpth <> foldMap linkClosest lnks
|
||||
-- where
|
||||
-- linkClosest (p, _) = doublePairSet (p, minimumBy (compare `on` dist p) $ map fst subpth)
|
||||
|
||||
linksAndPath' :: [RoomLink] -> [(Point2, Point2)] -> S.Set (Point2, Point2)
|
||||
linksAndPath' = linksAndPath . map lnkPosDir
|
||||
linksAndPath' lnks subpth = S.fromList subpth
|
||||
<> foldMap (linkClosest . (^. rlPos) ) lnks
|
||||
where
|
||||
linkClosest p = doublePairSet (p, minimumBy (compare `on` dist p) $ map fst subpth)
|
||||
--linksAndPath' = linksAndPath . map lnkPosDir
|
||||
|
||||
testCrossWalls :: [(Point2, Point2)] -> (Point2, Point2) -> Bool
|
||||
testCrossWalls wls (a, b) = not $ any (isJust . uncurry (intersectSegSeg a b)) wls
|
||||
|
||||
Reference in New Issue
Block a user