Search in sources :

Example 16 with Stats

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

the class RTreeNDTest method treeRemoveAndRebalanceTest.

@Disabled
public // This test ignored because output needs to be manually evaluated.
void treeRemoveAndRebalanceTest() {
    final RTree<RectDouble2D> rTree = createRectDouble2DTree(Spatialization.DefaultSplits.QUADRATIC);
    RectDouble2D[] rect = new RectDouble2D[65];
    for (int i = 0; i < rect.length; i++) {
        if (i < 4) {
            rect[i] = new RectDouble2D(0, 0, 1, 1);
        } else if (i < 8) {
            rect[i] = new RectDouble2D(2, 2, 4, 4);
        } else if (i < 12) {
            rect[i] = new RectDouble2D(4, 4, 5, 5);
        } else if (i < 16) {
            rect[i] = new RectDouble2D(5, 5, 6, 6);
        } else if (i < 20) {
            rect[i] = new RectDouble2D(6, 6, 7, 7);
        } else if (i < 24) {
            rect[i] = new RectDouble2D(7, 7, 8, 8);
        } else if (i < 28) {
            rect[i] = new RectDouble2D(8, 8, 9, 9);
        } else if (i < 32) {
            rect[i] = new RectDouble2D(9, 9, 10, 10);
        } else if (i < 36) {
            rect[i] = new RectDouble2D(2, 2, 4, 4);
        } else if (i < 40) {
            rect[i] = new RectDouble2D(4, 4, 5, 5);
        } else if (i < 44) {
            rect[i] = new RectDouble2D(5, 5, 6, 6);
        } else if (i < 48) {
            rect[i] = new RectDouble2D(6, 6, 7, 7);
        } else if (i < 52) {
            rect[i] = new RectDouble2D(7, 7, 8, 8);
        } else if (i < 56) {
            rect[i] = new RectDouble2D(8, 8, 9, 9);
        } else if (i < 60) {
            rect[i] = new RectDouble2D(9, 9, 10, 10);
        } else if (i < 65) {
            rect[i] = new RectDouble2D(1, 1, 2, 2);
        }
    }
    for (int i = 0; i < rect.length; i++) {
        rTree.add(rect[i]);
    }
    Stats stat = rTree.stats();
    stat.print(System.out);
    for (int i = 0; i < 5; i++) {
        rTree.remove(rect[64]);
    }
    Stats stat2 = rTree.stats();
    stat2.print(System.out);
}
Also used : Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Disabled(org.junit.jupiter.api.Disabled)

Example 17 with Stats

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

the class RTreeNDTest method treeStructureStatsTest.

/**
 * Collect stats making the structure of trees of each split type
 * more visible.
 */
@Disabled
public // This test ignored because output needs to be manually evaluated.
void treeStructureStatsTest() {
    final int entryCount = 50_000;
    final RectDouble2D[] rects = generateRandomRects(entryCount);
    for (Spatialization.DefaultSplits type : Spatialization.DefaultSplits.values()) {
        RTree<RectDouble2D> rTree = createRectDouble2DTree(2, 8, type);
        for (int i = 0; i < rects.length; i++) {
            rTree.add(rects[i]);
        }
        Stats stats = rTree.stats();
        stats.print(System.out);
    }
}
Also used : Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Disabled(org.junit.jupiter.api.Disabled)

Example 18 with Stats

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

the class RTree2DTest method treeStructureStatsTest.

/**
 * Collect stats making the structure of trees of each split type
 * more visible.
 */
@Disabled
public // This test ignored because output needs to be manually evaluated.
void treeStructureStatsTest() {
    final int entryCount = 50_000;
    final RectDouble2D[] rects = generateRandomRects(entryCount);
    for (Spatialization.DefaultSplits type : Spatialization.DefaultSplits.values()) {
        RTree<RectDouble2D> rTree = createRect2DTree(2, 8, type);
        for (int i = 0; i < rects.length; i++) {
            rTree.add(rects[i]);
        }
        Stats stats = rTree.stats();
        stats.print(System.out);
    }
}
Also used : Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Disabled(org.junit.jupiter.api.Disabled)

Example 19 with Stats

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

the class RTree2DTest method treeRemoveAndRebalanceTest.

