Search in sources :

Example 1 with FloatND

use of jcog.tree.rtree.point.FloatND in project narchy by automenta.

the class RTreeNDTest method rectNDSearchTest2.

/**
 * Use an small bounding box to ensure that only expected rectangles are returned.
 * Verifies the count returned from search AND the number of rectangles results.
 * 2D but using N-d impl
 */
@Test
public void rectNDSearchTest2() {
    final int entryCount = 20;
    System.out.println("rectNDSearchTest2");
    for (Spatialization.DefaultSplits type : Spatialization.DefaultSplits.values()) {
        RTree<RectFloatND> rTree = RTree2DTest.createRectNDTree(2, 8, type);
        for (int i = 0; i < entryCount; i++) {
            rTree.add(new RectFloatND(new FloatND(i, i), new FloatND(i + 3, i + 3)));
        }
        final RectFloatND searchRect = new RectFloatND(new FloatND(5, 5), new FloatND(10, 10));
        List<RectFloatND> results = new ArrayList();
        rTree.whileEachIntersecting(searchRect, results::add);
        int resultCount = 0;
        for (int i = 0; i < results.size(); i++) {
            if (results.get(i) != null) {
                resultCount++;
            }
        }
        final int expectedCount = 9;
        // assertEquals("[" + type + "] Search returned incorrect search result count - expected: " + expectedCount + " actual: " + foundCount, expectedCount, foundCount);
        assertEquals(expectedCount, resultCount, "[" + type + "] Search returned incorrect number of rectangles - expected: " + expectedCount + " actual: " + resultCount);
        // If the order of nodes in the tree changes, this test may fail while returning the correct results.
        Collections.sort(results);
        for (int i = 0; i < resultCount; i++) {
            assertTrue(results.get(i).min.coord(0) == i + 2 && results.get(i).min.coord(1) == i + 2 && results.get(i).max.coord(0) == i + 5 && results.get(i).max.coord(1) == i + 5, "Unexpected result found");
        }
        System.out.println("\t" + rTree.stats());
    }
}
Also used : RectFloatND(jcog.tree.rtree.rect.RectFloatND) FloatND(jcog.tree.rtree.point.FloatND) RectFloatND(jcog.tree.rtree.rect.RectFloatND) Test(org.junit.jupiter.api.Test)

Aggregations

FloatND (jcog.tree.rtree.point.FloatND)1 RectFloatND (jcog.tree.rtree.rect.RectFloatND)1 Test (org.junit.jupiter.api.Test)1