Try to simplify link code in roomRect

This commit is contained in:
2025-10-27 15:10:19 +00:00
parent c88fc1c729
commit 0946ee1310
9 changed files with 95 additions and 105 deletions
+8 -18
View File
@@ -1,11 +1,5 @@
module Dodge.Room.Path (
gridPoints,
linksGridToPath,
-- makeGrid,
-- createPathGrid,
gridPoints'',
linksGridToPath',
) where
{-# LANGUAGE TupleSections #-}
module Dodge.Room.Path (linksDAGToPath) where
import Control.Lens
import Data.Function (on)
@@ -13,16 +7,12 @@ import Data.List
import qualified Data.Set as S
import Dodge.Data.GenWorld
import Geometry
import Grid
-- assumes subpth is symmetric
linksGridToPath :: [RoomLink] -> [(Point2, Point2)] -> S.Set (Point2, Point2)
linksGridToPath lnks subpth = S.fromList subpth <> foldMap (linkClosest . (^. rlPos)) lnks
linksDAGToPath :: Foldable f => [RoomLink] -> f (Point2, Point2) -> S.Set (Point2, Point2)
linksDAGToPath lnks xs
| null xs = foldMap doublePairSet $ ys & each %~ (, centroid ys)
| otherwise = subpth <> foldMap (linkClosest . (^. rlPos)) lnks
where
linkClosest p = doublePairSet (p, minimumBy (compare `on` dist p) $ map fst subpth)
linksGridToPath' :: Foldable f => [RoomLink] -> f (Point2, Point2) -> S.Set (Point2, Point2)
linksGridToPath' lnks subpth' = subpth <> foldMap (linkClosest . (^. rlPos)) lnks
where
subpth = foldMap doublePairSet subpth'
ys = lnks <&> _rlPos
subpth = foldMap doublePairSet xs
linkClosest p = doublePairSet (p, minimumBy (compare `on` dist p) $ S.map fst subpth)