I have a separate bug to report in "getNeighborsMaxDistance" and related

The methods include two mutable IntBags "xPos" and "yPos" that are supposed
to be filled with "each x and y value of these locations in the provided
IntBags xPos and yPos, clearing the bags first" (quoted from the ClassDoc).

The bug is that these bags are filled with EVERY x and y location within the
range of maxDistance, not just the x and y locations of objects found in the

The problem seems to arise because of the interplay between the void method
"getNeighborsMaxDistance", which loads the IntBags "xPos" and "yPos" with
all values in the neighborhood, and the method
"getObjectsAtLocations(xPos,yPos,result)", which returns a bag with objects
found within that neighborhood, but DOES NOT modify xPos or yPos bags with
the object locations, as it should.

Here's the code from lines 524-546 of SparseGrid2D. Notice that xPos and
yPos are not updated with object locations:

public Bag getObjectsAtLocations(final IntBag xPos, final IntBag yPos, Bag
        if (result==null) result = new Bag();
        else result.clear();

        final int len = xPos.numObjs;
        final int[] xs = xPos.objs;
        final int[] ys = yPos.objs;
        for(int i=0; i < len; i++)
            // a little efficiency: add if we're 1, addAll if we're > 1,
            // do nothing if we're 0
            Bag temp = getObjectsAtLocation(xs[i],ys[i]);
            if (temp!=null)
                int n = temp.numObjs;
                if (n==1) result.add(temp.objs[0]);
                else if (n > 1) result.addAll(temp);
        return result;
Russ Thomas

On 8/9/12 10:08 AM, "Chris Hollander" <[log in to unmask]> wrote:

> So, I'm not sure if this is a bug or intended... and it's been around
> for a LONG time, so it might be fixed already on the SVN... but when
> you call getNeighborsMaxDistance with a sufficiently large distance
> (say, the size of the grid width or height), you get duplicates in the
> returned bag.
> So if I have 10 agents with a unique ID 1, 2, .. 10 on a 10x10 grid
> and I call getNeighborsMaxDistance with a radius of 10, I'll get back
> a bag that has multiple copies of each agent... which means I can't
> exactly iterate over the raw bag. Of course, this is easy enough to
> handle by simply dumping all the elements in the bag in to a set, but
> should that have to be done? Shouldn't the returned list of neighbors
> be guaranteed to not contain duplicates?
> Christopher Hollander
> University of Central Florida