MapElementTreeSet extends StandardGISTreeSet<P> implements GISElementSet<P> { @Override @Pure public final P getNearest(Point2D<?, ?> position) { final Pair<P, Double> data = getNearestData(position.getX(), position.getY()); if (data != null) { return data.getKey(); } return null; } MapElementTreeSet();  MapElementTreeSet(double boundsX, double boundsY, double boundsWidth, double boundsHeight);  MapElementTreeSet(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds); @Override @Pure final P getNearest(Point2D<?, ?> position); @Override @Pure final P getNearest(double x, double y); @Override @Pure final Pair<P, Double> getNearestData(Point2D<?, ?> position); @Override @Pure Pair<P, Double> getNearestData(double x, double y);  }
@Test public void testGetNearest() { getLogger().info("Preparing the benchmark..."); MapElementTreeSet<MapPolyline> test; if (this.bounds!=null) test = new MapElementTreeSet<>(this.bounds); else test = new MapElementTreeSet<>(); test.addAll(this.reference); assertEpsilonEquals(this.reference.size(), test.size()); getLogger().info("Run test..."); Random rnd = new Random(); MapPolyline nearestData; double minDistance, distance, x, y; Point2d p; final ArrayList<MapPolyline> nearest = new ArrayList<>(); x = rnd.nextDouble()*this.bounds.getWidth()+this.bounds.getMinX(); y = rnd.nextDouble()*this.bounds.getHeight()+this.bounds.getMinY(); p = new Point2d(x,y); minDistance = Double.MAX_VALUE; nearest.clear(); for (MapPolyline line : this.reference) { distance = line.getDistance(p); if (isEpsilonEquals(minDistance, distance)) { nearest.add(line); } else if (distance<minDistance) { minDistance = distance; nearest.clear(); nearest.add(line); } } nearestData = test.getNearest(x, y); assertNotNull(nearestData); assertTrue(nearest.contains(nearestData)); }