public class SparseGrid2D extends SparseField implements Grid2D, SparseField2D
Generally speaking, if you have a grid of objects, one per location, you should use an ObjectGrid2D. If you have a large grid occupied by a few objects, or those objects can pile up on the same grid location, you should use a SparseGrid2D.
In either case, you might consider storing the location of an object IN THE OBJECT ITSELF if you need to query for the object location often -- it's faster than the hashtable lookup in SparseGrid2D, and certainly faster than searching the entire array of an ObjectGrid2D.
Boundaries. SparseGrid2D has no boundaries at all. width and height exist only to allow
you to define pseudo-boundaries for toroidal computation; and to provide typical bounds for visualization. But you can
attach any coordinate as a location for an object with no restrictions.
Setting and getting an object and its Location. The method setObjectLocation(...) methods set the location of the object
(to an Int2D or an Neighborhood Lookups. The method getObjectsAtLocationOfObject returns all Objects at the same location as the provided
object (in a Bag, which must NOT modify). The various getNeighbors...Distance(...) methods return all locations defined by certain
distance bounds, or all the objects stored at those locations. They are expensive to compute and it may be wiser to compute them by hand
if there aren't many.
SparseField.LocationAndIndex
Modifier and Type | Field and Description |
---|---|
protected int |
height |
protected int |
width |
allObjects, ANY_SIZE, INITIAL_BAG_SIZE, LARGE_BAG_RATIO, locationAndIndexHash, MIN_BAG_SIZE, objectHash, removeEmptyBags, replaceLargeBags, REPLACEMENT_BAG_RATIO
Constructor and Description |
---|
SparseGrid2D(int width,
int height) |
SparseGrid2D(SparseGrid2D values) |
Modifier and Type | Method and Description |
---|---|
int |
dlx(int x,
int y)
Hex downleft x.
|
int |
dly(int x,
int y)
Hex downleft y.
|
int |
downx(int x,
int y)
Hex down x.
|
int |
downy(int x,
int y)
Hex down y.
|
int |
drx(int x,
int y)
Hex downright x.
|
int |
dry(int x,
int y)
Hex downright y.
|
Double2D |
getDimensions()
Returns the width and height of the sparse field as a Double2D
|
int |
getHeight()
Returns the height of the grid
|
void |
getHexagonalLocations(int x,
int y,
int dist,
int mode,
boolean includeOrigin,
IntBag xPos,
IntBag yPos)
Gets all neighbors located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point
inclusive.
|
Bag |
getHexagonalNeighbors(int x,
int y,
int dist,
int mode,
boolean includeOrigin)
Determines all locations located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point
inclusive.
|
Bag |
getHexagonalNeighbors(int x,
int y,
int dist,
int mode,
boolean includeOrigin,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point
inclusive.
|
Bag |
getHexagonalNeighborsAndLocations(int x,
int y,
int dist,
int mode,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point
inclusive.
|
void |
getMooreLocations(int x,
int y,
int dist,
int mode,
boolean includeOrigin,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) <= dist.
|
Bag |
getMooreNeighbors(int x,
int y,
int dist,
int mode,
boolean includeOrigin)
Determines all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) <= dist.
|
Bag |
getMooreNeighbors(int x,
int y,
int dist,
int mode,
boolean includeOrigin,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) <= dist, This region forms a
square 2*dist+1 cells across, centered at (X,Y).
|
Bag |
getMooreNeighborsAndLocations(int x,
int y,
int dist,
int mode,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) <= dist.
|
Bag |
getNeighborsAndCorrespondingPositionsHamiltonianDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Deprecated.
|
Bag |
getNeighborsAndCorrespondingPositionsHexagonalDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Deprecated.
|
Bag |
getNeighborsAndCorrespondingPositionsMaxDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Deprecated.
|
Bag |
getNeighborsHamiltonianDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Deprecated.
|
void |
getNeighborsHamiltonianDistance(int x,
int y,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos)
Deprecated.
|
Bag |
getNeighborsHexagonalDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Deprecated.
|
void |
getNeighborsHexagonalDistance(int x,
int y,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos)
Deprecated.
|
Bag |
getNeighborsMaxDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Deprecated.
|
void |
getNeighborsMaxDistance(int x,
int y,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos)
Deprecated.
|
Int2D |
getObjectLocation(java.lang.Object obj)
Returns the object location, or null if there is no such object.
|
Double2D |
getObjectLocationAsDouble2D(java.lang.Object obj)
Returns the object location as a Double2D, or as null if there is no such object.
|
Bag |
getObjectsAtLocation(int x,
int y)
Returns a bag containing all the objects at a given location, or null when there are no objects at the location.
|
void |
getRadialLocations(int x,
int y,
double dist,
int mode,
boolean includeOrigin,
IntBag xPos,
IntBag yPos)
Gets all neighbors overlapping with a circular region centered at (X,Y) and with a radius of dist.
|
void |
getRadialLocations(int x,
int y,
double dist,
int mode,
boolean includeOrigin,
int measurementRule,
boolean closed,
IntBag xPos,
IntBag yPos)
Gets all neighbors overlapping with a circular region centered at (X,Y) and with a radius of dist.
|
Bag |
getRadialNeighbors(int x,
int y,
double dist,
int mode,
boolean includeOrigin) |
Bag |
getRadialNeighbors(int x,
int y,
double dist,
int mode,
boolean includeOrigin,
Bag result,
IntBag xPos,
IntBag yPos) |
Bag |
getRadialNeighbors(int x,
int y,
double dist,
int mode,
boolean includeOrigin,
int measurementRule,
boolean closed,
Bag result,
IntBag xPos,
IntBag yPos) |
Bag |
getRadialNeighborsAndLocations(int x,
int y,
double dist,
int mode,
boolean includeOrigin,
Bag result,
IntBag xPos,
IntBag yPos) |
Bag |
getRadialNeighborsAndLocations(int x,
int y,
double dist,
int mode,
boolean includeOrigin,
int measurementRule,
boolean closed,
Bag result,
IntBag xPos,
IntBag yPos) |
void |
getVonNeumannLocations(int x,
int y,
int dist,
int mode,
boolean includeOrigin,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) <= dist.
|
Bag |
getVonNeumannNeighbors(int x,
int y,
int dist,
int mode,
boolean includeOrigin)
Determines all neighbors of a location that satisfy abs(x-X) + abs(y-Y) <= dist.
|
Bag |
getVonNeumannNeighbors(int x,
int y,
int dist,
int mode,
boolean includeOrigin,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) <= dist.
|
Bag |
getVonNeumannNeighborsAndLocations(int x,
int y,
int dist,
int mode,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) <= dist.
|
int |
getWidth()
Returns the width of the grid
|
int |
numObjectsAtLocation(int x,
int y)
Returns the number of objects stored in the grid at the given location.
|
Bag |
removeObjectsAtLocation(int x,
int y)
Removes all the objects stored at the given location and returns them as a Bag (which you are free to modify).
|
protected void |
removeOrigin(int x,
int y,
IntBag xPos,
IntBag yPos) |
protected void |
removeOriginToroidal(int x,
int y,
IntBag xPos,
IntBag yPos) |
boolean |
setObjectLocation(java.lang.Object obj,
Int2D location)
Changes the location of an object, or adds if it doesn't exist yet.
|
boolean |
setObjectLocation(java.lang.Object obj,
int x,
int y)
Changes the location of an object, or adds if it doesn't exist yet.
|
int |
stx(int x)
Simple [and fast] toroidal x.
|
int |
sty(int y)
Simple [and fast] toroidal y.
|
boolean |
trb(int x,
int y)
Horizontal edge is on the bottom for triangle.
|
boolean |
trt(int x,
int y)
Horizontal edge is on the top for triangle.
|
int |
tx(int x)
Toroidal x.
|
int |
ty(int y)
Toroidal y.
|
int |
ulx(int x,
int y)
Hex upleft x.
|
int |
uly(int x,
int y)
Hex upleft y.
|
int |
upx(int x,
int y)
Hex up x.
|
int |
upy(int x,
int y)
Hex up y.
|
int |
urx(int x,
int y)
Hex upright x.
|
int |
ury(int x,
int y)
Hex upright y.
|
buildMap, buildMap, clear, exists, getAllObjects, getObjectIndex, getObjectsAtLocation, getObjectsAtLocationOfObject, getObjectsAtLocations, getRawObjectLocation, getRawObjectsAtLocation, iterator, locationBagIterator, numObjectsAtLocation, numObjectsAtLocationOfObject, remove, removeObjectsAtLocation, setObjectLocation, size
public SparseGrid2D(int width, int height)
public SparseGrid2D(SparseGrid2D values)
public int getWidth()
public int getHeight()
public final int tx(int x)
Grid2D
public final int ty(int y)
Grid2D
public int stx(int x)
Grid2D
public int sty(int y)
Grid2D
public int ulx(int x, int y)
Grid2D
public int uly(int x, int y)
Grid2D
public int urx(int x, int y)
Grid2D
public int ury(int x, int y)
Grid2D
public int dlx(int x, int y)
Grid2D
public int dly(int x, int y)
Grid2D
public int drx(int x, int y)
Grid2D
public int dry(int x, int y)
Grid2D
public int upx(int x, int y)
Grid2D
public int upy(int x, int y)
Grid2D
public int downx(int x, int y)
Grid2D
public int downy(int x, int y)
Grid2D
public boolean trb(int x, int y)
Grid2D
public boolean trt(int x, int y)
Grid2D
public int numObjectsAtLocation(int x, int y)
public Bag getObjectsAtLocation(int x, int y)
public Double2D getObjectLocationAsDouble2D(java.lang.Object obj)
getObjectLocationAsDouble2D
in interface SparseField2D
public Int2D getObjectLocation(java.lang.Object obj)
public Bag removeObjectsAtLocation(int x, int y)
public boolean setObjectLocation(java.lang.Object obj, int x, int y)
public boolean setObjectLocation(java.lang.Object obj, Int2D location)
public void getNeighborsMaxDistance(int x, int y, int dist, boolean toroidal, IntBag xPos, IntBag yPos)
Grid2D
This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so this function is deprecated: instead you should use the other version of this function which has more functionality. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height), that is, the width and height of the grid. if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsMaxDistance(x,y,dist,toroidal ? Grid2D.TOROIDAL : Grid2D.BOUNDED, true, xPos, yPos);
getNeighborsMaxDistance
in interface Grid2D
public void getMooreLocations(int x, int y, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos)
Grid2D
This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height), that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example, SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
getMooreLocations
in interface Grid2D
public void getNeighborsHamiltonianDistance(int x, int y, int dist, boolean toroidal, IntBag xPos, IntBag yPos)
Grid2D
This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so this function is deprecated: instead you should use the other version of this function which has more functionality. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height), that is, the width and height of the grid. if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsHamiltonianDistance(x,y,dist,toroidal ? Grid2D.TOROIDAL : Grid2D.BOUNDED, true, xPos, yPos);
getNeighborsHamiltonianDistance
in interface Grid2D
public void getVonNeumannLocations(int x, int y, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos)
Grid2D
This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height), that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example, SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
getVonNeumannLocations
in interface Grid2D
public void getNeighborsHexagonalDistance(int x, int y, int dist, boolean toroidal, IntBag xPos, IntBag yPos)
Grid2D
This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so this function is deprecated: instead you should use the other version of this function which has more functionality. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height), that is, the width and height of the grid. if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsHexagonalDistance(x,y,dist,toroidal ? Grid2D.TOROIDAL : Grid2D.BOUNDED, true, xPos, yPos);
getNeighborsHexagonalDistance
in interface Grid2D
public void getHexagonalLocations(int x, int y, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos)
Grid2D
This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height), that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example, SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
getHexagonalLocations
in interface Grid2D
public Bag getNeighborsMaxDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos)
Then places into the result Bag any Objects which fall on one of these This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so
this function is deprecated: instead you should use the other version of this function which has more functionality.
If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsMaxDistance(x,y,dist,toroidal ? Grid2D.TOROIDAL : Grid2D.BOUNDED, true, result, xPos, yPos);
public Bag getMooreNeighbors(int x, int y, int dist, int mode, boolean includeOrigin, Bag result, IntBag xPos, IntBag yPos)
Then places into the result Bag any Objects which fall on one of these This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded
neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example,
SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
public Bag getNeighborsAndCorrespondingPositionsMaxDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos)
For each Object which falls within this distance, adds the X position, Y position, and Object into the
xPos, yPos, and result Bag, clearing them first.
Some This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so
this function is deprecated: instead you should use the other version of this function which has more functionality.
If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsAndCorrespondingPositionsMaxDistance(x,y,dist,toroidal ? Grid2D.TOROIDAL : Grid2D.BOUNDED, true, result, xPos, yPos);
public Bag getMooreNeighborsAndLocations(int x, int y, int dist, int mode, Bag result, IntBag xPos, IntBag yPos)
For each Object which falls within this distance, adds the X position, Y position, and Object into the
xPos, yPos, and result Bag, clearing them first.
Some This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded
neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example,
SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
public Bag getNeighborsHamiltonianDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos)
Places each x and y value of these locations in the provided IntBags xPos and yPos, clearing the bags first.
Then places into the result Bag any Objects which fall on one of these This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so
this function is deprecated: instead you should use the other version of this function which has more functionality.
If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsHamiltonianDistance(x,y,dist,toroidal ? Grid2D.TOROIDAL : Grid2D.BOUNDED, true, result, xPos, yPos);
public Bag getVonNeumannNeighbors(int x, int y, int dist, int mode, boolean includeOrigin, Bag result, IntBag xPos, IntBag yPos)
Places each x and y value of these locations in the provided IntBags xPos and yPos, clearing the bags first.
Then places into the result Bag any Objects which fall on one of these This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded
neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example,
SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
public Bag getNeighborsAndCorrespondingPositionsHamiltonianDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos)
For each Object which falls within this distance, adds the X position, Y position, and Object into the
xPos, yPos, and result Bag, clearing them first.
Some This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so
this function is deprecated: instead you should use the other version of this function which has more functionality.
If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsAndCorrespondingPositionsHamiltonianDistance(x,y,dist,toroidal ? Grid2D.TOROIDAL : Grid2D.BOUNDED, true, result, xPos, yPos);
public Bag getVonNeumannNeighborsAndLocations(int x, int y, int dist, int mode, Bag result, IntBag xPos, IntBag yPos)
For each Object which falls within this distance, adds the X position, Y position, and Object into the
xPos, yPos, and result Bag, clearing them first.
Some This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded
neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example,
SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
public Bag getNeighborsHexagonalDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos)
Places each x and y value of these locations in the provided IntBags xPos and yPos, clearing the bags first.
Then places into the result Bag any Objects which fall on one of these This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so
this function is deprecated: instead you should use the other version of this function which has more functionality.
If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsHexagonalDistance(x,y,dist,toroidal ? Grid2D.TOROIDAL : Grid2D.BOUNDED, true, result, xPos, yPos);
public Bag getHexagonalNeighbors(int x, int y, int dist, int mode, boolean includeOrigin, Bag result, IntBag xPos, IntBag yPos)
Places each x and y value of these locations in the provided IntBags xPos and yPos, clearing the bags first.
Then places into the result Bag any Objects which fall on one of these This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded
neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example,
SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
public Bag getNeighborsAndCorrespondingPositionsHexagonalDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos)
For each Object which falls within this distance, adds the X position, Y position, and Object into the
xPos, yPos, and result Bag, clearing them first.
Some This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so
this function is deprecated: instead you should use the other version of this function which has more functionality.
If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsAndCorrespondingPositionsHexagonalDistance(x,y,dist,toroidal ? Grid2D.TOROIDAL : Grid2D.BOUNDED, true, result, xPos, yPos);
public Bag getHexagonalNeighborsAndLocations(int x, int y, int dist, int mode, Bag result, IntBag xPos, IntBag yPos)
For each Object which falls within this distance, adds the X position, Y position, and Object into the
xPos, yPos, and result Bag, clearing them first.
Some This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded
neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example,
SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
public void getRadialLocations(int x, int y, double dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos)
Grid2D
Places each x and y value of these locations in the provided IntBags xPos and yPos, clearing the bags first.
This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height), that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example, SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
getRadialLocations
in interface Grid2D
public void getRadialLocations(int x, int y, double dist, int mode, boolean includeOrigin, int measurementRule, boolean closed, IntBag xPos, IntBag yPos)
Grid2D
Places each x and y value of these locations in the provided IntBags xPos and yPos, clearing the bags first.
This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height), that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example, SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y) point at the center of the neighborhood -- in the neighborhood results.
getRadialLocations
in interface Grid2D
public Bag getRadialNeighbors(int x, int y, double dist, int mode, boolean includeOrigin, Bag result, IntBag xPos, IntBag yPos)
public Bag getRadialNeighborsAndLocations(int x, int y, double dist, int mode, boolean includeOrigin, Bag result, IntBag xPos, IntBag yPos)
public Bag getRadialNeighbors(int x, int y, double dist, int mode, boolean includeOrigin, int measurementRule, boolean closed, Bag result, IntBag xPos, IntBag yPos)
public Bag getRadialNeighborsAndLocations(int x, int y, double dist, int mode, boolean includeOrigin, int measurementRule, boolean closed, Bag result, IntBag xPos, IntBag yPos)
public Bag getMooreNeighbors(int x, int y, int dist, int mode, boolean includeOrigin)
Then returns, as a Bag, any Objects which fall on one of these This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded
neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example,
SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
public Bag getVonNeumannNeighbors(int x, int y, int dist, int mode, boolean includeOrigin)
Then returns, as a Bag, any Objects which fall on one of these This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded
neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example,
SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
public Bag getHexagonalNeighbors(int x, int y, int dist, int mode, boolean includeOrigin)
Then returns, as a Bag, any Objects which fall on one of these This function may be run in one of three modes: Grid2D.BOUNDED, Grid2D.UNBOUNDED, and Grid2D.TOROIDAL. If "bounded",
then the neighbors are restricted to be only those which lie within the box ranging from (0,0) to (width, height),
that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded
neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example,
SparseGrid2D permits this but ObjectGrid2D and DoubleGrid2D and IntGrid2D and DenseGrid2D do not. Finally if "toroidal",
then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal
locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around
the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to
resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
public Bag getRadialNeighbors(int x, int y, double dist, int mode, boolean includeOrigin)
public final Double2D getDimensions()
SparseField2D
getDimensions
in interface SparseField2D