Search in sources :

Example 11 with RectDouble2D

use of jcog.tree.rtree.rect.RectDouble2D in project narchy by automenta.

the class QuadraticSplitLeafTest method overlappingEntryTest.

/**
 * Adds several overlapping rectangles and confirms that no entries
 * are lost during insert/split.
 */
@Test
public void overlappingEntryTest() {
    final RTree<RectDouble2D> rTree = RTree2DTest.createRect2DTree(TYPE);
    rTree.add(new RectDouble2D(0, 0, 1, 1));
    rTree.add(new RectDouble2D(0, 0, 2, 2));
    rTree.add(new RectDouble2D(0, 0, 2.1, 2));
    rTree.add(new RectDouble2D(0, 0, 3, 3));
    rTree.add(new RectDouble2D(0, 0, 3.1, 3));
    rTree.add(new RectDouble2D(0, 0, 4, 4));
    rTree.add(new RectDouble2D(0, 0, 5, 5));
    rTree.add(new RectDouble2D(0, 0, 6, 6));
    rTree.add(new RectDouble2D(0, 0, 7, 7));
    rTree.add(new RectDouble2D(0, 0, 7.1, 7));
    rTree.add(new RectDouble2D(0, 0, 8, 8));
    rTree.add(new RectDouble2D(0, 0, 9, 9));
    rTree.add(new RectDouble2D(0, 1, 2, 2));
    rTree.add(new RectDouble2D(0, 1, 3, 3));
    rTree.add(new RectDouble2D(0, 1, 4, 4));
    rTree.add(new RectDouble2D(0, 1, 4.1, 4));
    rTree.add(new RectDouble2D(0, 1, 5, 5));
    // 17 entries guarantees *at least* 2 splits when max leaf size is 8
    final int expectedEntryCount = 17;
    final Stats stats = rTree.stats();
    assertEquals(expectedEntryCount, stats.getEntryCount(), "Unexpected number of entries in " + TYPE + " split tree: " + stats.getEntryCount() + " entries - expected: " + expectedEntryCount + " actual: " + stats.getEntryCount());
}
Also used : Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 12 with RectDouble2D

use of jcog.tree.rtree.rect.RectDouble2D in project narchy by automenta.

the class RTreeNDTest method RectDouble2DIntersectTest.

/**
 * 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.
 */
@Test
public void RectDouble2DIntersectTest() {
    final int entryCount = 20;
    for (Spatialization.DefaultSplits type : Spatialization.DefaultSplits.values()) {
        RTree<RectDouble2D> rTree = createRectDouble2DTree(2, 8, type);
        for (int i = 0; i < entryCount; i++) {
            rTree.add(new RectDouble2D(i, i, i + 3, i + 3));
        }
        final RectDouble2D searchRect = new RectDouble2D(5, 5, 10, 10);
        final int expectedCount = 9;
        List<RectDouble2D> results = new ArrayList(expectedCount);
        rTree.whileEachIntersecting(searchRect, results::add);
        final int resultCount = results.size();
        assertEquals(expectedCount, resultCount, "[" + type + "] Search returned incorrect search result count - expected: " + expectedCount + " actual: " + resultCount);
        assertEquals(expectedCount, resultCount, "[" + type + "] Search returned incorrect number of rectangles - expected: " + expectedCount + " actual: " + resultCount);
        Collections.sort(results);
        // If the order of nodes in the tree changes, this test may fail while returning the correct results.
        for (int i = 0; i < resultCount; i++) {
            assertTrue(Util.equals(results.get(i).min.x, (double) (i + 2), Spatialization.EPSILON) && Util.equals(results.get(i).min.y, (double) (i + 2), Spatialization.EPSILON) && Util.equals(results.get(i).max.x, (double) (i + 5), Spatialization.EPSILON) && Util.equals(results.get(i).max.y, (double) (i + 5), Spatialization.EPSILON), "Unexpected result found");
        }
    }
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 13 with RectDouble2D

use of jcog.tree.rtree.rect.RectDouble2D in project narchy by automenta.

the class RTreeNDTest method treeContainsTest.

@Test
public void treeContainsTest() {
    final RTree<RectDouble2D> rTree = createRectDouble2DTree(Spatialization.DefaultSplits.QUADRATIC);
    final RectDouble2D[] rects = new RectDouble2D[5];
    for (int i = 0; i < rects.length; i++) {
        rects[i] = new RectDouble2D(i, i, i + 1, i + 1);
        rTree.add(rects[i]);
    }
    assertEquals(rTree.size(), rects.length);
    for (int i = 0; i < rects.length; i++) {
        assertFalse(rTree.containedToSet(rects[i]).isEmpty());
    }
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 14 with RectDouble2D

use of jcog.tree.rtree.rect.RectDouble2D in project narchy by automenta.

the class RTreeNDTest method treesize.

@Test
public void treesize() {
    final int NENTRY = 500;
    final RTree<RectDouble2D> rTree = createRectDouble2DTree(Spatialization.DefaultSplits.QUADRATIC);
    for (int i = 0; i < NENTRY; i++) {
        final RectDouble2D rect = new RectDouble2D(i, i, i + 1, i + 1);
        rTree.add(rect);
    }
    assertEquals(NENTRY, rTree.size());
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 15 with RectDouble2D

use of jcog.tree.rtree.rect.RectDouble2D in project narchy by automenta.

the class RTreeNDTest method treeRemovalTestDuplicates.

@Test
public void treeRemovalTestDuplicates() {
    final int NENTRY = 50;
    final RTree<RectDouble2D> rTree = createRectDouble2DTree(Spatialization.DefaultSplits.QUADRATIC);
    final RectDouble2D[] rect = new RectDouble2D[2];
    for (int i = 0; i < rect.length; i++) {
        rect[i] = new RectDouble2D(i, i, i + 1, i + 1);
        rTree.add(rect[i]);
    }
    assertEquals(2, rTree.size());
    for (int i = 0; i < NENTRY; i++) {
        rTree.add(rect[1]);
    }
    assertEquals(2, rTree.size());
    for (int i = 0; i < rect.length; i++) {
        rTree.remove(rect[i]);
    }
    assertEquals(0, rTree.size());
    for (int i = 0; i < rect.length; i++) {
        assertTrue(rTree.containedToSet(rect[i]).isEmpty(), "Found hyperRect that should have been removed " + rect[i]);
    }
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Aggregations

RectDouble2D (jcog.tree.rtree.rect.RectDouble2D)48 Test (org.junit.jupiter.api.Test)40 Stats (jcog.tree.rtree.util.Stats)17 Disabled (org.junit.jupiter.api.Disabled)6 Random (java.util.Random)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Double2D (jcog.tree.rtree.point.Double2D)2 CounterNode (jcog.tree.rtree.util.CounterNode)2