Class Grid<P extends GISPrimitive>

  • 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 Detail

      • Grid

        Grid​(int nRows,
             int nColumns,
             Rectangle2d bounds)
        Constructor.
        Parameters:
        nRows - numbers of rows in the grid
        nColumns - numbers of columns in the grid
        bounds - 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:
        true if the grid is empty; otherwise false.
      • 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 null if 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 null if no element at the specified location.
      • addElement

        public boolean addElement​(P element)
        Add the element in the grid.
        Parameters:
        element - the element.
        Returns:
        true if the element was added; otherwise false.
      • removeElement

        public boolean removeElement​(P element)
        Remove the element at the specified location.
        Parameters:
        element - the element.
        Returns:
        true if the element was removed; otherwise false.
      • 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 bounds
        createCells - 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 -1 if 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 -1 if 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​(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 -1 if 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.