I\'ve written a method to help build a quadtree. Each quadtree has a root node, and a root node has 4 children. I\'m using depth recursion to stop this function from dividin
If the n->isLeaf()
condition means "all n
's children are null", then I suppose it is always false here.
I may be wrong but display depth at the first call. If its value is NaN. you got your answer.
Where is the original call to buildTreeHelper
? I can just imagine its in the constructor.
Can you replace "QuadtreeNode * &n" with "QuadtreeNode *n" for second argument in buildTreeHelper(...) and check for result please ???
Your handling on the recursive call to buildTreeHelper
seems perfectly correct. You check the depth
terminating condition before recursing, and you always call it with depth-1
.
The only potential prolem I can see is if it's the constructor calls (the ones creating the children) which call buildTreeHelper
again. That could result in infinite recursion if, for example, the constructor always calls buildTreeHelper
with a object variable for depth
(it would have the same or a greater value each time).
Can't see any issue with the depth check. Are you sure you pass the right depth to the first call? Maybe it isn't infinite, just tooooo deep?