@Override public boolean findNearest(P point, double maxDistance, NnData<P> result) { if( maxDistance < 0 ) search1.setMaxDistance(Double.MAX_VALUE); else search1.setMaxDistance(maxDistance); KdTree.Node found = search1.findNeighbor(point); if( found == null ) return false; result.point = (P)found.point; result.index = found.index; result.distance = search1.getDistance(); return true; }
@Override public boolean findNearest(P point, double maxDistance, NnData<P> result) { if( maxDistance < 0 ) search1.setMaxDistance(Double.MAX_VALUE); else search1.setMaxDistance(maxDistance); KdTree.Node found = search1.findNeighbor(point); if( found == null ) return false; result.point = (P)found.point; result.index = found.index; result.distance = search1.getDistance(); return true; }
/** * Provide an insufficient number of steps to produce an optimal solution and see if it produces the expected * result */ @Test public void checkMaxNodes() { KdTree tree = StandardKdTreeSearch1Tests.createTreeA(); KdTreeSearch1Bbf<double[]> alg = new KdTreeSearch1Bbf<>(new KdTreeEuclideanSq_F64(2),0); alg.setTree(tree); KdTree.Node found = alg.findNeighbor(new double[]{12, 2}); // The first search from the root node is not counted. In that search it will traverse down to a leaf assertTrue(found==tree.root.left.right); }
/** * Provide multiple trees for input and see if it finds the best one */ @Test public void multiTreeSearch() { KdTree forest[] = new KdTree[2]; forest[0] = StandardKdTreeSearch1Tests.createTreeA(); forest[1] = new KdTree(2); forest[1].root = new KdTree.Node(new double[]{12,2}); KdTreeSearch1Bbf<double[]> alg = new KdTreeSearch1Bbf<>(new KdTreeEuclideanSq_F64(2),200); alg.setTrees(forest); KdTree.Node found = alg.findNeighbor(new double[]{12, 3}); // make sure it searched some nodes besides the root ones assertTrue(alg.numNodesSearched>0); // the best node should be the root node in the second forest assertSame(found, forest[1].root); }