rect Intersection(const rect &a, const rect &b) { int xmax = Maximum(a.x, b.x); int ymax = Maximum(a.y, b.y); int xmin = Minimum(a.x + a.w, b.x + b.w); int ymin = Minimum(a.y + a.h, b.y + b.h); int width = xmin - xmax; int height = ymin - ymax; if(width > 0 && height > 0) { rect intersect = {xmax, ymax, width, height}; return intersect; } else { rect intersect = {0, 0, 0, 0}; return intersect; } }