(Point2D p)
| 126 | |
| 127 | // a nearest neighbor in the set to point p; null if the set is empty |
| 128 | public Point2D nearest(Point2D p) { |
| 129 | if (p == null) throw new IllegalArgumentException(); |
| 130 | if (isEmpty()) return null; |
| 131 | Champion champion = new Champion(root.p, Double.POSITIVE_INFINITY); |
| 132 | nearest(p, root, true, champion); |
| 133 | return champion.p; |
| 134 | } |
| 135 | |
| 136 | private void nearest(Point2D p, Node nd, boolean flag, Champion champion) { |
| 137 | double queryD = p.distanceSquaredTo(nd.p); |