Try to simplify link code in roomRect
This commit is contained in:
+8
-18
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user