Correctly intersect lines and circles

This commit is contained in:
2021-12-15 11:16:56 +00:00
parent 9333d9497e
commit c5a211afce
4 changed files with 15 additions and 18 deletions
+3 -3
View File
@@ -166,15 +166,15 @@ aLaser it cr = particles .:~ makeLaserAt phasev pos dir
makeLaserAt :: Float -> Point2 -> Float -> Particle
makeLaserAt phasev pos dir = Particle
{ _ptDraw = const blank
, _ptUpdate = moveLaser phasev pos dir
, _ptUpdate = mvLaser phasev pos dir
}
moveLaser :: Float -- ^ Phase velocity, controls deflection through windows
mvLaser :: Float -- ^ Phase velocity, controls deflection through windows
-> Point2
-> Float
-> World
-> Particle
-> (World, Maybe Particle)
moveLaser phasev pos dir w pt
mvLaser phasev pos dir w pt
= ( damThingHitWith (Lasering 19) pos xp thHit w
, Just pt {_ptDraw = const pic ,_ptUpdate = ptSimpleTime 0 }
)
+5 -1
View File
@@ -1,3 +1,4 @@
{-# LANGUAGE TupleSections #-}
{- |
Find which objects lie upon a line.
-}
@@ -121,7 +122,10 @@ thingsHitLongLine sp ep w
| sp == ep = []
| otherwise = sortOn (dist sp . fst) (crs ++ wls)
where
crs = zip crPs (map Left hitCrs)
crs = mapMaybe
(\cr -> (,Left cr) <$> listToMaybe (intersectCircSeg (_crPos cr) (_crRad cr) sp ep))
. IM.elems $ _creatures w
--crs = zip crPs (map Left hitCrs)
hitCrs = IM.elems
. IM.filter (\cr -> circOnSeg sp ep (_crPos cr) (_crRad cr))
$ _creatures w