Class SparseGrid2D
- All Implemented Interfaces:
Serializable
,Grid2D
,SparseField2D
- SparseGrid2D can store more than one object at a location. ObjectGrid2D cannot.
- ObjectGrid2D can store an object at more than one location (though it's bad form!).
- SparseGrid2D can efficiently (O(1)) tell you the location of an object.
- SparseGrid2D can efficiently (O(#objs)) scan through all objects. The best you can do with ObjectGrid2D is search its array (which might have many empty slots).
- Storing an object, finding its location, or changing its location, in a SparseGrid2D is O(1) but requires several Map lookups and/or removes, which has a significant constant overhead.
- SparseGrid2D can associate objects with any 2D integer location. ObjectGrid2D's locations are restricted to be within its array.
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 invalid input: '<'x,y> location). The method getObjectsAtLocation(Object location), inherited from SparseField, returns a Bag (which you MUST NOT modify) containing all objects at a given location (which must be provided in the form of an Int2D or MutableInt2D). The numObjectsAtLocation(location) method returns the number of such objects. The getObjectsAtLocations(Bag locations, Bag putInHere) gathers objects at a variety of locations and puts them in the bag you provide. The getAllObjects() method returns all objects in a bag you must NOT modiify. The removeObjectsAtLocation(Object location) method removes and returns all objects at a given location (defined as an Int2D or MutableDouble2D). The exists method tells you if the object exists in the field.
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.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class sim.field.SparseField
SparseField.LocationAndIndex
-
Field Summary
Fields inherited from class sim.field.SparseField
allObjects, ANY_SIZE, INITIAL_BAG_SIZE, LARGE_BAG_RATIO, locationAndIndexHash, MIN_BAG_SIZE, objectHash, removeEmptyBags, replaceLargeBags, REPLACEMENT_BAG_RATIO
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
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.final Double2D
Returns the width and height of the sparse field as a Double2Dint
Returns the height of the gridvoid
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.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.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.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) ) invalid input: '<'= dist.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) ) invalid input: '<'= dist.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) ) invalid input: '<'= dist, This region forms a square 2*dist+1 cells across, centered at (X,Y).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) ) invalid input: '<'= dist.getNeighborsAndCorrespondingPositionsHamiltonianDistance
(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos) Deprecated.getNeighborsAndCorrespondingPositionsHexagonalDistance
(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos) Deprecated.getNeighborsAndCorrespondingPositionsMaxDistance
(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos) Deprecated.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.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.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.getObjectLocation
(Object obj) Returns the object location, or null if there is no such object.Returns the object location as a Double2D, or as null if there is no such object.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, 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.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.getRadialNeighbors
(int x, int y, double dist, int mode, boolean includeOrigin) getRadialNeighbors
(int x, int y, double dist, int mode, boolean includeOrigin, int measurementRule, boolean closed, Bag result, IntBag xPos, IntBag yPos) getRadialNeighbors
(int x, int y, double dist, int mode, boolean includeOrigin, Bag result, IntBag xPos, IntBag yPos) getRadialNeighborsAndLocations
(int x, int y, double dist, int mode, boolean includeOrigin, int measurementRule, boolean closed, Bag result, IntBag xPos, IntBag yPos) getRadialNeighborsAndLocations
(int x, int y, double dist, int mode, boolean includeOrigin, 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) invalid input: '<'= dist.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) invalid input: '<'= dist.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) invalid input: '<'= dist.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) invalid input: '<'= dist.int
getWidth()
Returns the width of the gridint
numObjectsAtLocation
(int x, int y) Returns the number of objects stored in the grid at the given location.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) void
reshape
(int width, int height) Entirely wipes the grid and reshapes it into a different sized rectangle.boolean
setObjectLocation
(Object obj, int x, int y) Changes the location of an object, or adds if it doesn't exist yet.boolean
setObjectLocation
(Object obj, Int2D location) 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.final int
tx
(int x) Toroidal x.final 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.Methods inherited from class sim.field.SparseField
buildMap, buildMap, clear, exists, getAllObjects, getObjectIndex, getObjectsAtLocation, getObjectsAtLocationOfObject, getObjectsAtLocations, getRawObjectLocation, getRawObjectsAtLocation, iterator, locationBagIterator, numObjectsAtLocation, numObjectsAtLocationOfObject, remove, removeObjectsAtLocation, setObjectLocation, size
-
Field Details
-
width
protected int width -
height
protected int height
-
-
Constructor Details
-
SparseGrid2D
public SparseGrid2D(int width, int height) -
SparseGrid2D
-
-
Method Details
-
reshape
public void reshape(int width, int height) Description copied from interface:Grid2D
Entirely wipes the grid and reshapes it into a different sized rectangle. You should generally not call this: it's used for exotic purposes such as in Distributed MASON. -
getWidth
public int getWidth()Returns the width of the grid -
getHeight
public int getHeight()Returns the height of the grid -
tx
public final int tx(int x) Description copied from interface:Grid2D
Toroidal x. The following definition:
final int length = this.length;
if (z >= 0) return (z % length);
final int length2 = (z % length) + length;
if (length2 < length) return length2;
return 0;
... produces the correct code and is 27 bytes, so it's likely to be inlined in Hotspot for 1.4.1. -
ty
public final int ty(int y) Description copied from interface:Grid2D
Toroidal y. The following definition:
final int length = this.length;
if (z >= 0) return (z % length);
final int length2 = (z % length) + length;
if (length2 invalid input: '<' length) return length2;
return 0;
... produces the correct code and is 27 bytes, so it's likely to be inlined in Hotspot for 1.4.1. -
stx
public int stx(int x) Description copied from interface:Grid2D
Simple [and fast] toroidal x. Use this if the values you'd pass in never stray beyond (-width ... width * 2) not inclusive. It's a bit faster than the full toroidal computation as it uses if statements rather than two modulos. The following definition:
{ int width = this.width; if (x >= 0) { if (x invalid input: '<' width) return x; return x - width; } return x + width; } ...produces the shortest code (24 bytes) and is inlined in Hotspot for 1.4.1. However in most cases removing the int width = this.width; is likely to be a little faster if most objects are usually within the toroidal region. -
sty
public int sty(int y) Description copied from interface:Grid2D
Simple [and fast] toroidal y. Use this if the values you'd pass in never stray beyond (-height ... height * 2) not inclusive. It's a bit faster than the full toroidal computation as it uses if statements rather than two modulos. The following definition:
{ int height = this.height; if (y >= 0) { if (y invalid input: '<' height) return y ; return y - height; } return y + height; } ...produces the shortest code (24 bytes) and is inlined in Hotspot for 1.4.1. However in most cases removing the int height = this.height; is likely to be a little faster if most objects are usually within the toroidal region. -
ulx
public int ulx(int x, int y) Description copied from interface:Grid2D
Hex upleft x. -
uly
public int uly(int x, int y) Description copied from interface:Grid2D
Hex upleft y. -
urx
public int urx(int x, int y) Description copied from interface:Grid2D
Hex upright x. -
ury
public int ury(int x, int y) Description copied from interface:Grid2D
Hex upright y. -
dlx
public int dlx(int x, int y) Description copied from interface:Grid2D
Hex downleft x. -
dly
public int dly(int x, int y) Description copied from interface:Grid2D
Hex downleft y. -
drx
public int drx(int x, int y) Description copied from interface:Grid2D
Hex downright x. -
dry
public int dry(int x, int y) Description copied from interface:Grid2D
Hex downright y. -
upx
public int upx(int x, int y) Description copied from interface:Grid2D
Hex up x. -
upy
public int upy(int x, int y) Description copied from interface:Grid2D
Hex up y. -
downx
public int downx(int x, int y) Description copied from interface:Grid2D
Hex down x. -
downy
public int downy(int x, int y) Description copied from interface:Grid2D
Hex down y. -
trb
public boolean trb(int x, int y) Description copied from interface:Grid2D
Horizontal edge is on the bottom for triangle. True if x + y is odd. One definition of this is return ((x + y) invalid input: '&' 1) == 1; -
trt
public boolean trt(int x, int y) Description copied from interface:Grid2D
Horizontal edge is on the top for triangle. True if x + y is even. One definition of this is return ((x + y) invalid input: '&' 1) == 0; -
removeOrigin
-
removeOriginToroidal
-
numObjectsAtLocation
public int numObjectsAtLocation(int x, int y) Returns the number of objects stored in the grid at the given location. -
getObjectsAtLocation
Returns a bag containing all the objects at a given location, or null when there are no objects at the location. You should NOT MODIFY THIS BAG. This is the actual container bag, and modifying it will almost certainly break the Sparse Field object. If you want to modify the bag, make a copy and modify the copy instead, using something along the lines of new Bag(foo.getObjectsAtLocation(location)) . Furthermore, changing values in the Sparse Field may result in a different bag being used -- so you should not rely on this bag staying valid. -
getObjectLocationAsDouble2D
Returns the object location as a Double2D, or as null if there is no such object.- Specified by:
getObjectLocationAsDouble2D
in interfaceSparseField2D
-
getObjectLocation
Returns the object location, or null if there is no such object. -
removeObjectsAtLocation
Removes all the objects stored at the given location and returns them as a Bag (which you are free to modify). -
setObjectLocation
Changes the location of an object, or adds if it doesn't exist yet. Returns false if the object is null (null objects cannot be put into the grid). -
setObjectLocation
Changes the location of an object, or adds if it doesn't exist yet. Returns false if the object is null (null objects cannot be put into the grid) or if the location is null. -
getNeighborsMaxDistance
public void getNeighborsMaxDistance(int x, int y, int dist, boolean toroidal, IntBag xPos, IntBag yPos) Deprecated.Description copied from interface:Grid2D
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) invalid input: '<'= dist. This region forms a square 2*dist+1 cells across, centered at (X,Y). If dist==1, this is equivalent to the so-called "Moore Neighborhood" (the eight neighbors surrounding (X,Y)), plus (X,Y) itself. Places each x and y value of these locations in the provided IntBags xPos and yPos, clearing the bags first.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);
- Specified by:
getNeighborsMaxDistance
in interfaceGrid2D
-
getMooreLocations
public void getMooreLocations(int x, int y, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos) Description copied from interface:Grid2D
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) invalid input: '<'= dist. This region forms a square 2*dist+1 cells across, centered at (X,Y). If dist==1, this is equivalent to the so-called "Moore Neighborhood" (the eight neighbors surrounding (X,Y)), plus (X,Y) itself. 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.
- Specified by:
getMooreLocations
in interfaceGrid2D
-
getNeighborsHamiltonianDistance
public void getNeighborsHamiltonianDistance(int x, int y, int dist, boolean toroidal, IntBag xPos, IntBag yPos) Deprecated.Description copied from interface:Grid2D
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) invalid input: '<'= dist. This region forms a diamond 2*dist+1 cells from point to opposite point inclusive, centered at (X,Y). If dist==1 this is equivalent to the so-called "Von-Neumann Neighborhood" (the four neighbors above, below, left, and right of (X,Y)), plus (X,Y) itself. Places each x and y value of these locations in the provided IntBags xPos and yPos, clearing the bags first.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);
- Specified by:
getNeighborsHamiltonianDistance
in interfaceGrid2D
-
getVonNeumannLocations
public void getVonNeumannLocations(int x, int y, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos) Description copied from interface:Grid2D
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) invalid input: '<'= dist. This region forms a diamond 2*dist+1 cells from point to opposite point inclusive, centered at (X,Y). If dist==1 this is equivalent to the so-called "Von-Neumann Neighborhood" (the four neighbors above, below, left, and right of (X,Y)), plus (X,Y) itself. 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.
- Specified by:
getVonNeumannLocations
in interfaceGrid2D
-
getNeighborsHexagonalDistance
public void getNeighborsHexagonalDistance(int x, int y, int dist, boolean toroidal, IntBag xPos, IntBag yPos) Deprecated.Description copied from interface:Grid2D
Gets all neighbors located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point inclusive. If dist==1, this is equivalent to the six neighbors immediately surrounding (X,Y), plus (X,Y) itself. Places each x and y value of these locations in the provided IntBags xPos and yPos, clearing the bags first.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);
- Specified by:
getNeighborsHexagonalDistance
in interfaceGrid2D
-
getHexagonalLocations
public void getHexagonalLocations(int x, int y, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos) Description copied from interface:Grid2D
Gets all neighbors located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point inclusive. If dist==1, this is equivalent to the six neighbors immediately surrounding (X,Y), plus (X,Y) itself. 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.
- Specified by:
getHexagonalLocations
in interfaceGrid2D
-
getNeighborsMaxDistance
public Bag getNeighborsMaxDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos) Deprecated.Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) invalid input: '<'= dist, This region forms a square 2*dist+1 cells across, centered at (X,Y). If dist==1, this is equivalent to the so-called "Moore Neighborhood" (the eight neighbors surrounding (X,Y)), plus (X,Y) itself. 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 invalid input: '<'x,y> locations, clearning it first. Note that the order and size of the result Bag may not correspond to the X and Y bags. If you want all three bags to correspond (x, y, object) then use getNeighborsAndCorrespondingPositionsMaxDistance(...) Returns the result Bag. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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);
-
getMooreNeighbors
public 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) ) invalid input: '<'= dist, This region forms a square 2*dist+1 cells across, centered at (X,Y). If dist==1, this is equivalent to the so-called "Moore Neighborhood" (the eight neighbors surrounding (X,Y)), plus (X,Y) itself. 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 invalid input: '<'x,y> locations, clearning it first. Note that the order and size of the result Bag may not correspond to the X and Y bags. If you want all three bags to correspond (x, y, object) then use getNeighborsAndCorrespondingPositionsMaxDistance(...) Returns the result Bag. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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.
-
getNeighborsAndCorrespondingPositionsMaxDistance
public Bag getNeighborsAndCorrespondingPositionsMaxDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos) Deprecated.Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) invalid input: '<'= dist. This region forms a square 2*dist+1 cells across, centered at (X,Y). If dist==1, this is equivalent to the so-called "Moore Neighborhood" (the eight neighbors surrounding (X,Y)), plus (X,Y) itself.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 invalid input: '<'X,Y> positions may not appear and that others may appear multiply if multiple objects share that positions. Compare this function with getNeighborsMaxDistance(...). Returns the result Bag. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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);
-
getMooreNeighborsAndLocations
public 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) ) invalid input: '<'= dist. This region forms a square 2*dist+1 cells across, centered at (X,Y). If dist==1, this is equivalent to the so-called "Moore Neighborhood" (the eight neighbors surrounding (X,Y)), plus (X,Y) itself.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 invalid input: '<'X,Y> positions may not appear and that others may appear multiply if multiple objects share that positions. Compare this function with getNeighborsMaxDistance(...). Returns the result Bag. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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.
-
getNeighborsHamiltonianDistance
public Bag getNeighborsHamiltonianDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos) Deprecated.Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) invalid input: '<'= dist. This region forms a diamond 2*dist+1 cells from point to opposite point inclusive, centered at (X,Y). If dist==1 this is equivalent to the so-called "Von-Neumann Neighborhood" (the four neighbors above, below, left, and right of (X,Y)), plus (X,Y) itself.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 invalid input: '<'x,y> locations, clearning it first. Note that the order and size of the result Bag may not correspond to the X and Y bags. If you want all three bags to correspond (x, y, object) then use getNeighborsAndCorrespondingPositionsHamiltonianDistance(...) Returns the result Bag (constructing one if null had been passed in). null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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);
-
getVonNeumannNeighbors
public 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) invalid input: '<'= dist. This region forms a diamond 2*dist+1 cells from point to opposite point inclusive, centered at (X,Y). If dist==1 this is equivalent to the so-called "Von-Neumann Neighborhood" (the four neighbors above, below, left, and right of (X,Y)), plus (X,Y) itself.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 invalid input: '<'x,y> locations, clearning it first. Note that the order and size of the result Bag may not correspond to the X and Y bags. If you want all three bags to correspond (x, y, object) then use getNeighborsAndCorrespondingPositionsHamiltonianDistance(...) Returns the result Bag (constructing one if null had been passed in). null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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.
-
getNeighborsAndCorrespondingPositionsHamiltonianDistance
public Bag getNeighborsAndCorrespondingPositionsHamiltonianDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos) Deprecated.Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) invalid input: '<'= dist. This region forms a diamond 2*dist+1 cells from point to opposite point inclusive, centered at (X,Y). If dist==1 this is equivalent to the so-called "Von-Neumann Neighborhood" (the four neighbors above, below, left, and right of (X,Y)), plus (X,Y) itself.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 invalid input: '<'X,Y> positions may not appear and that others may appear multiply if multiple objects share that positions. Compare this function with getNeighborsMaxDistance(...). Returns the result Bag. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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);
-
getVonNeumannNeighborsAndLocations
public 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) invalid input: '<'= dist. This region forms a diamond 2*dist+1 cells from point to opposite point inclusive, centered at (X,Y). If dist==1 this is equivalent to the so-called "Von-Neumann Neighborhood" (the four neighbors above, below, left, and right of (X,Y)), plus (X,Y) itself.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 invalid input: '<'X,Y> positions may not appear and that others may appear multiply if multiple objects share that positions. Compare this function with getNeighborsMaxDistance(...). Returns the result Bag. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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.
-
getNeighborsHexagonalDistance
public Bag getNeighborsHexagonalDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos) Deprecated.Gets all neighbors located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point inclusive. If dist==1, this is equivalent to the six neighbors immediately surrounding (X,Y), plus (X,Y) itself.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 invalid input: '<'x,y> locations, clearning it first. Note that the order and size of the result Bag may not correspond to the X and Y bags. If you want all three bags to correspond (x, y, object) then use getNeighborsAndCorrespondingPositionsHamiltonianDistance(...) Returns the result Bag (constructing one if null had been passed in). null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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);
-
getHexagonalNeighbors
public 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. If dist==1, this is equivalent to the six neighbors immediately surrounding (X,Y), plus (X,Y) itself.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 invalid input: '<'x,y> locations, clearning it first. Note that the order and size of the result Bag may not correspond to the X and Y bags. If you want all three bags to correspond (x, y, object) then use getNeighborsAndCorrespondingPositionsHamiltonianDistance(...) Returns the result Bag (constructing one if null had been passed in). null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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.
-
getNeighborsAndCorrespondingPositionsHexagonalDistance
public Bag getNeighborsAndCorrespondingPositionsHexagonalDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos) Deprecated.Gets all neighbors located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point inclusive. If dist==1, this is equivalent to the six neighbors immediately surrounding (X,Y), plus (X,Y) itself.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 invalid input: '<'X,Y> positions may not appear and that others may appear multiply if multiple objects share that positions. Compare this function with getNeighborsMaxDistance(...). Returns the result Bag. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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);
-
getHexagonalNeighborsAndLocations
public 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. If dist==1, this is equivalent to the six neighbors immediately surrounding (X,Y), plus (X,Y) itself.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 invalid input: '<'X,Y> positions may not appear and that others may appear multiply if multiple objects share that positions. Compare this function with getNeighborsMaxDistance(...). Returns the result Bag. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.
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
public void getRadialLocations(int x, int y, double dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos) Description copied from interface:Grid2D
Gets all neighbors overlapping with a circular region centered at (X,Y) and with a radius of dist. The measurement rule is Grid2D.ANY, meaning those cells which overlap at all with the region. The region is closed, meaning that that points which touch on the outer surface of the circle will be considered members of the region.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.
- Specified by:
getRadialLocations
in interfaceGrid2D
-
getRadialLocations
public void getRadialLocations(int x, int y, double dist, int mode, boolean includeOrigin, int measurementRule, boolean closed, IntBag xPos, IntBag yPos) Description copied from interface:Grid2D
Gets all neighbors overlapping with a circular region centered at (X,Y) and with a radius of dist. If measurementRule is Grid2D.CENTER, then the measurement rule will be those cells whose centers overlap with the region. If measurementRule is Grid2D.ALL, then the measurement rule will be those cells which entirely overlap with the region. If measurementrule is Grid2D.ANY, then the measurement rule will be those cells which overlap at all with the region. If closed is true, then the region will be considered "closed", that is, that points which touch on the outer surface of the circle will be considered members of the region. If closed is open, then the region will be considered "open", that is, that points which touch on the outer surface of the circle will NOT be considered members of the region.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.
- Specified by:
getRadialLocations
in interfaceGrid2D
-
getRadialNeighbors
-
getRadialNeighborsAndLocations
-
getRadialNeighbors
-
getRadialNeighborsAndLocations
-
getMooreNeighbors
Determines all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) invalid input: '<'= dist. This region forms a square 2*dist+1 cells across, centered at (X,Y). If dist==1, this is equivalent to the so-called "Moore Neighborhood" (the eight neighbors surrounding (X,Y)), plus (X,Y) itself.Then returns, as a Bag, any Objects which fall on one of these invalid input: '<'x,y> locations.
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.
-
getVonNeumannNeighbors
Determines all neighbors of a location that satisfy abs(x-X) + abs(y-Y) invalid input: '<'= dist. This region forms a diamond 2*dist+1 cells from point to opposite point inclusive, centered at (X,Y). If dist==1 this is equivalent to the so-called "Von-Neumann Neighborhood" (the four neighbors above, below, left, and right of (X,Y)), plus (X,Y) itself.Then returns, as a Bag, any Objects which fall on one of these invalid input: '<'x,y> locations.
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.
-
getHexagonalNeighbors
Determines all locations located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point inclusive. If dist==1, this is equivalent to the six neighboring locations immediately surrounding (X,Y), plus (X,Y) itself.Then returns, as a Bag, any Objects which fall on one of these invalid input: '<'x,y> locations.
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.
-
getRadialNeighbors
-
getDimensions
Description copied from interface:SparseField2D
Returns the width and height of the sparse field as a Double2D- Specified by:
getDimensions
in interfaceSparseField2D
-