This commit is contained in:
2022-06-29 12:42:02 +01:00
parent e24f89217a
commit 1f4f1f6ab1
3 changed files with 10 additions and 13 deletions
+5 -5
View File
@@ -16,7 +16,7 @@ import Geometry
import Data.Maybe
import Data.Bifunctor
import Streaming
import StreamingHelp
import qualified Streaming.Prelude as S
{- List those objects that appear on a line. -}
@@ -24,12 +24,12 @@ thingsHit
:: Point2 -- ^ Line start point
-> Point2 -- ^ Line end point
-> World
-> Stream (Of (Point2, Either Creature Wall)) Identity ()
-> StreamOf (Point2, Either Creature Wall)
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 :: Point2 -> Point2 -> World -> StreamOf (Point2, Creature)
crsHit sp ep
| sp == ep = const mempty
| otherwise = sortStreamOn (dist sp . fst)
@@ -48,14 +48,14 @@ thingsHitExceptCr
-> Point2 -- ^ Line start point
-> Point2 -- ^ Line end point
-> World
-> Stream (Of (Point2, Either Creature Wall)) Identity ()
-> StreamOf (Point2, Either Creature Wall)
thingsHitExceptCr Nothing sp ep = thingsHit sp ep
thingsHitExceptCr (Just cid) sp ep = S.filter crNotCid . thingsHit sp ep
where
crNotCid (_,Left cr) = _crID cr /= cid
crNotCid _ = True
wlsHit :: Point2 -> Point2 -> World -> Stream (Of (Point2, Wall)) Identity ()
wlsHit :: Point2 -> Point2 -> World -> StreamOf (Point2, Wall)
wlsHit sp ep
| sp == ep = const mempty
| otherwise = sortStreamOn (dist sp . fst)