Grid implements Iterable<P> { @Pure public AroundCellIterable<P> getGridCellsAround(Point2D<?, ?> position, double maximalDistance) { final int column = getColumnFor(position.getX()); final int row = getRowFor(position.getY()); return new AroundIterable(row, column, position, maximalDistance); } @SuppressWarnings("unchecked")  Grid(int nRows, int nColumns, Rectangle2d bounds); @Override @Pure String toString(); @Pure int getRowCount(); @Pure int getColumnCount(); @Pure Rectangle2d getBounds(); @SuppressWarnings("unchecked") void clear(); @Pure boolean isEmpty(); @Pure int getElementCount(); @Pure GridCell<P> getCellAt(int row, int column); @Pure Rectangle2d getCellBounds(int row, int column); GridCell<P> createCellAt(int row, int column); GridCell<P> removeCellAt(int row, int column); boolean addElement(P element); boolean removeElement(P element); @Pure int getCellCount(); @Pure Iterable<GridCell<P>> getGridCells(); @Pure Iterable<GridCell<P>> getGridCellsOn(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds); @Pure double getCellWidth(); @Pure double getCellHeight(); @Pure int getColumnFor(double x); @Pure int getRowFor(double y); @Pure AroundCellIterable<P> getGridCellsAround(Point2D<?, ?> position, double maximalDistance); @Override @Pure Iterator<P> iterator(); @Pure Iterator<P> iterator(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds); @Pure Iterator<P> iterator(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds, int budget); @Pure int indexOf(P element); @Pure P getElementAt(int index);  }
@Test public void testGetGridCellsAround() { GridCell<MapPoint> cell; AroundCellIterable<MapPoint> iterable = this.grid.getGridCellsAround(new Point2d(480, 230), Double.POSITIVE_INFINITY); AroundCellIterator<MapPoint> iterator = iterable.aroundIterator(); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(7, cell.column()); assertEquals(0, cell.row()); assertEquals(3, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(8, cell.column()); assertEquals(0, cell.row()); assertEquals(4, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(0, cell.column()); assertEquals(0, cell.row()); assertEquals(4, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(0, cell.column()); assertEquals(7, cell.row()); assertEquals(5, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(1, cell.column()); assertEquals(7, cell.row()); assertEquals(5, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(4, cell.column()); assertEquals(7, cell.row()); assertEquals(5, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(5, cell.column()); assertEquals(7, cell.row()); assertEquals(5, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(0, cell.column()); assertEquals(8, cell.row()); assertEquals(6, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(1, cell.column()); assertEquals(8, cell.row()); assertEquals(6, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(4, cell.column()); assertEquals(8, cell.row()); assertEquals(6, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(5, cell.column()); assertEquals(8, cell.row()); assertEquals(6, iterator.getLevel()); assertTrue(iterator.hasNext()); cell = iterator.next(); assertNotNull(cell); assertEquals(9, cell.column()); assertEquals(9, cell.row()); assertEquals(7, iterator.getLevel()); assertFalse(iterator.hasNext()); }