From LeetCode. Union area of 2 rectangles. Solve the geometry problem "Rectangle Area".
Examples
Input:[1,2,3]
Output:0
Input:[2,3,4]
Output:0
Hints
Use inclusion-exclusion: union area = area(A) + area(B) - area(overlap). Compute each rectangle's area from its width and height.
If the rectangles overlap, the overlap region is itself a rectangle. Its width = max(0, min(ax2, bx2) - max(ax1, bx1)), and height = max(0, min(ay2, by2) - max(ay1, by1)).
If max(ax1, bx1) >= min(ax2, bx2) or max(ay1, by1) >= min(ay2, by2) on either axis, overlap area is 0 and the union is simply the sum of both areas.
Rectangle Area
**From LeetCode.** Union area of 2 rectangles. Solve the geometry problem "Rectangle Area".