Search in sources :

Example 1 with Octree

use of com.bergerkiller.bukkit.common.collections.octree.Octree in project BKCommonLib by bergerhealer.

the class OctreeTest method testIteratorSelectSibling.

@Test
public void testIteratorSelectSibling() {
    // Tests a very specific edge case where, while trying to find a value,
    // it first runs into a direct sibling of the value. This causes the algorithm
    // to look for a sibling at depth=0 which has some interesting consequences.
    IntVector3 block = new IntVector3(1, 0, 0);
    Octree<String> tree = new Octree<String>();
    tree.put(block.x, block.y, block.z, "A");
    tree.put(block.x, block.y, block.z + 1, "B");
    tree.put(block.x, block.y + 1, block.z, "C");
    OctreeIterator<String> iter = tree.cuboid(block, block.add(1, 1, 0)).iterator();
    assertNext(iter, "A", block.x, block.y, block.z);
    assertNext(iter, "C", block.x, block.y + 1, block.z);
    assertFalse(iter.hasNext());
}
Also used : Octree(com.bergerkiller.bukkit.common.collections.octree.Octree) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) Test(org.junit.Test)

Example 2 with Octree

use of com.bergerkiller.bukkit.common.collections.octree.Octree in project BKCommonLib by bergerhealer.

the class OctreeTest method testSmallCuboid.

@Test
public void testSmallCuboid() {
    // Tests a single-block area cuboid, which is challenging because
    // the last data-entry holding node will be filtered only
    Octree<String> tree = new Octree<String>();
    putDemoValues(tree);
    IntVector3 block = new IntVector3(10, 100, 1000);
    OctreeIterator<String> iter = tree.cuboid(block, block).iterator();
    assertTrue(iter.hasNext());
    assertEquals("D", iter.next());
    assertEquals(10, iter.getX());
    assertEquals(100, iter.getY());
    assertEquals(1000, iter.getZ());
    assertFalse(iter.hasNext());
}
Also used : Octree(com.bergerkiller.bukkit.common.collections.octree.Octree) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) Test(org.junit.Test)

Aggregations

IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)2 Octree (com.bergerkiller.bukkit.common.collections.octree.Octree)2 Test (org.junit.Test)2