use of jcog.tree.rtree.rect.RectDouble2D in project narchy by automenta.
the class AxialSplitLeafTest method splitCorrectnessTest.
@Test
public void splitCorrectnessTest() {
RTree<RectDouble2D> rTree = RTree2DTest.createRect2DTree(2, 4, TYPE);
rTree.add(new RectDouble2D(0, 0, 3, 3));
rTree.add(new RectDouble2D(1, 1, 2, 2));
rTree.add(new RectDouble2D(2, 2, 4, 4));
rTree.add(new RectDouble2D(4, 0, 5, 1));
// 5 entrees guarantees a split
rTree.add(new RectDouble2D(0, 2, 1, 4));
Branch root = (Branch) rTree.root();
Node<RectDouble2D, Object>[] children = root.children();
int childCount = 0;
for (Node c : children) {
if (c != null) {
childCount++;
}
}
assertEquals(2, childCount, "Expected different number of children after split");
Node<RectDouble2D, Object> child1 = children[0];
RectDouble2D child1Mbr = (RectDouble2D) child1.bounds();
RectDouble2D expectedChild1Mbr = new RectDouble2D(0, 0, 3, 4);
assertEquals(3, child1.size(), "Child 1 size incorrect after split");
assertEquals(expectedChild1Mbr, child1Mbr, "Child 1 mbr incorrect after split");
Node<RectDouble2D, Object> child2 = children[1];
RectDouble2D child2Mbr = (RectDouble2D) child2.bounds();
RectDouble2D expectedChild2Mbr = new RectDouble2D(2, 0, 5, 4);
assertEquals(2, child2.size(), "Child 2 size incorrect after split");
assertEquals(expectedChild2Mbr, child2Mbr, "Child 2 mbr incorrect after split");
}
use of jcog.tree.rtree.rect.RectDouble2D 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());
}
use of jcog.tree.rtree.rect.RectDouble2D 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);
}
use of jcog.tree.rtree.rect.RectDouble2D 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");
}
use of jcog.tree.rtree.rect.RectDouble2D 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);
}
Aggregations