MapPolylineGridSet extends MapElementGridSet<P> implements GISPolylineSet<P> { @Override @Pure public final P getNearestEnd(double x, double y) { return getNearestEnd(new Point2d(x, y)); } MapPolylineGridSet(int nRows, int nColumns, double boundsX, double boundsY, double boundsWidth, double boundsHeight);  MapPolylineGridSet(int nRows, int nColumns, Rectangle2d bounds); @Override boolean add(P polyline, double precision,
			OutputParameter<P> firstNeighbour,
			OutputParameter<P> secondNeighbour); @Override @Pure final P getNearestEnd(double x, double y); @Override @Pure P getNearestEnd(Point2D<?, ?> position);  }
@Test public void testGetNearestEnd() { assertNotNull(this.bounds); MapPolylineGridSet<MapPolyline> test = new MapPolylineGridSet<>(100,100,this.bounds); test.addAll(this.reference); assertEquals(this.reference.size(), test.size()); Random rnd = new Random(); MapPolyline nearestData; double minDistance, distance, x, y; final ArrayList<MapPolyline> nearest = new ArrayList<>(); x = rnd.nextDouble()*this.bounds.getWidth()+this.bounds.getMinX(); y = rnd.nextDouble()*this.bounds.getHeight()+this.bounds.getMinY(); minDistance = Double.MAX_VALUE; for (MapPolyline line : this.reference) { distance = line.distanceToEnd(new Point2d(x, y)); if (distance<minDistance) { minDistance = distance; nearest.clear(); nearest.add(line); } else if (distance==minDistance) { nearest.add(line); } } nearestData = test.getNearestEnd(x, y); assertNotNull(nearestData); assertTrue(nearest.contains(nearestData)); }