-- | Find the intersection of two rectangles.
rectIntersection :: (Real a) => Rect a -> Rect a -> Rect a
rectIntersection (Rect x1 y1 w1 h1) (Rect x2 y2 w2 h2) =
  let x = max x1 x2
      y = max y1 y2
      w = max 0 (min (x1 + w1) (x2 + w2) - x)
      h = max 0 (min (y1 + h1) (y2 + h2) - y)
  in Rect x y w h
rectIntersection :: (Real a) => Rect a -> Rect a -> Rect a
rectIntersection (Rect x1 y1 w1 h1) (Rect x2 y2 w2 h2) =
  let x = max x1 x2
      y = max y1 y2
      w = max 0 (min (x1 + w1) (x2 + w2) - x)
      h = max 0 (min (y1 + h1) (y2 + h2) - y)
  in Rect x y w h
rectIntersection (Rect x1 y1 w1 h1) (Rect x2 y2 w2 h2) =
  let x = max x1 x2
      y = max y1 y2
      w = max 0 (min (x1 + w1) (x2 + w2) - x)
      h = max 0 (min (y1 + h1) (y2 + h2) - y)
  in Rect x y w h