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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations