RRectDelta
Workflows

Coding workflows · Union area of two rectangles

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Union area of two rectangles

A concrete starting point
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) - overlap

The 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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