Fix pathing for zChasm

This commit is contained in:
2025-10-27 19:07:04 +00:00
parent 323a50ed31
commit 7c40db7153
4 changed files with 92 additions and 111 deletions
+14 -1
View File
@@ -1,6 +1,8 @@
{-# LANGUAGE TupleSections #-}
module Dodge.Room.Path (linksDAGToPath) where
module Dodge.Room.Path (linksDAGToPath,addNodesCrossing) where
import Linear
import Data.Maybe
import Control.Lens
import Data.Function (on)
import Data.List
@@ -16,3 +18,14 @@ linksDAGToPath lnks xs
ys = lnks <&> _rlPos
subpth = foldMap doublePairSet xs
linkClosest p = doublePairSet (p, minimumBy (compare `on` dist p) $ S.map fst subpth)
addNodesCrossing :: (Point2,Point2) -> S.Set (Point2,Point2) -> S.Set (Point2,Point2)
addNodesCrossing (x,y) = g . foldMap f
where
g (xs,m) = h xs <> m
f (a,b) = fromMaybe (mempty,S.singleton (a,b)) $ do
i <- intersectSegSeg x y a b
return (S.singleton i, S.fromList [(a,i),(i,b)])
h is | null is = mempty
| otherwise = let js = sortOn (distance x) $ S.toList is
in S.fromList . zip js $ tail js