Open the context
Choose the project folder and name the files or behavior involved.
Compute the union area of two axis-aligned rectangles with strictly increasing integer bounds. Check overlapping, contained and touching rectangles, rejecting zero-area or reversed bounds before arithmetic and leaving both inputs unchanged.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def union_area(first, second):
if any(type(v) not in (list, tuple) or len(v) != 4 for v in (first, second)):
raise ValueError("rectangle.container")
first, second = tuple(first), tuple(second)
for rectangle in (first, second):
if len(rectangle) != 4 or any(type(v) is not int for v in rectangle):
raise ValueError("rectangle.integer")
x0, y0, x1, y1 = rectangle
if x0 >= x1 or y0 >= y1:
raise ValueError("rectangle.bounds")
a, b, c, d = first
e, f, g, h = second
overlap = max(0, min(c, g) - max(a, e)) * max(0, min(d, h) - max(b, f))
return (c - a) * (d - b) + (g - e) * (h - f) - overlapThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.