I have two grids (coming from finite elements, but this is not relevant), say T_1, T_2. One grid is inside the other, think of a square inside another one for instance. For each grid I have constructed an RTree with boost of bounding boxes, say RTree1 and RTree2. To find all the pair of intersecting rectangles, I do the following
for (const auto &[box2, cell2] : RTree_2)
{
for (const auto &[box1, cell1] :
RTree1 | bgi::adaptors::queried(bgi::intersects(box2)))
{
do_something_with_cells(cell1,cell2);
}
}
}
Let's say that I have N bounding boxes for the first tree and M bounding boxes for the second tree. I want to determine the complexity of the snippet above.
Since the intersection has a complexity which is O(log(N)) (on average), I think the snippet above has a complexity which is O(N M log(N)). Is this correct?
If the code above was written like this:
for (const auto &[box2, cell2] : RTree_2)
{
for (const auto &[box1, cell1] :
RTree1)
{
//check if box1 and box2 intersects using bgi
bgi::query(box1,bgi::intersects(box2));
}
}
}
I should have a O(NM log(N)), right?