Okay, the issue is as follows. The bug (or more correctly, corner case) is triggered when:
- You use toroidal lookup
- Your distance measure is inappropriately large for the field.
In your example, you had a 10x10 field but a 5-distance lookup, which is huge for this grid. Consider the width of the rectangle region that's looked up. At 5, the width is 5 left, 5 right, and the center location, for a total of 11 units wide. But the field is only 10 units wide! So what's happening is that one of the units is wrapping toroidally over to the other side, resulting in a few grid squares being looked up twice.
I have attached a new AbstractGrid2D and SparseGrid2D which should fix the problem. For rectangular regions ("max"), they just truncate the distance to an appropriate size. For diamond and hexagonal regions ("hamiltonian" and "hex"), you can't do that so easily, so instead if the distance is too large, they have to run all the locations through a hash table to remove duplicates. This has a big constant overhead, so long story short, don't do this on hamiltonian and hex regions.
I'l get this on SVN when I get home, but I *think* the attached code should work correctly.
Sean
|