Module org.arakhne.afc.gis.giscore
Package org.arakhne.afc.gis.grid
Class Grid<P extends GISPrimitive>
- java.lang.Object
-
- org.arakhne.afc.gis.grid.Grid<P>
-
- Type Parameters:
P- is the type of the user data inside the node.
- All Implemented Interfaces:
Iterable<P>
class Grid<P extends GISPrimitive> extends Object implements Iterable<P>
A grid.- Since:
- 14.0
- Version:
- 17.0 2020-01-04 14:41:53
- Author:
- Stéphane GALLAND
- See Also:
GISPrimitive- Maven Group Id:
- org.arakhne.afc.gis
- Maven Artifact Id:
- giscore
-
-
Constructor Summary
Constructors Constructor Description Grid(int nRows, int nColumns, Rectangle2d bounds)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddElement(P element)Add the element in the grid.voidclear()Clear the grid.GridCell<P>createCellAt(int row, int column)Create a cell at the specified location if there is no cell at this location.Rectangle2dgetBounds()Replies the bounds of the cell.GridCell<P>getCellAt(int row, int column)Replies the cell at the specified location.Rectangle2dgetCellBounds(int row, int column)Replies the bounds covered by a cell at the specified location.intgetCellCount()Replies the number of cells in the grid that contains an element.doublegetCellHeight()Replies the height of the cells.doublegetCellWidth()Replies the width of the cells.intgetColumnCount()Replies the number of columns in the grid.intgetColumnFor(double x)Replies the column index for the specified position.PgetElementAt(int index)Replies the element at the specified index.intgetElementCount()Replies the number of elements in the grid.Iterable<GridCell<P>>getGridCells()Replies an iterator on all the existing grid cells.AroundCellIterable<P>getGridCellsAround(Point2D<?,?> position, double maximalDistance)Replies the cells around the specified point.Iterable<GridCell<P>>getGridCellsOn(Rectangle2afp<?,?,?,?,?,?> bounds)Replies the grid cells that are intersecting the specified bounds.protected Iterable<GridCell<P>>getGridCellsOn(Rectangle2afp<?,?,?,?,?,?> bounds, boolean createCells)Replies the grid cells that are intersecting the specified bounds.intgetRowCount()Replies the number of rows in the grid.intgetRowFor(double y)Replies the row index for the specified position.intindexOf(P element)Replies the index of the specified element.booleanisEmpty()Replies if the grid is empty.Iterator<P>iterator()Iterator<P>iterator(Rectangle2afp<?,?,?,?,?,?> bounds)Replies the elements that are inside the cells intersecting the specified bounds.Iterator<P>iterator(Rectangle2afp<?,?,?,?,?,?> bounds, int budget)Replies the elements that are inside the cells intersecting the specified bounds.GridCell<P>removeCellAt(int row, int column)Remove the cell at the specified location.booleanremoveElement(P element)Remove the element at the specified location.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
Grid
Grid(int nRows, int nColumns, Rectangle2d bounds)Constructor.- Parameters:
nRows- numbers of rows in the gridnColumns- numbers of columns in the gridbounds- are the bounds of the grid cell.
-
-
Method Detail
-
getRowCount
@Pure public int getRowCount()
Replies the number of rows in the grid.- Returns:
- the number of rows in the grid.
-
getColumnCount
@Pure public int getColumnCount()
Replies the number of columns in the grid.- Returns:
- the number of columns in the grid.
-
getBounds
@Pure public Rectangle2d getBounds()
Replies the bounds of the cell.- Returns:
- the cell.
-
clear
public void clear()
Clear the grid.
-
isEmpty
@Pure public boolean isEmpty()
Replies if the grid is empty.- Returns:
trueif the grid is empty; otherwisefalse.
-
getElementCount
@Pure public int getElementCount()
Replies the number of elements in the grid.- Returns:
- the number of elements in the grid.
-
getCellAt
@Pure public GridCell<P> getCellAt(int row, int column)
Replies the cell at the specified location.- Parameters:
row- the row index.column- the column index.- Returns:
- the cell or
nullif no element at the specified location.
-
getCellBounds
@Pure public Rectangle2d getCellBounds(int row, int column)
Replies the bounds covered by a cell at the specified location.- Parameters:
row- the row index.column- the column index.- Returns:
- the bounds.
-
createCellAt
public GridCell<P> createCellAt(int row, int column)
Create a cell at the specified location if there is no cell at this location.- Parameters:
row- the row index.column- the column index.- Returns:
- the cell.
-
removeCellAt
public GridCell<P> removeCellAt(int row, int column)
Remove the cell at the specified location.- Parameters:
row- the row index.column- the column index.- Returns:
- the removed cell or
nullif no element at the specified location.
-
addElement
public boolean addElement(P element)
Add the element in the grid.- Parameters:
element- the element.- Returns:
trueif the element was added; otherwisefalse.
-
removeElement
public boolean removeElement(P element)
Remove the element at the specified location.- Parameters:
element- the element.- Returns:
trueif the element was removed; otherwisefalse.
-
getCellCount
@Pure public int getCellCount()
Replies the number of cells in the grid that contains an element.- Returns:
- the number of cells in the grid.
-
getGridCells
@Pure public Iterable<GridCell<P>> getGridCells()
Replies an iterator on all the existing grid cells.- Returns:
- the iterator.
-
getGridCellsOn
@Pure public Iterable<GridCell<P>> getGridCellsOn(Rectangle2afp<?,?,?,?,?,?> bounds)
Replies the grid cells that are intersecting the specified bounds.- Parameters:
bounds- the bounds.- Returns:
- the grid cells.
-
getGridCellsOn
protected Iterable<GridCell<P>> getGridCellsOn(Rectangle2afp<?,?,?,?,?,?> bounds, boolean createCells)
Replies the grid cells that are intersecting the specified bounds.- Parameters:
bounds- the boundscreateCells- indicates if the not already created cells should be created.- Returns:
- the grid cells.
-
getCellWidth
@Pure public double getCellWidth()
Replies the width of the cells.- Returns:
- the width of the cells.
-
getCellHeight
@Pure public double getCellHeight()
Replies the height of the cells.- Returns:
- the height of the cells.
-
getColumnFor
@Pure public int getColumnFor(double x)
Replies the column index for the specified position.- Parameters:
x- the x coordinate.- Returns:
- the column index or
-1if outside.
-
getRowFor
@Pure public int getRowFor(double y)
Replies the row index for the specified position.- Parameters:
y- y coordinate.- Returns:
- the row index or
-1if outside.
-
getGridCellsAround
@Pure public AroundCellIterable<P> getGridCellsAround(Point2D<?,?> position, double maximalDistance)
Replies the cells around the specified point. The order of the replied cells follows cocentric circles around the cell that contains the specified point.- Parameters:
position- the position.maximalDistance- is the distance above which the cells are not replied.- Returns:
- the iterator on the cells.
-
iterator
@Pure public Iterator<P> iterator()
- Specified by:
iteratorin interfaceIterable<P extends GISPrimitive>
-
iterator
@Pure public Iterator<P> iterator(Rectangle2afp<?,?,?,?,?,?> bounds)
Replies the elements that are inside the cells intersecting the specified bounds.- Parameters:
bounds- the bounds.- Returns:
- the iterator on the elements.
-
iterator
@Pure public Iterator<P> iterator(Rectangle2afp<?,?,?,?,?,?> bounds, int budget)
Replies the elements that are inside the cells intersecting the specified bounds.- Parameters:
bounds- the bounds.budget- is the number of elements to return through the iterator.- Returns:
- the iterator on the elements.
-
indexOf
@Pure public int indexOf(P element)
Replies the index of the specified element.- Parameters:
element- the element.- Returns:
- the index of the specified element or
-1if it was not found.
-
getElementAt
@Pure public P getElementAt(int index)
Replies the element at the specified index.- Parameters:
index- the index.- Returns:
- the element at the specified position.
-
-