a light breeze said:
Or do simply stop traversing when you reach the same depth as the initial quad, ignoring that two of that quad's children are neighbors and two are not?
Yes, you only traverse to the same level of the current quad. There should be never a reason to go deeper, because the neighboring deeper quads will instead find the current quad on their side, which has a higher level from their perspective.
But this applies to both options, no matter if we go up down from the current, or if we go top down for all potential 8 neighbor coordinates.
Now i think the best option would be a compromise. We can always find 3 neighbors quickly by looking just at the parent, which has low complexity, does not need a stack (e.g. recursion), and is faster than traversing from the root.
Then we only search for the parents of the remaining neighbors and do the same with them, which reduces the max number of required traversals to just 2. And we may find both neighbors already from just one parent.
By looking at the Morton code of neighbor coordinates, we also know in advance if they have a common parent, or a common ancestor at which level. May be helpful.
myers.m007@gmail.com said:
I did come across this solution where the author used a bit-mask. but I don't understand that algorithm.
Hmm, i see some flaws in the code examples: He uses if else else sequences a lot, where some bitmath or a compressed LUT in a single 32bit constant would avoid all the branches (but eventually makes the code even harder to understand).
And i assume he confuses Morton code with a hash. Big difference. Only the former contains spatial information in its bits, the latter is just a pseudo random value.
I really liked this paper, introducing quadtrees with efficiency in mind: https://www.merl.com/publications/docs/TR2002-41.pdf