Search in sources :

Example 16 with RectDouble2D

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

the class RTreeNDTest method treeRemovalTest1000Entries.

@Test
public void treeRemovalTest1000Entries() {
    final RTree<RectDouble2D> rTree = createRectDouble2DTree(Spatialization.DefaultSplits.QUADRATIC);
    int N = 1000;
    final RectDouble2D[] rect = new RectDouble2D[N];
    for (int i = 0; i < rect.length; i++) {
        rect[i] = new RectDouble2D(i, i, i + 1, i + 1);
        rTree.add(rect[i]);
    }
    assertEquals(N, rTree.size());
    for (int i = 0; i < N; i++) {
        boolean removed = rTree.remove(rect[i]);
        assertTrue(removed);
    }
    assertEquals(0, rTree.size());
    for (int i = 0; i < N; i++) {
        assertTrue(rTree.containedToSet(rect[i]).isEmpty(), "#" + i + " of " + rect.length + ": Found hyperRect that should have been removed" + rect[i]);
    }
    assertFalse(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 17 with RectDouble2D

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

the class RTreeNDTest method pointSearchTest.

@Test
public void pointSearchTest() {
    final RTree<Double2D> pTree = new RTree<>(new Double2D.Builder(), 2, 8, Spatialization.DefaultSplits.AXIAL);
    for (int i = 0; i < 10; i++) {
        pTree.add(new Double2D(i, i));
    }
    final RectDouble2D rect = new RectDouble2D(new Double2D(2, 2), new Double2D(8, 8));
    final Double2D[] result = new Double2D[10];
    final int n = pTree.containedToArray(rect, result);
    assertEquals(7, n);
    for (int i = 0; i < n; i++) {
        assertTrue(result[i].coord(0) >= 2);
        assertTrue(result[i].coord(0) <= 8);
        assertTrue(result[i].coord(1) >= 2);
        assertTrue(result[i].coord(1) <= 8);
    }
}
Also used : Double2D(jcog.tree.rtree.point.Double2D) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 18 with RectDouble2D

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

the class RTreeNDTest method treeRemovalTest5Entries.

@Test
public void treeRemovalTest5Entries() {
    final RTree<RectDouble2D> rTree = createRectDouble2DTree(Spatialization.DefaultSplits.QUADRATIC);
    final RectDouble2D[] rects = new RectDouble2D[5];
    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 = 1; i < rects.length; i++) {
        assertTrue(rTree.remove(rects[i]));
        assertEquals(rects.length - i, rTree.size());
    }
    assertEquals(1, rTree.size());
    assertFalse(rTree.containedToSet(rects[0]).isEmpty(), "Missing hyperRect that should  be found " + rects[0]);
    for (int i = 1; i < rects.length; i++) {
        assertTrue(rTree.containedToSet(rects[i]).isEmpty(), "Found hyperRect that should have been removed on search " + rects[i]);
    }
    final RectDouble2D hr = new RectDouble2D(0, 0, 5, 5);
    rTree.add(hr);
    assertFalse(rTree.containedToSet(hr).isEmpty());
    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 19 with RectDouble2D

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

the class RTreeNDTest method treeUpdateTest.

@Test
public void treeUpdateTest() {
    final RTree<RectDouble2D> rTree = createRectDouble2DTree(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];
    final int num = rTree.containedToArray(newRect, results);
    assertTrue(num == 1, "Did not find the updated HyperRect");
    System.out.print(results[0]);
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 20 with RectDouble2D

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

the class Rect2DTest method intersectsTest.

@Test
public void intersectsTest() {
    RectDouble2D rect = new RectDouble2D(0, 0, 4, 3);
    // shares an edge on the outside, intersects
    RectDouble2D rectOutsideIntersects = new RectDouble2D(4, 2, 5, 3);
    assertTrue(rect.intersects(rectOutsideIntersects), "Shares an edge and should 'intersect'");
    // shares an edge on the inside, intersects
    RectDouble2D rectInsideIntersects = new RectDouble2D(0, 1, 4, 5);
    assertTrue(rect.intersects(rectInsideIntersects), "Shares an edge and should 'intersect'");
    // shares an edge on the inside, intersects
    RectDouble2D rectInsideIntersectsContained = new RectDouble2D(0, 1, 1, 2);
    assertTrue(rect.intersects(rectInsideIntersectsContained), "Shares an edge and should 'intersect'");
    // intersects
    RectDouble2D rectIntersects = new RectDouble2D(3, 2, 5, 4);
    assertTrue(rect.intersects(rectIntersects), "Intersects and should 'intersect'");
    // contains
    RectDouble2D rectContained = new RectDouble2D(1, 1, 2, 2);
    assertTrue(rect.intersects(rectContained), "Contains and should 'intersect'");
    // does not contain or intersect
    RectDouble2D rectNotIntersects = new RectDouble2D(5, 0, 6, 1);
    assertTrue(!rect.intersects(rectNotIntersects), "Does not intersect and should not 'intersect'");
}
Also used : 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