// // function to compute bounding box of two rectangles // // input, output tuples are of the form (x, y, width, height) // where x, y are coordinates of top left corner in coordinate system // with (0,0) as its top left corner // // (these functions are not needed since Scala has min and max operators, // but we wrote them in class so keep them) def min(i1 : Int, i2 : Int) : Int = if (i1 < i2) i1 else i2 def max(i1 : Int, i2 : Int) : Int = if (i1 > i2) i1 else i2 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 = min(x1, x2) val y = min(y1, y2) val right1 = x1 + w1 val right2 = x2 + w2 val w = max(right1, right2) - x val bottom1 = y1 + h1 val bottom2 = y2 + h2 val h = max(bottom1, bottom2) - y (x, y, w, h) }