|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsim.field.grid.AbstractGrid2D
sim.field.grid.ObjectGrid2D
A wrapper for 2D arrays of Objects.
This object expects that the 2D arrays are rectangular. You are encouraged to access the array directly. The object implements all of the Grid2D interface. See Grid2D for rules on how to properly implement toroidal or hexagonal grids.
The width and height of the object are provided to avoid having to say field[x].length, etc.
We very strongly encourage you to examine SparseGrid2D first to see if it's more appropriate to your task. If you need arbitrary numbers of Objects to be able to occupy the same location in the grid, or if you have very few Objects and a very large grid, or if your space is unbounded, you should probably use SparseGrid2D instead.
Field Summary | |
java.lang.Object[][] |
field
|
Fields inherited from class sim.field.grid.AbstractGrid2D |
height, width |
Constructor Summary | |
ObjectGrid2D(int width,
int height)
|
|
ObjectGrid2D(int width,
int height,
java.lang.Object initialValue)
|
|
ObjectGrid2D(ObjectGrid2D values)
|
Method Summary | |
Bag |
clear()
Sets all the locations in the grid to null, and returns in a Bag all stored objects (including duplicates but not null values). |
java.lang.Object |
get(int x,
int y)
Returns the element at location (x,y) |
Bag |
getNeighborsHamiltonianDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) <= dist. |
Bag |
getNeighborsHexagonalDistance(int x,
int y,
int dist,
boolean toroidal,
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 |
getNeighborsMaxDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) <= dist. |
void |
set(int x,
int y,
java.lang.Object val)
Sets location (x,y) to val |
ObjectGrid2D |
setTo(java.lang.Object thisObj)
Sets all the locations in the grid the provided element |
ObjectGrid2D |
setTo(ObjectGrid2D values)
Changes the dimensions of the grid to be the same as the one provided, then sets all the locations in the grid to the elements at the quivalent locations in the provided grid. |
Methods inherited from class sim.field.grid.AbstractGrid2D |
dlx, dly, downx, downy, drx, dry, getHeight, getNeighborsHamiltonianDistance, getNeighborsHexagonalDistance, getNeighborsMaxDistance, getWidth, stx, sty, trb, trt, tx, ty, ulx, uly, upx, upy, urx, ury |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public java.lang.Object[][] field
Constructor Detail |
public ObjectGrid2D(int width, int height)
public ObjectGrid2D(int width, int height, java.lang.Object initialValue)
public ObjectGrid2D(ObjectGrid2D values)
Method Detail |
public final void set(int x, int y, java.lang.Object val)
public final java.lang.Object get(int x, int y)
public final ObjectGrid2D setTo(java.lang.Object thisObj)
public final Bag clear()
public final ObjectGrid2D setTo(ObjectGrid2D values)
public final Bag getNeighborsMaxDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos)
public final Bag getNeighborsHamiltonianDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos)
public final Bag getNeighborsHexagonalDistance(int x, int y, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |