Search in sources :

Example 6 with Rectangle

use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.

the class TestFlatbush method testSingletonFlatbushXY.

@Test
public void testSingletonFlatbushXY() {
    // Because mixing up x and y is easy to do...
    List<Rectangle> items = ImmutableList.of(new Rectangle(0, 10, 1, 11));
    Flatbush<Rectangle> rtree = new Flatbush<>(items.toArray(new Rectangle[] {}));
    // hit
    assertEquals(findIntersections(rtree, new Rectangle(1, 11, 2, 12)), items);
    // miss
    assertEquals(findIntersections(rtree, new Rectangle(11, 1, 12, 2)), ImmutableList.of());
}
Also used : Rectangle(com.facebook.presto.geospatial.Rectangle) Test(org.testng.annotations.Test)

Example 7 with Rectangle

use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.

the class TestFlatbush method testTwoLevelFlatbush.

@Test
public void testTwoLevelFlatbush() {
    // This is the smallest Rtree with height > 2
    // Also test for NaN behavior
    Rectangle rect0 = new Rectangle(1, 1, 1, 1);
    Rectangle rect1 = new Rectangle(-1, -1, -1, -1);
    Rectangle rect2 = new Rectangle(1, -1, 1, -1);
    List<Rectangle> items = ImmutableList.of(rect0, rect1, rect2);
    Flatbush<Rectangle> rtree = new Flatbush<>(items.toArray(new Rectangle[] {}), 2);
    List<Rectangle> allResults = findIntersections(rtree, EVERYTHING);
    assertEqualsSorted(allResults, items, RECTANGLE_COMPARATOR);
    assertEquals(findIntersections(rtree, new Rectangle(1, 1, 1, 1)), ImmutableList.of(rect0));
    assertEquals(findIntersections(rtree, new Rectangle(-1, -1, -1, -1)), ImmutableList.of(rect1));
    assertEquals(findIntersections(rtree, new Rectangle(1, -1, 1, -1)), ImmutableList.of(rect2));
    // Test hitting across parent nodes
    List<Rectangle> results12 = findIntersections(rtree, new Rectangle(-1, -1, 1, -1));
    assertEqualsSorted(results12, ImmutableList.of(rect1, rect2), RECTANGLE_COMPARATOR);
    // This should test missing at the root level
    assertEquals(findIntersections(rtree, new Rectangle(10, 10, 12, 12)), ImmutableList.of());
    // This should test missing at the leaf level
    assertEquals(findIntersections(rtree, new Rectangle(0, 0, 0, 0)), ImmutableList.of());
}
Also used : Rectangle(com.facebook.presto.geospatial.Rectangle) Test(org.testng.annotations.Test)

Example 8 with Rectangle

use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.

the class TestFlatbush method testChildrenOffsets.

@Test
public void testChildrenOffsets() {
    int numRectangles = 10;
    int degree = 8;
    Random random = new Random(122);
    int firstParentIndex = 2 * degree * ENVELOPE_SIZE;
    int secondParentIndex = firstParentIndex + ENVELOPE_SIZE;
    int grandparentIndex = 3 * degree * ENVELOPE_SIZE;
    List<Rectangle> rectangles = makeRectangles(random, numRectangles);
    Flatbush<Rectangle> rtree = new Flatbush<>(rectangles.toArray(new Rectangle[] {}), degree);
    assertEquals(rtree.getHeight(), 3);
    assertEquals(rtree.getChildrenOffset(firstParentIndex, 1), 0);
    assertEquals(rtree.getChildrenOffset(secondParentIndex, 1), degree * ENVELOPE_SIZE);
    assertEquals(rtree.getChildrenOffset(grandparentIndex, 2), 2 * degree * ENVELOPE_SIZE);
}
Also used : Random(java.util.Random) Rectangle(com.facebook.presto.geospatial.Rectangle) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) Test(org.testng.annotations.Test)

Example 9 with Rectangle

use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.

the class TestFlatbush method testSingletonFlatbush.

@Test
public void testSingletonFlatbush() {
    List<Rectangle> items = ImmutableList.of(new Rectangle(0, 0, 1, 1));
    Flatbush<Rectangle> rtree = new Flatbush<>(items.toArray(new Rectangle[] {}));
    assertEquals(findIntersections(rtree, EVERYTHING), items);
    // hit
    assertEquals(findIntersections(rtree, new Rectangle(1, 1, 2, 2)), items);
    // miss
    assertEquals(findIntersections(rtree, new Rectangle(-1, -1, -0.1, -0.1)), ImmutableList.of());
}
Also used : Rectangle(com.facebook.presto.geospatial.Rectangle) Test(org.testng.annotations.Test)

Example 10 with Rectangle

use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.

the class TestFlatbush method testDoubletonFlatbush.

@Test
public void testDoubletonFlatbush() {
    // This is the smallest Rtree with height > 1
    // Also test for some degeneracies
    Rectangle rect0 = new Rectangle(1, 1, 1, 1);
    Rectangle rect1 = new Rectangle(-1, -2, -1, -1);
    List<Rectangle> items = ImmutableList.of(rect0, rect1);
    Flatbush<Rectangle> rtree = new Flatbush<>(items.toArray(new Rectangle[] {}));
    List<Rectangle> allResults = findIntersections(rtree, EVERYTHING);
    assertEqualsSorted(allResults, items, RECTANGLE_COMPARATOR);
    assertEquals(findIntersections(rtree, new Rectangle(1, 1, 2, 2)), ImmutableList.of(rect0));
    assertEquals(findIntersections(rtree, new Rectangle(-2, -2, -1, -2)), ImmutableList.of(rect1));
    // This should test missing at the root level
    assertEquals(findIntersections(rtree, new Rectangle(10, 10, 12, 12)), ImmutableList.of());
    // This should test missing at the leaf level
    assertEquals(findIntersections(rtree, new Rectangle(0, 0, 0, 0)), ImmutableList.of());
}
Also used : Rectangle(com.facebook.presto.geospatial.Rectangle) Test(org.testng.annotations.Test)

Aggregations

Rectangle (com.facebook.presto.geospatial.Rectangle)19 Test (org.testng.annotations.Test)11 Envelope (com.esri.core.geometry.Envelope)4 Point (com.esri.core.geometry.Point)3 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)3 EsriGeometrySerde.deserializeEnvelope (com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope)3 List (java.util.List)3 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)2 GeometryUtils (com.facebook.presto.geospatial.GeometryUtils)2 PrestoException (com.facebook.presto.spi.PrestoException)2 Description (com.facebook.presto.spi.function.Description)2 ImmutableList (com.google.common.collect.ImmutableList)2 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)2 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 ClassLayout (org.openjdk.jol.info.ClassLayout)2 Session (com.facebook.presto.Session)1 Page (com.facebook.presto.common.Page)1 PageBuilder (com.facebook.presto.common.PageBuilder)1