Attempt to improve perfomance

This commit is contained in:
2022-08-25 09:52:12 +01:00
parent 6973663055
commit 920bfdbc8e
18 changed files with 60 additions and 311 deletions
+9 -8
View File
@@ -104,7 +104,7 @@ pointTowardsImpulse a b w = (find (flip (isWalkable a) w) . reverse) =<< makePat
-- _ -> return $ Just $ ns !! i
--
pairsToGraph :: Set.Set (Point2, Point2) -> (Map (V2 Point2) (Int, Int, PathEdge), Gr Point2 PathEdge)
pairsToGraph :: Set.Set (Point2, Point2) -> (Map (V2 Point2) PathEdgeNodes, Gr Point2 PathEdge)
pairsToGraph pairs = addEdges nodemap gr pairs
where
(nodemap, _, gr) = addNodes $ Set.toList $ Set.map fst pairs <> Set.map snd pairs
@@ -120,27 +120,28 @@ addEdges ::
Map Point2 Int ->
Gr Point2 PathEdge ->
Set.Set (Point2, Point2) ->
(Map (V2 Point2) (Int, Int, PathEdge), Gr Point2 PathEdge)
(Map (V2 Point2) PathEdgeNodes, Gr Point2 PathEdge)
addEdges nodemap gr = foldl' f (mempty, gr)
where
f (edgemap, gr') (a, b) =
( M.insert (V2 a b) theedge edgemap
, insEdge theedge gr'
( M.insert (V2 a b) theedgedata edgemap
, insEdge theedgetup gr'
)
where
theedge = (g a, g b, PathEdge a b (dist a b) mempty)
theedgetup = (g a, g b, PathEdge a b (dist a b) mempty)
theedgedata = PathEdgeNodes (g a) (g b) (PathEdge a b (dist a b) mempty)
g a = nodemap M.! a
obstructPathsCrossing :: EdgeObstacle -> Point2 -> Point2 -> World -> (World, Set (Int, Int, PathEdge))
obstructPathsCrossing :: EdgeObstacle -> Point2 -> Point2 -> World -> (World, Set PathEdgeNodes)
obstructPathsCrossing obstacletype sp' ep w =
( w & cWorld . pathGraph %~ updateedges
, es
)
where
es = Set.filter edgecrosses $ pesNearSeg sp' ep w
edgecrosses (_, _, pe) = isJust $ intersectSegSeg sp' ep (_peStart pe) (_peEnd pe)
edgecrosses (PathEdgeNodes _ _ pe) = isJust $ intersectSegSeg sp' ep (_peStart pe) (_peEnd pe)
updateedges gr = foldl' updateedge gr es
updateedge gr (x, y, pe) =
updateedge gr (PathEdgeNodes x y pe) =
insEdge (x, y, pe & peObstacles . at obstacletype ?~ ()) $ delEdge (x, y) gr
fuseFunc :: (a -> a -> Bool) -> [a] -> a -> a