@Disabled
public // This test ignored because output needs to be manually evaluated.
void treeRemoveAndRebalanceTest() {
    final RTree<RectDouble2D> rTree = createRect2DTree(Spatialization.DefaultSplits.QUADRATIC);
    RectDouble2D[] rect = new RectDouble2D[65];
    for (int i = 0; i < rect.length; i++) {
        if (i < 4) {
            rect[i] = new RectDouble2D(0, 0, 1, 1);
        } else if (i < 8) {
            rect[i] = new RectDouble2D(2, 2, 4, 4);
        } else if (i < 12) {
            rect[i] = new RectDouble2D(4, 4, 5, 5);
        } else if (i < 16) {
            rect[i] = new RectDouble2D(5, 5, 6, 6);
        } else if (i < 20) {
            rect[i] = new RectDouble2D(6, 6, 7, 7);
        } else if (i < 24) {
            rect[i] = new RectDouble2D(7, 7, 8, 8);
        } else if (i < 28) {
            rect[i] = new RectDouble2D(8, 8, 9, 9);
        } else if (i < 32) {
            rect[i] = new RectDouble2D(9, 9, 10, 10);
        } else if (i < 36) {
            rect[i] = new RectDouble2D(2, 2, 4, 4);
        } else if (i < 40) {
            rect[i] = new RectDouble2D(4, 4, 5, 5);
        } else if (i < 44) {
            rect[i] = new RectDouble2D(5, 5, 6, 6);
        } else if (i < 48) {
            rect[i] = new RectDouble2D(6, 6, 7, 7);
        } else if (i < 52) {
            rect[i] = new RectDouble2D(7, 7, 8, 8);
        } else if (i < 56) {
            rect[i] = new RectDouble2D(8, 8, 9, 9);
        } else if (i < 60) {
            rect[i] = new RectDouble2D(9, 9, 10, 10);
        } else if (i < 65) {
            rect[i] = new RectDouble2D(1, 1, 2, 2);
        }
    }
    for (int i = 0; i < rect.length; i++) {
        rTree.add(rect[i]);
    }
    Stats stat = rTree.stats();
    stat.print(System.out);
    for (int i = 0; i < 5; i++) {
        rTree.remove(rect[64]);
    }
    Stats stat2 = rTree.stats();
    stat2.print(System.out);
}
Also used : Stats(jcog.tree.rtree.util.Stats) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Disabled(org.junit.jupiter.api.Disabled)

Example 20 with Stats

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

the class Rect1DTest method rect2DSearchTest.

/**
 * 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 rect2DSearchTest() {
    final int entryCount = 20;
    // for (RTree.Split type : RTree.Split.values()) {
    RTree<Double> t = new RTree<>((x) -> new RectDouble1D.DefaultRect1D(x, x), 2, 3, Spatialization.DefaultSplits.LINEAR);
    for (int i = 0; i < entryCount; i++) {
        t.add((double) (i * i));
    }
    // t.forEach(x -> System.out.println(x));
    Stats s = t.stats();
    System.out.println(s);
    DoubleArrayList d = new DoubleArrayList();
    t.whileEachIntersecting(new RectDouble1D.DefaultRect1D(1, 101), d::add);
    assertEquals(10, d.size());
    System.out.println(d);
// final Rect2D searchRect = new Rect2D(5, 5, 10, 10);
// Rect2D[] results = new Rect2D[entryCount];
// 
// final int foundCount = rTree.search(searchRect, results);
// int resultCount = 0;
// for(int i = 0; i < results.length; i++) {
// if(results[i] != null) {
// resultCount++;
// }
// }
// 
// final int expectedCount = 9;
// assertEquals("[" + type + "] Search returned incorrect search result count - expected: " + expectedCount + " actual: " + foundCount, expectedCount, foundCount);
// assertEquals("[" + type + "] Search returned incorrect number of rectangles - expected: " + expectedCount + " actual: " + resultCount, expectedCount, resultCount);
// 
// // 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("Unexpected result found", results[i].min.x == i + 2 && results[i].min.y == i + 2 && results[i].max.x == i + 5 && results[i].max.y == i + 5);
// }
}
Also used : RectDouble1D(jcog.tree.rtree.rect.RectDouble1D) Stats(jcog.tree.rtree.util.Stats) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) 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