Finish replacement of sortOn with safeMinimumBy, regress door space leak

This commit is contained in:
2021-07-20 05:40:57 +02:00
parent 8bc5b49a3c
commit 40ee81aff9
4 changed files with 10 additions and 16 deletions
+2 -5
View File
@@ -1,16 +1,13 @@
module Dodge.Creature.Action.Flee
where
import Dodge.Data
import Dodge.Base.Collide
import Geometry
import Data.List
import Data.Maybe
retreatPointForFrom
:: Float -> World -> Creature -> Point2 -> Maybe Point2
retreatPointForFrom d _ cr p
= listToMaybe
. sortOn (dist cpos)
= safeMinimumOn (dist cpos)
$ divideCircle 10 p d
where
cpos = _crPos cr
+1 -2
View File
@@ -17,7 +17,6 @@ import Picture
import Geometry
import Data.Maybe
import Data.List
import qualified Data.IntMap.Strict as IM
import Control.Lens
import Control.Monad.Reader
@@ -59,7 +58,7 @@ mFlockACC cr w = do
&& dist (_crPos cr') tpos > dist cpos tpos
-- && circOnSeg (_crPos cr') tpos cpos (_crRad cr + _crRad cr')
nearACCs = IM.filter isFarACC $ creaturesNearPointI 3 cpos w
acr <- listToMaybe $ sortOn (dist cpos . _crPos) $ IM.elems nearACCs
acr <- safeMinimumOn (dist cpos . _crPos) nearACCs
let r = _crRad acr + _crRad cr + 10
horDir = normalizeV (vNormal (cpos -.- tpos))
horShift = if isLHS tpos cpos (_crPos acr)