Every object detector is scored with IoU: the overlap between a predicted box and the true box, divided by the total area the two of them cover.
IoU = area of intersection / area of union
Boxes arrive as [x1, y1, x2, y2] — top-left corner, then bottom-right.
Task: write iou(box_a, box_b) returning a float rounded to 4 decimal places.
The whole problem is the intersection rectangle. Its left edge is the rightmost of the two left edges, its right edge is the leftmost of the two right edges — and the same logic vertically. If that leaves a negative width or height, the boxes miss each other entirely and the intersection is 0, not a negative number.
area_a + area_b - intersection.