public void addSelection(Point p) { ExprPoint ep = null; int minDist = -1; for (ExprPoint ex : points) { int sd = ex.screenDist(p); if (ep == null || sd < minDist) { ep = ex; minDist = sd; } } if (ep != null) { Set<Point> remove = new HashSet<Point>(); for (Point rp : selections.keySet()) { if (selections.get(rp).equals(ep)) { remove.add(rp); } } selections.put(p, ep); for (Point rp : remove) { selections.remove(rp); } } }