Search in sources :

Example 26 with RectDouble2D

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

the class SplitTest method randomEntryTest.

/**
 * Adds many random entries to trees of different types and confirms that
 * no entries are lost during insert/split.
 */
@Test
public void randomEntryTest() {
    int entryCount = 25000;
    final RectDouble2D[] rects = RTree2DTest.generateRandomRects(entryCount);
    for (Spatialization.DefaultSplits s : Spatialization.DefaultSplits.values()) {
        for (int min : new int[] { 2, 3, 4 }) {
            for (int max : new int[] { min + 1, 8 }) {
                final RTree<RectDouble2D> rTree = RTree2DTest.createRect2DTree(s, min, max);
                int i = 0;
                for (RectDouble2D r : rects) {
                    boolean added = rTree.add(r);
                    if (!added) {
                        // for debugging: try again and see what happened
                        rTree.add(r);
                        fail("");
                    }
                    assertTrue(added);
                    assertEquals(++i, rTree.size());
                    // assertEquals(i, rTree.stats().getEntryCount());
                    boolean tryAddingAgainToTestForNonMutation = rTree.add(r);
                    if (tryAddingAgainToTestForNonMutation) {
                        // for debugging: try again and see what happened
                        rTree.add(r);
                        fail("");
                    }
                    // reinsertion of existing element will not affect size and will return false here
                    assertFalse(tryAddingAgainToTestForNonMutation, i + "==?" + rTree.size());
                    // reinsertion should cause no change in size
                    assertEquals(i, rTree.size());
                // assertEquals(i, rTree.stats().getEntryCount());
                }
                assertEquals(entryCount, rTree.size());
                final Stats stats = rTree.stats();
                assertEquals(entryCount, stats.getEntryCount());
                stats.print(System.out);
            }
        }
    }
}
Also used : Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 27 with RectDouble2D

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

the class RTree2DTest method treeUpdateTest.

@Test
public void treeUpdateTest() {
    final RTree<RectDouble2D> rTree = createRect2DTree(Spatialization.DefaultSplits.QUADRATIC);
    RectDouble2D rect = new RectDouble2D(0, 1, 2, 3);
    rTree.add(rect);
    RectDouble2D oldRect = new RectDouble2D(0, 1, 2, 3);
    RectDouble2D newRect = new RectDouble2D(1, 2, 3, 4);
    rTree.replace(oldRect, newRect);
    RectDouble2D[] results = new RectDouble2D[2];
    int num = rTree.containedToArray(newRect, results);
    assertTrue(num == 1, "Did not find the updated HyperRect");
    String st = results[0].toString();
    System.out.print(st);
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 28 with RectDouble2D

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

the class RTree2DTest method treeRemovalTest.

@Test
public void treeRemovalTest() {
    final RTree<RectDouble2D> rTree = createRect2DTree(Spatialization.DefaultSplits.QUADRATIC);
    RectDouble2D[] rects = new RectDouble2D[1000];
    for (int i = 0; i < rects.length; i++) {
        rects[i] = new RectDouble2D(i, i, i + 1, i + 1);
        rTree.add(rects[i]);
    }
    for (int i = 0; i < rects.length; i++) {
        rTree.remove(rects[i]);
    }
    RectDouble2D[] searchResults = new RectDouble2D[10];
    for (int i = 0; i < rects.length; i++) {
        assertTrue(rTree.containedToArray(rects[i], searchResults) == 0, "Found hyperRect that should have been removed on search " + i);
    }
    rTree.add(new RectDouble2D(0, 0, 5, 5));
    assertTrue(rTree.size() != 0, "Found hyperRect that should have been removed on search ");
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 29 with RectDouble2D

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

the class AxialSplitLeafTest method randomEntryTest.

/**
 * Adds many random entries and confirm that no entries
 * are lost during insert/split.
 */
@Test
public void randomEntryTest() {
    final int entryCount = 50000;
    final RectDouble2D[] rects = RTree2DTest.generateRandomRects(entryCount);
    final RTree<RectDouble2D> rTree = RTree2DTest.createRect2DTree(TYPE);
    for (int i = 0; i < rects.length; i++) {
        rTree.add(rects[i]);
    }
    final Stats stats = rTree.stats();
    assertTrue(Math.abs(entryCount - stats.getEntryCount()) < 20, "Unexpected number of entries in " + TYPE + " split tree: " + stats.getEntryCount() + " entries - expected: " + entryCount + " actual: " + stats.getEntryCount());
    stats.print(System.out);
}
Also used : Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 30 with RectDouble2D

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

the class LinearSplitLeafTest method basicSplitTest.

/**
 * Adds enough entries to force a single split and confirms that
 * no entries are lost.
 */
@Test
public void basicSplitTest() {
    RTree<RectDouble2D> rTree = RTree2DTest.createRect2DTree(TYPE);
    rTree.add(new RectDouble2D(0, 0, 1, 1));
    rTree.add(new RectDouble2D(1, 1, 2, 2));
    rTree.add(new RectDouble2D(2, 2, 3, 3));
    rTree.add(new RectDouble2D(3, 3, 4, 4));
    rTree.add(new RectDouble2D(4, 4, 5, 5));
    rTree.add(new RectDouble2D(5, 5, 6, 6));
    rTree.add(new RectDouble2D(6, 6, 7, 7));
    rTree.add(new RectDouble2D(7, 7, 8, 8));
    // 9 entries guarantees a split
    rTree.add(new RectDouble2D(8, 8, 9, 9));
    Stats stats = rTree.stats();
    assertTrue(stats.getMaxDepth() == 1, "Unexpected max depth after basic split");
    assertTrue(stats.getBranchCount() == 1, "Unexpected number of branches after basic split");
    assertTrue(stats.getLeafCount() == 2, "Unexpected number of leaves after basic split");
    assertTrue(stats.getEntriesPerLeaf() == 4.5, "Unexpected number of entries per leaf after basic split");
}
Also used : Stats(jcog.tree.rtree.util.Stats) 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