Math Fundamentals18 sections · 814 units
Open in Course

Rectangle Area - Pseudocode

(Implementation ready)

function computeArea(x1a, y1a, x2a, y2a, x1b, y1b, x2b, y2b): area1 = (x2a - x1a) * (y2a - y1a) area2 = (x2b - x1b) * (y2b - y1b)

left = max(x1a, x1b)
right = min(x2a, x2b)
bottom = max(y1a, y1b)
top = min(y2a, y2b)

overlap = 0
if left < right and bottom < top:
    overlap = (right - left) * (top - bottom)

return area1 + area2 - overlap