Split off StreamingHelp module

This commit is contained in:
2022-06-28 12:26:37 +01:00
parent 0cb6657f35
commit e770fba7bf
7 changed files with 50 additions and 41 deletions
+5 -17
View File
@@ -17,6 +17,7 @@ module Dodge.Base.Collide
, bounceBall
, bouncePoint
, sortStreamOn
, minStreamOn
-- , wallsOnCirc
-- , wallsOnCirc'
, wallsOnLineHit
@@ -53,13 +54,12 @@ import Geometry
import FoldableHelp
import Data.Maybe
import Data.Function (on)
import qualified Data.IntMap.Strict as IM
import Control.Lens
import Control.Monad
import qualified FoldlHelp as L
--import qualified FoldlHelp as L
import Data.Monoid
import Streaming
import StreamingHelp
import qualified Streaming.Prelude as S
collidePoint :: Point2 -> Point2
@@ -96,14 +96,6 @@ collidePointWallsFilterStream t sp ep = collidePoint sp ep
. S.filter t
. wallsAlongLine sp ep
-- this hopefully also nub the stream in most cases
--orderStreamOn :: Ord b => (a -> b) -> Stream (Of a) Identity () -> Identity (Of (M.Map b a) ())
sortStreamOn :: Ord a => (b -> a) -> Stream (Of b) Identity () -> Stream (Of b) Identity ()
{-# INLINE sortStreamOn #-}
sortStreamOn f = S.each . runIdentity . L.purely S.fold_ L.map . S.map g
where
g x = (f x,x)
overlapSegWalls :: Point2 -> Point2 -> Stream (Of Wall) Identity ()
-> Stream (Of (Point2,Wall)) Identity ()
overlapSegWalls sp ep = S.mapMaybe $ \wl -> uncurry (intersectSegSeg sp ep) (_wlLine wl) <&> (,wl)
@@ -168,8 +160,7 @@ collideCircWallsStream sp ep rad = runIdentity
f = ((rad *.* normalizeV (vNormal $ a -.- b)) +.+)
overlapCircWallsClosest :: Point2 -> Float -> Stream (Of Wall) Identity () -> Maybe (Point2,Wall)
overlapCircWallsClosest p r = runIdentity
. L.purely S.fold_ (L.minimumBy (compare `on` (dist p . fst)))
overlapCircWallsClosest p r = minStreamOn (dist p . fst)
. overlapCircWalls p r
-- | Looks for first collision of a circle with walls.
@@ -250,10 +241,7 @@ circOnSomeWall p rad = runIdentity . S.any_ (uncurry (circOnSeg p rad) . _wlLine
-- . fmap _wlLine
-- . IM.elems
-- . wallsNearPoint p
{- | Adds the distance to the creature radius, tests whether the center is in
the circle of this size centered at the point -}
anyCrNearPoint :: Float -> Point2 -> World -> Bool
anyCrNearPoint d p = any (\c -> dist (_crPos c) p < (d + _crRad c)) . _creatures
{- | Produce an unordered list of creatures on a line. -}
crsOnLine :: Point2 -> Point2 -> World -> IM.IntMap Creature
crsOnLine p1 p2