Start using streaming as the way to consume foldable objects
This commit is contained in:
@@ -19,10 +19,11 @@ module Dodge.Base.Collide
|
||||
, collideCircWalls
|
||||
-- , collideCircWalls'
|
||||
, circOnSomeWall
|
||||
-- , collidePointWalls
|
||||
, collidePointWalls
|
||||
, collidePointWallsNorm
|
||||
, collidePointWalls'
|
||||
, collidePointWallsFilt'
|
||||
, collidePointWallsL
|
||||
, collidePointWallsFilt
|
||||
, overlapCircWallsReturnWall
|
||||
, collideCircCrsPoint
|
||||
, collideCircCreatures
|
||||
@@ -370,15 +371,20 @@ collidePointWalls :: Point2 -> Point2 -> IM.IntMap Wall -> Point2
|
||||
collidePointWalls p1 p2 = foldr findPoint p2 . fmap _wlLine
|
||||
where
|
||||
findPoint (x,y) p = fromMaybe p $ intersectSegSeg p1 p x y
|
||||
collidePointWalls' :: Point2 -> Point2 -> IM.IntMap Wall -> Point2
|
||||
collidePointWalls' :: (Foldable t, Functor t) => Point2 -> Point2 -> t Wall -> Point2
|
||||
{-# INLINE collidePointWalls' #-}
|
||||
collidePointWalls' p1 p2 = foldl' findPoint p2 . fmap _wlLine
|
||||
where
|
||||
findPoint p = fromMaybe p . uncurry (intersectSegSeg p1 p)
|
||||
|
||||
collidePointWallsFilt' :: (Wall -> Bool) -> Point2 -> Point2 -> IM.IntMap Wall -> Point2
|
||||
{-# INLINE collidePointWallsFilt' #-}
|
||||
collidePointWallsFilt' t p1 p2 = collidePointWalls p1 p2 . IM.filter t
|
||||
collidePointWallsL :: Point2 -> Point2 -> L.Fold Wall Point2
|
||||
collidePointWallsL p1 p2 = L.Fold findPoint p2 id
|
||||
where
|
||||
findPoint p = fromMaybe p . uncurry (intersectSegSeg p1 p) . _wlLine
|
||||
|
||||
collidePointWallsFilt :: (Wall -> Bool) -> Point2 -> Point2 -> IM.IntMap Wall -> Point2
|
||||
{-# INLINE collidePointWallsFilt #-}
|
||||
collidePointWallsFilt t p1 p2 = collidePointWalls' p1 p2 . IM.filter t
|
||||
|
||||
-- | Looks for first collision of a circle with walls.
|
||||
-- If found, gives point and reflection velocity, reflection damped in normal.
|
||||
|
||||
Reference in New Issue
Block a user