MCPcopy Create free account
hub / github.com/MolinDeng/Princeton-algs4 / nearest

Method nearest

05Lab-Kd Tree/KdTree.java:128–134  ·  view source on GitHub ↗
(Point2D p)

Source from the content-addressed store, hash-verified

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);

Callers 1

mainMethod · 0.95

Calls 1

isEmptyMethod · 0.95

Tested by

no test coverage detected