I have an isometric scene in a custom engine where my world sim is 3D, but I'm rendering sprites. To depth sort, I follow [the approach in this blog post](https://web.archive.org/web/20161016065648/https://mazebert.com/2013/04/18/isometric-depth-sorting/). Basically: wrap each sprite in an AABB, then sort them by depth.

The condition it uses to test if one of the sprite's AABBs is behind another is:
```
if (b.minX < a.maxX && b.minY < a.maxY && b.minZ < a.maxZ)
{
 // b is behind a
}
```
however, this doesn't produce the result I would like in a few situations. Say I have two boxes, where one is intersecting the other:
[![Separated boxes, and intersecting boxes][1]][1]

```
// BoundingBox is {minX, maxX, minY, maxY, minZ, maxZ}
BoundingBox spriteABounds{0, 7, 0, 32, 0, 78};
BoundingBox spriteBBounds{0, 32, 0, 32, 0, 78};
```
The desired behavior would be for sprite A to be behind sprite B, but the above condition considers both boxes to be behind eachother.

Another situation is when dealing with planes (note that the floor tile isn't graphically a plane, but should be treated as one in the world sim):
[![Floor tile drawing over a wall][2]][2]
```
BoundingBox spriteABounds{0, 32, 0, 32, 78, 78};
BoundingBox spriteBBounds{32, 64, 0, 32, 0, 78};
```
The desired behavior would be for sprite A to be behind sprite B, but the above condition considers neither to be behind eachother.

Is there a way that I can set up the condition to handle these cases appropriately, or would I need to switch to a different approach? If the latter, what approach would be more appropriate?


 [1]: https://i.sstatic.net/mjbHNGDs.png
 [2]: https://i.sstatic.net/w1Hb3HY8.png