aaBBTreeCollisions search (AABBTreeBranch l r _)  = (nodeResult l) ++ (nodeResult r)
  where
    nodeResult n | collides  = aaBBTreeCollisions search n
                 | otherwise = []
      where
        collides = fromMaybe False mayCollide
        mayCollide = fmap (doCollide search) mayBB
        mayBB = case n of
            AABBTreeEmpty           -> Nothing
            (AABBTreeLeaf _ x)      -> Just x
            (AABBTreeBranch _ _ x)  -> Just x

--------------------------------------------------------------------------------

-- | Puts the elements of an AABBTree into a list.
aaBBTreeCollisions search (AABBTreeBranch l r _)  = (nodeResult l) ++ (nodeResult r)
  where
    nodeResult n | collides  = aaBBTreeCollisions search n
                 | otherwise = []
      where
        collides = fromMaybe False mayCollide
        mayCollide = fmap (doCollide search) mayBB
        mayBB = case n of
            AABBTreeEmpty           -> Nothing
            (AABBTreeLeaf _ x)      -> Just x
            (AABBTreeBranch _ _ x)  -> Just x

--------------------------------------------------------------------------------

-- | Puts the elements of an AABBTree into a list.
aaBBTreeCollisions search (AABBTreeBranch l r _)  = (nodeResult l) ++ (nodeResult r)
  where
    nodeResult n | collides  = aaBBTreeCollisions search n
                 | otherwise = []
      where
        collides = fromMaybe False mayCollide
        mayCollide = fmap (doCollide search) mayBB
        mayBB = case n of
            AABBTreeEmpty           -> Nothing
            (AABBTreeLeaf _ x)      -> Just x
            (AABBTreeBranch _ _ x)  -> Just x

--------------------------------------------------------------------------------

-- | Puts the elements of an AABBTree into a list.