@Override public boolean findNearest( P point , double maxDistance , NnData<P> result ) { if( maxDistance < 0 ) search.setMaxDistance(Double.MAX_VALUE); else search.setMaxDistance(maxDistance); KdTree.Node found = search.findNeighbor(point); if( found == null ) return false; result.point = (P)found.point; result.index = found.index; result.distance = search.getDistance(); return true; }
@Override public boolean findNearest( P point , double maxDistance , NnData<P> result ) { if( maxDistance < 0 ) search.setMaxDistance(Double.MAX_VALUE); else search.setMaxDistance(maxDistance); KdTree.Node found = search.findNeighbor(point); if( found == null ) return false; result.point = (P)found.point; result.index = found.index; result.distance = search.getDistance(); return true; }
/** * Make sure the distance it returns is correct */ @Test public void checkDistance() { KdTreeSearch1<double[]> alg = createAlg(); KdTree tree = createTreeA(); alg.setTree(tree); alg.setMaxDistance(Double.MAX_VALUE); double[] pt = new double[]{11.5,8.2}; KdTree.Node found = alg.findNeighbor(pt); double d0 = ((double[])found.point)[0]-pt[0]; double d1 = ((double[])found.point)[1]-pt[1]; assertEquals(d0*d0 + d1*d1,alg.getDistance(),1e-8); } }