Search in sources :

Example 1 with Stats

use of jcog.tree.rtree.util.Stats in project narchy by automenta.

the class RTree method stats.

@Override
public Stats stats() {
    Stats stats = new Stats();
    stats.setType(model);
    stats.setMaxFill(model.max);
    stats.setMinFill(model.min);
    root.collectStats(stats, 0);
    return stats;
}
Also used : Stats(jcog.tree.rtree.util.Stats)

Example 2 with Stats

use of jcog.tree.rtree.util.Stats in project narchy by automenta.

the class AxialSplitLeafTest 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 3 with Stats

use of jcog.tree.rtree.util.Stats in project narchy by automenta.

the class AxialSplitLeafTest method causeLinearSplitOverflow.

/**
 * This test previously caused a StackOverflowException on LINEAR leaf.
 * It has since been fixed, but keeping the test here to ensure this leaf type
 * never falls victim to the same issue.
 */
@Test
public void causeLinearSplitOverflow() {
    final RTree<RectDouble2D> rTree = RTree2DTest.createRect2DTree(TYPE);
    final Random rand = new Random(13);
    for (int i = 0; i < 500; i++) {
        final int x1 = rand.nextInt(10);
        final int y1 = rand.nextInt(10);
        final int x2 = x1 + rand.nextInt(200);
        final int y2 = y1 + rand.nextInt(200);
        rTree.add(new RectDouble2D(x1, y1, x2, y2));
    }
    final Stats stats = rTree.stats();
    stats.print(System.out);
}
Also used : Random(java.util.Random) Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 4 with Stats

use of jcog.tree.rtree.util.Stats in project narchy by automenta.

the class AxialSplitLeafTest 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)

Example 5 with Stats

use of jcog.tree.rtree.util.Stats in project narchy by automenta.

the class LinearSplitLeafTest method causeLinearSplitOverflow.

/**
 * This test previously caused a StackOverflowException.
 * It has since been fixed, but keeping the test to ensure
 * it doesn't happen again.
 */
@Test
public void causeLinearSplitOverflow() {
    final RTree<RectDouble2D> rTree = RTree2DTest.createRect2DTree(2, 8, TYPE);
    final Random rand = new Random(13);
    for (int i = 0; i < 500; i++) {
        final int x1 = rand.nextInt(10);
        final int y1 = rand.nextInt(10);
        final int x2 = x1 + rand.nextInt(200);
        final int y2 = y1 + rand.nextInt(200);
        rTree.add(new RectDouble2D(x1, y1, x2, y2));
    }
    final Stats stats = rTree.stats();
    stats.print(System.out);
}
Also used : Random(java.util.Random) Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Aggregations

Stats (jcog.tree.rtree.util.Stats)20 RectDouble2D (jcog.tree.rtree.rect.RectDouble2D)17 Test (org.junit.jupiter.api.Test)14 Random (java.util.Random)4 Disabled (org.junit.jupiter.api.Disabled)4 RectDouble1D (jcog.tree.rtree.rect.RectDouble1D)1 RectFloatND (jcog.tree.rtree.rect.RectFloatND)1 DoubleArrayList (org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)1