-- | Create a transformation mapping points from the first bounding box to the
--   second. Returns 'Nothing' if either of the boxes are empty.
boxTransform
  :: (HasLinearMap v, Fractional n)
  => BoundingBox v n -> BoundingBox v n -> Maybe (Transformation v n)
boxTransform u v = do
  (P ul, _) <- getCorners u
  (P vl, _) <- getCorners v
  let vec = liftU2 (/) (boxExtents v) (boxExtents u)
      T m m_ _  = scalingV vec
  return $ T m m_ (vl ^-^ liftU2 (*) vec ul)

-- | Check whether a point is contained in a bounding box (inclusive
--   of its boundary). This is a specialised version of 'inquire'.
boxTransform
  :: (HasLinearMap v, Fractional n)
  => BoundingBox v n -> BoundingBox v n -> Maybe (Transformation v n)
boxTransform u v = do
  (P ul, _) <- getCorners u
  (P vl, _) <- getCorners v
  let vec = liftU2 (/) (boxExtents v) (boxExtents u)
      T m m_ _  = scalingV vec
  return $ T m m_ (vl ^-^ liftU2 (*) vec ul)

-- | Check whether a point is contained in a bounding box (inclusive
--   of its boundary). This is a specialised version of 'inquire'.
boxTransform u v = do
  (P ul, _) <- getCorners u
  (P vl, _) <- getCorners v
  let vec = liftU2 (/) (boxExtents v) (boxExtents u)
      T m m_ _  = scalingV vec
  return $ T m m_ (vl ^-^ liftU2 (*) vec ul)

-- | Check whether a point is contained in a bounding box (inclusive
--   of its boundary). This is a specialised version of 'inquire'.