module GJK.Support
( polySupport
, isCollision
) where
import GJK.Point (Pt, dot)
import GJK.Collision (collision)
import Data.Maybe (fromMaybe)
polySupport :: [Pt] -> Pt -> Maybe Pt
polySupport list d =
let
dotList = fmap (dot d) list
decorated = zip dotList list
maybemax = safeMaximum decorated
in
case maybemax of
Just (_, p) -> Just p
_ -> Nothing
safeMaximum :: Ord a => [a] -> Maybe a
safeMaximum [] = Nothing
safeMaximum list = Just $ maximum list
isCollision :: [Pt] -> [Pt] -> Bool
isCollision a b =
fromMaybe False $ collision 1 (a, polySupport) (b, polySupport)