// // function to compute bounding box of two rectangles // input, output tuples are of the form (x, y, width, height) // def bbox(r1 : (Int, Int, Int, Int), r2 : (Int, Int, Int, Int)) : (Int, Int, Int, Int) = { val (x1, y1, w1, h1) = r1; val (x2, y2, w2, h2) = r2; val x = x1 min x2 val y = y1 min y2 val width = ((x1 + w1) max (x2 + w2)) - x val height = ((y1 + h1) max (y2 + h2)) - y (x, y, width, height) }