MapPolylineGridSet extends MapElementGridSet<P> implements GISPolylineSet<P> { @Override public boolean add(P polyline, double precision, OutputParameter<P> firstNeighbour, OutputParameter<P> secondNeighbour) { if (add(polyline)) { Point2d point; point = polyline.getPointAt(0); if (point != null) { firstNeighbour.set(getNearestEnd(polyline, point, precision)); } point = polyline.getPointAt(polyline.getPointCount() - 1); if (point != null) { secondNeighbour.set(getNearestEnd(polyline, point, precision)); } return true; } return false; } 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 testAddPDoubleOutputParameterOutputParameter() { assertNotNull(this.bounds); MapPolylineGridSet<MapPolyline> test = new MapPolylineGridSet<>(100,100,this.bounds); test.addAll(this.reference); assertEquals(this.reference.size(), test.size()); OutputParameter<MapPolyline> first = new OutputParameter<>(); OutputParameter<MapPolyline> second = new OutputParameter<>(); MapPolyline polyline; Point2d p1, p2; first.clear(); second.clear(); polyline = new MapPolyline(); p1 = this.reference.get(0).getPointAt(this.reference.get(0).getPointCount()-1); p2 = new Point2d( this.bounds.getMinX() + getRandom().nextDouble() * this.bounds.getWidth(), this.bounds.getMinY() + getRandom().nextDouble() * this.bounds.getHeight()); polyline.addPoint(p1.getX(), p1.getY()); polyline.addPoint(p2.getX(), p2.getY()); assertTrue(test.add(polyline, 0.5, first, second)); assertConnected(polyline, first.get(), true); assertConnected(polyline, second.get(), false); first.clear(); second.clear(); polyline = new MapPolyline(); p1 = new Point2d( this.bounds.getMinX() + getRandom().nextDouble() * this.bounds.getWidth(), this.bounds.getMinY() + getRandom().nextDouble() * this.bounds.getHeight()); p2 = this.reference.get(1).getPointAt(this.reference.get(1).getPointCount()-1); polyline.addPoint(p1.getX(), p1.getY()); polyline.addPoint(p2.getX(), p2.getY()); assertTrue(test.add(polyline, 0.5, first, second)); assertConnected(polyline, first.get(), true); assertConnected(polyline, second.get(), false); first.clear(); second.clear(); polyline = new MapPolyline(); p1 = this.reference.get(2).getPointAt(this.reference.get(2).getPointCount()-1); p2 = this.reference.get(3).getPointAt(this.reference.get(3).getPointCount()-1); polyline.addPoint(p1.getX(), p1.getY()); polyline.addPoint(p2.getX(), p2.getY()); assertTrue(test.add(polyline, 0.5, first, second)); assertConnected(polyline, first.get(), true); assertConnected(polyline, second.get(), false); first.clear(); second.clear(); polyline = new MapPolyline(); p1 = new Point2d( this.bounds.getMinX() + getRandom().nextDouble() * this.bounds.getWidth(), this.bounds.getMinY() + getRandom().nextDouble() * this.bounds.getHeight()); p2 = new Point2d( this.bounds.getMinX() + getRandom().nextDouble() * this.bounds.getWidth(), this.bounds.getMinY() + getRandom().nextDouble() * this.bounds.getHeight()); polyline.addPoint(p1.getX(), p1.getY()); polyline.addPoint(p2.getX(), p2.getY()); assertTrue(test.add(polyline, 0.5, first, second)); assertConnected(polyline, first.get(), true); assertConnected(polyline, second.get(), false); }