Copyright | (c) axionbuster 2025 |
---|---|
License | BSD-3-Clause |
Safe Haskell | None |
Language | GHC2021 |
Core collision detection primitives and algorithms in pure form. Provides AABB collision testing, shape interfaces, and hit detection utilities.
Synopsis
- class Shape (s :: Type -> Type) where
- intersecting :: (Fractional a, Ord a) => s a -> s a -> Bool
- crossing :: RealFloat a => V3 a -> V3 a -> s a -> Hit a
- hitting :: RealFloat a => V3 a -> s a -> s a -> Hit a
- translate :: Num a => V3 a -> s a -> s a
- corners :: (Fractional a, Ord a) => s a -> V2 (V3 a)
- tomanyboxes :: s a -> ManyBoxes [] a
- scenter :: (Fractional a, Ord a) => s a -> V3 a
- sdimensions :: (Fractional a, Ord a) => s a -> V3 a
- data SomeShape1 a = (Typeable (s a), Show (s a), Shape s) => SomeShape1 (s a)
- data Hit a = Hit {}
- newtype Hit' a = Hit' {}
- data Box a where
- Box {
- dimensions :: !(V3 a)
- center :: !(V3 a)
- pattern Box' :: Fractional a => V3 a -> V3 a -> Box a
- Box {
- newtype ManyBoxes (f :: Type -> Type) a = ManyBoxes (f (Box a))
- type ManyBoxes_ a = ManyBoxes [] a
- _dimensions :: forall a f. Functor f => (V3 a -> f (V3 a)) -> Box a -> f (Box a)
- _center :: forall a f. Functor f => (V3 a -> f (V3 a)) -> Box a -> f (Box a)
- _lcorner :: Fractional a => Lens' (Box a) (V3 a)
- _hcorner :: Fractional a => Lens' (Box a) (V3 a)
- hitin01 :: (Num a, Ord a) => Hit a -> Bool
- infhit :: Fractional a => Hit a
- boxfromcorners :: Fractional a => V3 a -> V3 a -> Box a
- castshape1 :: Typeable b => SomeShape1 a -> Maybe b
- boxzero :: Num a => Box a
- hicorner :: Fractional a => Box a -> V3 a
- hicorner' :: Fractional a => Box a -> V3 a
- locorner :: Fractional a => Box a -> V3 a
- locorner' :: Fractional a => Box a -> V3 a
- shicorner :: (Shape s, Fractional a, Ord a) => s a -> V3 a
- slocorner :: (Shape s, Fractional a, Ord a) => s a -> V3 a
Documentation
class Shape (s :: Type -> Type) where Source #
an AABB type class used for collision detection and resolution
intersecting :: (Fractional a, Ord a) => s a -> s a -> Bool Source #
check if two shapes intersect
crossing :: RealFloat a => V3 a -> V3 a -> s a -> Hit a Source #
check if a ray will hit the shape and return the hit data
hitting :: RealFloat a => V3 a -> s a -> s a -> Hit a Source #
check if the first shape will collide into the second shape if it moves with the given displacement
translate :: Num a => V3 a -> s a -> s a Source #
translate the shape by the given displacement
corners :: (Fractional a, Ord a) => s a -> V2 (V3 a) Source #
the locations of the lower and higher corners of the shape respectively
tomanyboxes :: s a -> ManyBoxes [] a Source #
convert a Shape
to a ManyBoxes
of Box
es with a list container,
which is a canonical form for ManyBoxes
scenter :: (Fractional a, Ord a) => s a -> V3 a Source #
the center of the shape
sdimensions :: (Fractional a, Ord a) => s a -> V3 a Source #
the dimensions of the shape
Instances
data SomeShape1 a Source #
existential Shape
type but where numeric type is erased
see also: castshape1
(Typeable (s a), Show (s a), Shape s) => SomeShape1 (s a) |
Instances
Shape SomeShape1 Source # | |
Defined in M.Collision.Pure intersecting :: (Fractional a, Ord a) => SomeShape1 a -> SomeShape1 a -> Bool Source # crossing :: RealFloat a => V3 a -> V3 a -> SomeShape1 a -> Hit a Source # hitting :: RealFloat a => V3 a -> SomeShape1 a -> SomeShape1 a -> Hit a Source # translate :: Num a => V3 a -> SomeShape1 a -> SomeShape1 a Source # corners :: (Fractional a, Ord a) => SomeShape1 a -> V2 (V3 a) Source # tomanyboxes :: SomeShape1 a -> ManyBoxes [] a Source # scenter :: (Fractional a, Ord a) => SomeShape1 a -> V3 a Source # sdimensions :: (Fractional a, Ord a) => SomeShape1 a -> V3 a Source # | |
Show (SomeShape1 a) Source # | |
Defined in M.Collision.Pure showsPrec :: Int -> SomeShape1 a -> ShowS # show :: SomeShape1 a -> String # showList :: [SomeShape1 a] -> ShowS # |
a collision resolution data type
no hit is represented by a hit at infinity (other fields are unspecified)
Instances
Functor Hit Source # | |||||
Data a => Data (Hit a) Source # | |||||
Defined in M.Collision.Pure gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Hit a -> c (Hit a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Hit a) # dataTypeOf :: Hit a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Hit a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Hit a)) # gmapT :: (forall b. Data b => b -> b) -> Hit a -> Hit a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Hit a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Hit a -> r # gmapQ :: (forall d. Data d => d -> u) -> Hit a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Hit a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Hit a -> m (Hit a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Hit a -> m (Hit a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Hit a -> m (Hit a) # | |||||
Generic (Hit a) Source # | |||||
Defined in M.Collision.Pure
| |||||
Show a => Show (Hit a) Source # | |||||
Eq a => Eq (Hit a) Source # | |||||
Hashable a => Hashable (Hit a) Source # | |||||
Defined in M.Collision.Pure | |||||
type Rep (Hit a) Source # | |||||
Defined in M.Collision.Pure type Rep (Hit a) = D1 ('MetaData "Hit" "M.Collision.Pure" "mmm-0.1.0.0-oCDsNp3EBL2JzoyA6cTai" 'False) (C1 ('MetaCons "Hit" 'PrefixI 'True) (S1 ('MetaSel ('Just "hittime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: (S1 ('MetaSel ('Just "hitwhere") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (V3 a)) :*: S1 ('MetaSel ('Just "hitnorm") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (V3 a))))) |
internal newtype used with Min
to find the closest hit
a box in 3D space, located either relatively or absolutely
Box | |
|
pattern Box' :: Fractional a => V3 a -> V3 a -> Box a | bidrectional pattern for you can use the |
Instances
Applicative Box Source # | |||||
Functor Box Source # | |||||
Shape Box Source # | |||||
Defined in M.Collision.Pure intersecting :: (Fractional a, Ord a) => Box a -> Box a -> Bool Source # crossing :: RealFloat a => V3 a -> V3 a -> Box a -> Hit a Source # hitting :: RealFloat a => V3 a -> Box a -> Box a -> Hit a Source # translate :: Num a => V3 a -> Box a -> Box a Source # corners :: (Fractional a, Ord a) => Box a -> V2 (V3 a) Source # tomanyboxes :: Box a -> ManyBoxes [] a Source # scenter :: (Fractional a, Ord a) => Box a -> V3 a Source # sdimensions :: (Fractional a, Ord a) => Box a -> V3 a Source # | |||||
Data a => Data (Box a) Source # | |||||
Defined in M.Collision.Pure gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Box a -> c (Box a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Box a) # dataTypeOf :: Box a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Box a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Box a)) # gmapT :: (forall b. Data b => b -> b) -> Box a -> Box a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Box a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Box a -> r # gmapQ :: (forall d. Data d => d -> u) -> Box a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Box a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Box a -> m (Box a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Box a -> m (Box a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Box a -> m (Box a) # | |||||
Generic (Box a) Source # | |||||
Defined in M.Collision.Pure
| |||||
Show a => Show (Box a) Source # | |||||
Eq a => Eq (Box a) Source # | |||||
Hashable a => Hashable (Box a) Source # | |||||
Defined in M.Collision.Pure | |||||
type Rep (Box a) Source # | |||||
Defined in M.Collision.Pure type Rep (Box a) = D1 ('MetaData "Box" "M.Collision.Pure" "mmm-0.1.0.0-oCDsNp3EBL2JzoyA6cTai" 'False) (C1 ('MetaCons "Box" 'PrefixI 'True) (S1 ('MetaSel ('Just "dimensions") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (V3 a)) :*: S1 ('MetaSel ('Just "center") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (V3 a)))) |
newtype ManyBoxes (f :: Type -> Type) a Source #
a newtype over a Foldable
Functor
container of Box
es
the low and high corners are those of the smallest bounding box
Instances
Functor f => Functor (ManyBoxes f) Source # | |||||
(Functor f, Foldable f) => Shape (ManyBoxes f) Source # | |||||
Defined in M.Collision.Pure intersecting :: (Fractional a, Ord a) => ManyBoxes f a -> ManyBoxes f a -> Bool Source # crossing :: RealFloat a => V3 a -> V3 a -> ManyBoxes f a -> Hit a Source # hitting :: RealFloat a => V3 a -> ManyBoxes f a -> ManyBoxes f a -> Hit a Source # translate :: Num a => V3 a -> ManyBoxes f a -> ManyBoxes f a Source # corners :: (Fractional a, Ord a) => ManyBoxes f a -> V2 (V3 a) Source # tomanyboxes :: ManyBoxes f a -> ManyBoxes [] a Source # scenter :: (Fractional a, Ord a) => ManyBoxes f a -> V3 a Source # sdimensions :: (Fractional a, Ord a) => ManyBoxes f a -> V3 a Source # | |||||
(Typeable f, Typeable a, Data (f (Box a))) => Data (ManyBoxes f a) Source # | |||||
Defined in M.Collision.Pure gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ManyBoxes f a -> c (ManyBoxes f a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (ManyBoxes f a) # toConstr :: ManyBoxes f a -> Constr # dataTypeOf :: ManyBoxes f a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (ManyBoxes f a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ManyBoxes f a)) # gmapT :: (forall b. Data b => b -> b) -> ManyBoxes f a -> ManyBoxes f a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ManyBoxes f a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ManyBoxes f a -> r # gmapQ :: (forall d. Data d => d -> u) -> ManyBoxes f a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ManyBoxes f a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ManyBoxes f a -> m (ManyBoxes f a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ManyBoxes f a -> m (ManyBoxes f a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ManyBoxes f a -> m (ManyBoxes f a) # | |||||
Generic (ManyBoxes f a) Source # | |||||
Defined in M.Collision.Pure
| |||||
Show (f (Box a)) => Show (ManyBoxes f a) Source # | |||||
Eq (f (Box a)) => Eq (ManyBoxes f a) Source # | |||||
Ord (f (Box a)) => Ord (ManyBoxes f a) Source # | |||||
Defined in M.Collision.Pure compare :: ManyBoxes f a -> ManyBoxes f a -> Ordering # (<) :: ManyBoxes f a -> ManyBoxes f a -> Bool # (<=) :: ManyBoxes f a -> ManyBoxes f a -> Bool # (>) :: ManyBoxes f a -> ManyBoxes f a -> Bool # (>=) :: ManyBoxes f a -> ManyBoxes f a -> Bool # | |||||
Hashable (f (Box a)) => Hashable (ManyBoxes f a) Source # | |||||
Defined in M.Collision.Pure | |||||
type Rep (ManyBoxes f a) Source # | |||||
Defined in M.Collision.Pure |
type ManyBoxes_ a = ManyBoxes [] a Source #
_dimensions :: forall a f. Functor f => (V3 a -> f (V3 a)) -> Box a -> f (Box a) Source #
Lens for the dimensions of the box
_center :: forall a f. Functor f => (V3 a -> f (V3 a)) -> Box a -> f (Box a) Source #
Lens for the center of the box
_lcorner :: Fractional a => Lens' (Box a) (V3 a) Source #
Lens for the lower corner of the box
_hcorner :: Fractional a => Lens' (Box a) (V3 a) Source #
Lens for the higher corner of the box
infhit :: Fractional a => Hit a Source #
a hit at infinity
:: Fractional a | |
=> V3 a | low corner |
-> V3 a | high corner |
-> Box a | the box |
a box from the low and high corners
castshape1 :: Typeable b => SomeShape1 a -> Maybe b Source #
cast a SomeShape1
to a specific type
hicorner :: Fractional a => Box a -> V3 a Source #
the location of the higher corner of the box
hicorner' :: Fractional a => Box a -> V3 a Source #
locorner :: Fractional a => Box a -> V3 a Source #
the location of the lower corner of the box
locorner' :: Fractional a => Box a -> V3 a Source #