MapPolylineTreeSet extends MapElementTreeSet<P> implements GISPolylineSet<P> { @Override @Pure public final P getNearestEnd(Point2D<?, ?> position) { return getNearestEnd(position.getX(), position.getY()); } MapPolylineTreeSet();  MapPolylineTreeSet(double boundsX, double boundsY, double boundsWidth, double boundsHeight);  MapPolylineTreeSet(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds); @Override boolean add(P polyline, double precision, OutputParameter<P> firstNeighbour, OutputParameter<P> secondNeighbour); @Override @Pure final P getNearestEnd(Point2D<?, ?> position); @Override @Pure P getNearestEnd(double x, double y);  }
@Test public void testGetNearestEnd() { MapPolylineTreeSet<MapPolyline> test; if (this.bounds!=null) test = new MapPolylineTreeSet<>(this.bounds); else test = new MapPolylineTreeSet<>(); test.addAll(this.reference); assertEpsilonEquals(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)); }