Factor out wls/crsHit
This commit is contained in:
@@ -25,22 +25,22 @@ thingsHit
|
||||
-> Point2 -- ^ Line end point
|
||||
-> World
|
||||
-> Stream (Of (Point2, Either Creature Wall)) Identity ()
|
||||
thingsHit sp ep w
|
||||
| sp == ep = S.each []
|
||||
| otherwise = void $ S.mergeOn (dist sp . fst) crs wls
|
||||
where
|
||||
crs :: Stream (Of (Point2, Either Creature Wall)) Identity ()
|
||||
crs = sortStreamOn (dist sp . fst)
|
||||
thingsHit sp ep w = void $ S.mergeOn (dist sp . fst)
|
||||
(S.map (second Left) (crsHit sp ep w))
|
||||
(S.map (second Right) (wlsHit sp ep w))
|
||||
|
||||
crsHit :: Point2 -> Point2 -> World -> Stream (Of (Point2, Creature)) Identity ()
|
||||
crsHit sp ep
|
||||
| sp == ep = const mempty
|
||||
| otherwise = sortStreamOn (dist sp . fst)
|
||||
. S.mapMaybe
|
||||
(\cr -> (,Left cr) <$> listToMaybe (intersectCircSeg (_crPos cr) (_crRad cr) sp ep))
|
||||
(\cr -> (, cr) <$> listToMaybe (intersectCircSeg (_crPos cr) (_crRad cr) sp ep))
|
||||
. S.each
|
||||
$ _creatures w
|
||||
wls :: Stream (Of (Point2, Either Creature Wall)) Identity ()
|
||||
wls = S.map (second Right)
|
||||
. sortStreamOn (dist sp . fst)
|
||||
. overlapSegWalls sp ep $ wallsAlongLine sp ep w
|
||||
. _creatures
|
||||
|
||||
thingHit :: Point2 -> Point2 -> World -> Maybe (Point2, Either Creature Wall)
|
||||
thingHit sp ep = runIdentity . S.head_ . thingsHit sp ep
|
||||
|
||||
{- List objects that appear on a line.
|
||||
Can filter out a creature. -}
|
||||
thingsHitExceptCr
|
||||
@@ -55,12 +55,9 @@ thingsHitExceptCr (Just cid) sp ep = S.filter crNotCid . thingsHit sp ep
|
||||
crNotCid (_,Left cr) = _crID cr /= cid
|
||||
crNotCid _ = True
|
||||
|
||||
wallsHit
|
||||
:: Point2 -- ^ Line start point
|
||||
-> Point2 -- ^ Line end point
|
||||
-> World
|
||||
-> Stream (Of (Point2, Wall)) Identity ()
|
||||
wallsHit sp ep w
|
||||
| sp == ep = S.each []
|
||||
wlsHit :: Point2 -> Point2 -> World -> Stream (Of (Point2, Wall)) Identity ()
|
||||
wlsHit sp ep
|
||||
| sp == ep = const mempty
|
||||
| otherwise = sortStreamOn (dist sp . fst)
|
||||
. overlapSegWalls sp ep $ wallsAlongLine sp ep w
|
||||
. overlapSegWalls sp ep
|
||||
. wallsAlongLine sp ep
|
||||
|
||||
Reference in New Issue
Block a user