@Override public void setPoints(List<P> points, boolean trackIndicies) { alg.setPoints(points); this.points = points; }
@Override public void setPoints(List<P> points, boolean trackIndicies) { alg.setPoints(points); this.points = points; }
@Test public void findClosest_zero() { List<double[]> list = new ArrayList<double[]>(); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); assertEquals(alg.findClosest(new double[]{1, 2}, 10), -1); }
@Test public void findClosestN_zero() { List<double[]> list = new ArrayList<double[]>(); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{1, 2}, 10, 5, outputIndex, outputDistance); assertEquals(0,outputIndex.size); assertEquals(0,outputDistance.size); }
@Test public void findClosest_three() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4, 6,7); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); assertEquals(1, alg.findClosest(new double[]{3.1, 3.9}, 10)); }
@Test public void findNearest_compareToNaive() { for( int numPoints = 10; numPoints <= 100; numPoints += 10 ) { // System.out.println("numPoints = "+numPoints); List<double[]> points = new ArrayList<double[]>(); for( int i = 0; i < numPoints; i++ ) points.add(randPoint(2)); alg.setPoints(points,false); double[] where = randPoint(2); assertTrue(alg.findNearest(where, 10, found)); ExhaustiveNeighbor<double[]> exhaustive = new ExhaustiveNeighbor<>(distance); exhaustive.setPoints(points); double[] expected = points.get( exhaustive.findClosest(where,1000) ); assertSame(expected, found.point); } }
@Test public void findClosest_two() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); assertEquals(0, alg.findClosest(new double[]{1, 2.1}, 10)); }
@Test public void findClosest_one() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); assertEquals(0, alg.findClosest(new double[]{1, 2.1}, 10)); assertNotEquals(0, alg.findClosest(new double[]{1, 200}, 10)); }
exhaustive.setPoints(points);
@Test public void findClosestN_standard() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4 , 4,5, 6,7 , 8,9 ); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{4.1, 4.9}, 10, 3, outputIndex, outputDistance); assertEquals(3,outputIndex.size); assertEquals(3,outputDistance.size); checkContains(1,outputIndex); checkContains(2,outputIndex); checkContains(3,outputIndex); }
/** * Request more inliers than there are */ @Test public void findClosestN_toomany() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{1, 2}, 10, 5, outputIndex, outputDistance); assertEquals(2,outputIndex.size); assertEquals(2,outputDistance.size); assertEquals(0,outputIndex.get(0)); assertEquals(1,outputIndex.get(1)); }
/** * Request more inliers than there are within the allowed distance */ @Test public void findClosestN_toomany_distance() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{1, 2}, 0.1, 5, outputIndex, outputDistance); assertEquals(1,outputIndex.size); assertEquals(1,outputDistance.size); assertEquals(0,outputIndex.get(0)); assertEquals(0,outputDistance.get(0),1e-8); }
/** * Make sure it works after multiple calls */ @Test public void findClosestN_multiple_calls() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4 , 4,5, 6,7 , 8,9 ); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{4.1, 4.9}, 10, 3, outputIndex, outputDistance); outputIndex.reset(); outputDistance.reset(); alg.findClosestN(new double[]{4.1, 4.9}, 10, 3, outputIndex, outputDistance); assertEquals(3,outputIndex.size); assertEquals(3,outputDistance.size); checkContains(1,outputIndex); checkContains(2,outputIndex); checkContains(3,outputIndex); }