Change foldr to foldl' in some cases

This commit is contained in:
2022-06-23 21:46:46 +01:00
parent fb3f677957
commit 89dd8502ad
6 changed files with 34 additions and 27 deletions
+17 -17
View File
@@ -17,9 +17,9 @@ module Dodge.Base.Collide
, wallsOnCirc
, wallsOnLineHit
, collideCircWalls
, collideCircWalls'
-- , collideCircWalls'
, circOnSomeWall
, collidePointWalls
-- , collidePointWalls
, collidePointWallsNorm
, collidePointWalls'
, collidePointWallsFilt'
@@ -383,21 +383,21 @@ 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.
-- note that the "intersection" point is the center of the circle flush against the wall
collideCircWalls' :: Point2 -> Point2 -> Float -> IM.IntMap Wall -> Maybe (Point2,Point2)
collideCircWalls' p1 p2 rad = either (const Nothing) Just . foldr findPoint (Left p2)
where
findPoint wl eip = maybe eip Right $ doReflection (getp eip) $ shiftByRad $ _wlLine wl
getp (Left p) = p
getp (Right (p,_)) = p
doReflection p (x,y) = case intersectSegSeg p1 p x y of
Nothing -> Nothing
Just ip -> Just (ip +.+ normalizeV (vNormal (x -.- y)), reflectInParam 0.5 (x -.- y) (p2 -.- p1))
shiftByRad (a,b) =
(g $ a +.+ rad *.* normalizeV (a -.-b)
,g $ b +.+ rad *.* normalizeV (b -.-a)
)
where
g = ((rad *.* normalizeV (vNormal $ a -.- b)) +.+)
--collideCircWalls' :: Point2 -> Point2 -> Float -> IM.IntMap Wall -> Maybe (Point2,Point2)
--collideCircWalls' p1 p2 rad = either (const Nothing) Just . foldr findPoint (Left p2)
-- where
-- findPoint wl eip = maybe eip Right $ doReflection (getp eip) $ shiftByRad $ _wlLine wl
-- getp (Left p) = p
-- getp (Right (p,_)) = p
-- doReflection p (x,y) = case intersectSegSeg p1 p x y of
-- Nothing -> Nothing
-- Just ip -> Just (ip +.+ normalizeV (vNormal (x -.- y)), reflectInParam 0.5 (x -.- y) (p2 -.- p1))
-- shiftByRad (a,b) =
-- (g $ a +.+ rad *.* normalizeV (a -.-b)
-- ,g $ b +.+ rad *.* normalizeV (b -.-a)
-- )
-- where
-- g = ((rad *.* normalizeV (vNormal $ a -.- b)) +.+)
-- | Looks for first collision of a circle with walls.
-- If found, gives point and reflection velocity, reflection damped in normal.