Continue streaming refactor

This commit is contained in:
2022-06-26 01:34:58 +01:00
parent e2d09d57e9
commit ac9181e1a1
4 changed files with 29 additions and 20 deletions
+16
View File
@@ -18,6 +18,7 @@ module Dodge.Base.Collide
, wallsOnCirc
, wallsOnCirc'
, wallsOnLineHit
, collideCircWallsStream
, collideCircWalls
, collideCircWallsList
-- , collideCircWalls'
@@ -320,6 +321,21 @@ overlapCircWalls p r = S.mapMaybe dointersect
dointersect wl = f (_wlLine wl) <&> (,wl)
f (a,b) = intersectSegSeg p (p -.- r *.* vNormal (normalizeV (a -.- b))) a b
collideCircWallsStream :: Point2 -> Point2 -> Float -> Stream (Of Wall) Identity ()
-> (Point2, Maybe Wall)
collideCircWallsStream sp ep rad = runIdentity
. S.fold_ findPoint (ep, Nothing) id
where
findPoint (p,mwl) wl = maybe (p,mwl) (,Just wl) . uncurry (intersectSegSeg sp p)
. shiftbyrad
. _wlLine $ wl
shiftbyrad (a,b) = bimap f f
(a +.+ rad *.* normalizeV (a -.-b)
,b +.+ rad *.* normalizeV (b -.-a)
)
where
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)))