Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
The Bounds3::Intersect method calculates the intersection of two bounding boxes by taking the max of the minimums, and the min of the maximums (page 78). Figure 2.9 illustrates it in 2D. The two points are passed to the constructor that takes two points (page 77).
The combination of the Intersect method and the constructor gives the wrong result when the boxes do not overlap.
Look at this example, where we have a red and a blue box that do not overlap. The two circled points are the points that the Intersect method calculates.
Now, the constructor shuffles the coordinates around to make sure that pMin.x <= pMax.x && pMin.y <= pMax.y && pMin.z <= pMax.z. Because of this, the end result is that the shaded area is returned as the intersection:
Which is incorrect, because this is an area that's outside of both the red and blue box, and is not the intersection.
Paragraph 2.6 about bounding boxes:
The
Bounds3::Intersect
method calculates the intersection of two bounding boxes by taking the max of the minimums, and the min of the maximums (page 78). Figure 2.9 illustrates it in 2D. The two points are passed to the constructor that takes two points (page 77).The combination of the Intersect method and the constructor gives the wrong result when the boxes do not overlap.
Look at this example, where we have a red and a blue box that do not overlap. The two circled points are the points that the Intersect method calculates.
Now, the constructor shuffles the coordinates around to make sure that
pMin.x <= pMax.x && pMin.y <= pMax.y && pMin.z <= pMax.z
. Because of this, the end result is that the shaded area is returned as the intersection:Which is incorrect, because this is an area that's outside of both the red and blue box, and is not the intersection.