Whenever I store data in a quadtree, I provide its BB and an algorithm finds the correct nodes in the quadtree containing the provided BB.
My problem is the special case where the BB I provide shares boundaries with quadtree boxes. In this case more than 1 quadtree box with fit the search criterion (containment) and my data will be consequently written into more than 1 node.
Example:
A BB stretches from (-0.5, -0.5) to (0.5, 0.5), but there are quadtree boxes to the left and right, up and down of this BB, as well as diagonally, and these will duplicate the data I provide, as they all share 1 boundary with this box. Even worse, the quadtree boxes laying diagonally from this box share exactly 1 pixel (the corner) with it, hence they are taken in too, for a whooping total of 9 boxes having the provided data written into. A picture:
B|B|B
B|X|B
B|B|B
You can see 9 quadtree boxes (B) and the provided one (X) fitting a quadtree box completely.
How do you solve this problem of shared boundaries?
the #s are boxes, the box X that the user provides equals one of them and all 9 would normally store the data. However, we cleverly detect that the #s share only a face or pixel with the X box and so reject them. I suppose we need to calculate the intersection of boxes, if they intersect, and reject the candidate #s if the resulting intersection box is planar.
If this edge case is important to you, you could minimize its impact by using node ranges <= and <, e.g. the x range for the root node’s children would be [0, 1) and [1, 2]. Since 2 is on the edge of the tree, it is <=.
I believe your approach will also work. The intersection of two boxes is straightforward.