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