Search in sources :

Example 41 with RectDouble2D

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

the class Rect2DTest method rangeTest.

@Test
public void rangeTest() {
    RectDouble2D rect = new RectDouble2D(0, 0, 4, 3);
    double xRange = rect.range(0);
    double yRange = rect.range(1);
    assertTrue(xRange == 4.0d, "Bad range in dimension X - expected " + 4.0 + " but was " + xRange);
    assertTrue(yRange == 3.0d, "Bad range in dimension Y - expected " + 3.0 + " but was " + yRange);
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 42 with RectDouble2D

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

the class Rect2DTest method mbrTest.

@Test
public void mbrTest() {
    RectDouble2D rect = new RectDouble2D(0, 0, 4, 3);
    // shouldn't affect MBR
    RectDouble2D rectInside = new RectDouble2D(0, 0, 1, 1);
    RectDouble2D mbr = rect.mbr(rectInside);
    double expectedMinX = rect.min.x;
    double expectedMinY = rect.min.y;
    double expectedMaxX = rect.max.x;
    double expectedMaxY = rect.max.y;
    double actualMinX = mbr.min.x;
    double actualMinY = mbr.min.y;
    double actualMaxX = mbr.max.x;
    double actualMaxY = mbr.max.y;
    assertTrue(actualMinX == expectedMinX, "Bad minX - Expected: " + expectedMinX + " Actual: " + actualMinX);
    assertTrue(actualMinY == expectedMinY, "Bad minY - Expected: " + expectedMinY + " Actual: " + actualMinY);
    assertTrue(actualMaxX == expectedMaxX, "Bad maxX - Expected: " + expectedMaxX + " Actual: " + actualMaxX);
    assertTrue(actualMaxY == expectedMaxY, "Bad maxY - Expected: " + expectedMaxY + " Actual: " + actualMaxY);
    // should affect MBR
    RectDouble2D rectOverlap = new RectDouble2D(3, 1, 5, 4);
    mbr = rect.mbr(rectOverlap);
    expectedMinX = 0.0d;
    expectedMinY = 0.0d;
    expectedMaxX = 5.0d;
    expectedMaxY = 4.0d;
    actualMinX = mbr.min.x;
    actualMinY = mbr.min.y;
    actualMaxX = mbr.max.x;
    actualMaxY = mbr.max.y;
    assertTrue(actualMinX == expectedMinX, "Bad minX - Expected: " + expectedMinX + " Actual: " + actualMinX);
    assertTrue(actualMinY == expectedMinY, "Bad minY - Expected: " + expectedMinY + " Actual: " + actualMinY);
    assertTrue(actualMaxX == expectedMaxX, "Bad maxX - Expected: " + expectedMaxX + " Actual: " + actualMaxX);
    assertTrue(actualMaxY == expectedMaxY, "Bad maxY - Expected: " + expectedMaxY + " Actual: " + actualMaxY);
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 43 with RectDouble2D

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

the class Rect2DTest method containsTest.

@Test
public void containsTest() {
    RectDouble2D rect = new RectDouble2D(0, 0, 4, 3);
    // shares an edge on the outside, not contained
    RectDouble2D rectOutsideNotContained = new RectDouble2D(4, 2, 5, 3);
    assertTrue(!rect.contains(rectOutsideNotContained), "Shares an edge but should not be 'contained'");
    // shares an edge on the inside, not contained
    RectDouble2D rectInsideNotContained = new RectDouble2D(0, 1, 4, 5);
    assertTrue(!rect.contains(rectInsideNotContained), "Shares an edge but should not be 'contained'");
    // shares an edge on the inside, contained
    RectDouble2D rectInsideContained = new RectDouble2D(0, 1, 1, 2);
    assertTrue(rect.contains(rectInsideContained), "Shares an edge and should be 'contained'");
    // intersects
    RectDouble2D rectIntersects = new RectDouble2D(3, 2, 5, 4);
    assertTrue(!rect.contains(rectIntersects), "Intersects but should not be 'contained'");
    // contains
    RectDouble2D rectContained = new RectDouble2D(1, 1, 2, 2);
    assertTrue(rect.contains(rectContained), "Contains and should be 'contained'");
    // does not contain or intersect
    RectDouble2D rectNotContained = new RectDouble2D(5, 0, 6, 1);
    assertTrue(!rect.contains(rectNotContained), "Does not contain and should not be 'contained'");
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 44 with RectDouble2D

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

the class RTree2DTest method treeSingleRemovalTest.

@Test
public void treeSingleRemovalTest() {
    final RTree<RectDouble2D> rTree = createRect2DTree(Spatialization.DefaultSplits.QUADRATIC);
    RectDouble2D rect = new RectDouble2D(0, 0, 2, 2);
    rTree.add(rect);
    assertTrue(rTree.size() > 0, "Did not add HyperRect to Tree");
    assertTrue(rTree.remove(rect));
    assertTrue(rTree.size() == 0, "Did not remove HyperRect from Tree");
    rTree.add(rect);
    assertTrue(rTree.size() > 0, "Tree nulled out and could not add HyperRect back in");
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Test(org.junit.jupiter.api.Test)

Example 45 with RectDouble2D

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

the class RTree2DTest 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));
        assertEquals(i + 1, pTree.size());
        assertEquals(i + 1, Iterators.size(pTree.iterator()));
    }
    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, () -> Arrays.toString(result));
    for (int i = 0; i < n; i++) {
        assertTrue(result[i].x >= 2);
        assertTrue(result[i].x <= 8);
        assertTrue(result[i].y >= 2);
        assertTrue(result[i].y <= 8);
    }
}
Also used : RectDouble2D(jcog.tree.rtree.rect.RectDouble2D) Double2D(jcog.tree.rtree.point.Double2D) 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