static Rect rectUnion(Rect a, Rect b) { if (a == null) ret b; if (b == null) ret a; int x = min(a.x, b.x), y = min(a.y, b.y); int x2 = max(a.x+a.w, b.x+b.w), y2 = max(a.y+a.h, b.y+b.h); ret new Rect(x, y, x2-x, y2-y); }