Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualTheChubu

Posted 06 November 2012 - 02:30 AM

You're doing a logical OR in all those checks. It shouldn't be a logical AND? Since if any limit is outside bounds, you already know that node can't contain the data.

With a logical OR, if even only one of all those checks is true and the rest fail, it will return true.

So a (Entity.minx >= quadtree.minx && Entity.maxx <= quadtree.maxx && Entity.miny <= quadtree.miny && Entity.maxy >= quadtree.maxy ) check should do. You need all of those conditions to be true for the node to be able to contain the data. Thus the AND (&&).

btw, you should be careful with returns in the middle of the code. Its easy to forget and leak memory by allocating new memory and having a branch in your logic that returns before you get rid of the resources you no longer use.

#1TheChubu

Posted 06 November 2012 - 02:23 AM

You're doing a logical OR in all those checks. It shouldn't be a logical AND? Since if any limit is outside bounds, you already know that node can't contain the data.

With a logical OR, if even only one of all those checks is true and the rest fail, it will return true.

So a (Entity.minx >= quadtree.minx && Entity.maxx <= quadtree.maxx && Entity.miny <= quadtree.miny && Entity.maxy >= quadtree.maxy ) check should do. You need all of those conditions to be true for the node to be able to contain the data. Thus the AND (&&).

PARTNERS