Section 21.5.1
Purpose
Determine whether two bounding boxes produced during inference intersect. This helper is used in Qualified Detections, where the relationship between detections contributes to a condition.
Section 21.5.2
Why It Exists
A detection’s presence alone may not establish the condition you need. The book gives the example of a cable end and a plug connection point: intersecting boxes can be used as the overlap condition for identifying a plugged-in cable.
This function supplies the geometric test. Your application decides which labels to compare and what that overlap means.
Section 21.5.3
Input
The book provides two versions of bounding_box_2d_intercept:
- Individual box components: pass the upper-left X and Y positions, width, and height for each box as eight integers.
- BoundingBox objects: pass two object handles; the function reads
x,y,width, andheight.
These are inference coordinates, not normalized center-based training annotations. Both boxes must use the same image coordinate system. Supply valid boxes with positive widths and heights, and valid objects for the handle version.
Class IDs, label names, confidence, and display colors are not part of the overlap calculation.
Review 21.1 · Inference Data & BoundingBox →Section 21.5.4
Output
The return value is true or false. A true result requires overlap with positive width and positive height. Merely touching an edge or corner returns false.
| Relationship | Result |
|---|---|
| Partial overlap | true |
| One box fully inside the other | true |
| Identical valid boxes | true |
| Separated boxes | false |
| Edge-only or corner-only contact | false |
The strict > comparisons implement that positive-area rule. Changing them to >= would change the treatment of touching boxes.
Usage guidance
How To Use
This is an inference-runtime helper, not a standalone Python utility. The book’s object-handle syntax is AngelScript-style; place the function in the scripting environment used by your application.
Using individual components
Add the first version, then pass two boxes using upper-left pixel coordinates:
bool overlap = bounding_box_2d_intercept(
10, 10, 30, 20,
25, 15, 30, 20
);
// overlap is true: both horizontal and vertical overlap are positive.Using BoundingBox objects
Use the BoundingBox class described in 21.1 and the second function version. With valid handles named box1 and box2:
bool overlap = bounding_box_2d_intercept(box1, box2);The function reads their geometry; it does not alter either box. If your runtime supports function overloading, both versions can share the same name.
Before integrating
- Confirm that both detections refer to the same image coordinate system.
- Filter or select the relevant detections before calling the function; it does not check labels or confidence.
- Pass positive box dimensions and valid, non-null handles.
- Test edge and corner contact as well as actual overlap.
No package installation or operating-system command is required for this function. Integration depends on your inference runtime. The AI Request view can help reproduce the helper in another language.
Section 21.5.5
Code
Both versions from section 21.5 are included below. The object version depends on the runtime’s BoundingBox class; its definition is not duplicated here.
// Version 1: individual box components, in integer pixels.
bool bounding_box_2d_intercept(int x1, int y1, int w1, int h1,
int x2, int y2, int w2, int h2) {
if (x1 + w1 > x2 &&
x2 + w2 > x1 &&
y1 + h1 > y2 &&
y2 + h2 > y1) {
return true;
}
return false;
}
// Version 2: the BoundingBox class supplied by the inference runtime.
bool bounding_box_2d_intercept(BoundingBox@ box1, BoundingBox@ box2) {
if (box1.x + box1.width > box2.x &&
box2.x + box2.width > box1.x &&
box1.y + box1.height > box2.y &&
box2.y + box2.height > box1.y) {
return true;
}
return false;
}
Section 21.5.6
Prompt to Reproduce This Utility with AI
Copy the complete request into your AI chat. Review and test the resulting function before integrating it.
Replace [your favorite programming language] with your chosen language. The supplied download retains the book’s inference-scripting syntax.
Programming language: [your favorite programming language]
Create a simple function that determines whether two rectangular bounding boxes in a 2D image intersect.
Each bounding box is defined by the X and Y coordinates of its upper-left corner, along with its width and height. Assume integer pixel coordinates and valid boxes with positive width and height.
The function must return true when the boxes overlap by a positive area and false when they do not. Boxes that only touch at an edge or corner must return false.
Provide one version accepting the X, Y, width, and height values of both boxes individually, and another accepting two custom BoundingBox objects containing x, y, width, and height. Use the equivalent overload or function naming convention supported by the chosen language.
Keep the function simple and efficient, without external libraries. Include a short usage example and checks for partial overlap, full containment, separate boxes, edge contact, and corner contact. Do not replace positive-area overlap with an edge-touching test.

