use of me.wobblyyyy.pathfinder2.geometry.Geometry in project rtree2 by davidmoten.
the class RTreeTest method testDeleteOneFromLargeTreeThenDeleteAllAndEnsureEmpty.
@Test
public void testDeleteOneFromLargeTreeThenDeleteAllAndEnsureEmpty() {
int n = 10000;
RTree<Object, Geometry> tree = createRandomRTree(n).add(e(1)).add(e(2)).delete(e(1));
assertEquals(n + 1, Iterables.size(tree.entries()));
assertFalse(Observable.from(tree.entries()).contains(e(1)).toBlocking().single());
assertTrue(Observable.from(tree.entries()).contains(e(2)).toBlocking().single());
n++;
assertEquals(n, tree.size());
for (Entry<Object, Geometry> entry : tree.entries()) {
tree = tree.delete(entry);
n--;
assertEquals(n, tree.size());
}
assertTrue(Iterables.isEmpty(tree.entries()));
assertTrue(tree.isEmpty());
}
use of me.wobblyyyy.pathfinder2.geometry.Geometry in project rtree2 by davidmoten.
the class RTreeTest method testBulkLoadingTreeAndStarTreeReturnsSameAsStandardRTree.
@Test
public void testBulkLoadingTreeAndStarTreeReturnsSameAsStandardRTree() {
RTree<Integer, Geometry> tree1 = RTree.create();
RTree<Integer, Geometry> tree2 = RTree.star().create();
Rectangle[] testRects = { rectangle(0, 0, 0, 0), rectangle(0, 0, 100, 100), rectangle(0, 0, 10, 10), rectangle(0.12, 0.25, 50.356, 50.756), rectangle(1, 0.252, 50, 69.23), rectangle(13.12, 23.123, 50.45, 80.9), rectangle(10, 10, 50, 50) };
List<Entry<Integer, Geometry>> entries = new ArrayList<Entry<Integer, Geometry>>(10000);
for (int i = 1; i <= 10000; i++) {
Point point = nextPoint();
// System.out.println("point(" + point.x() + "," + point.y() +
// "),");
tree1 = tree1.add(i, point);
tree2 = tree2.add(i, point);
entries.add(new EntryDefault<Integer, Geometry>(i, point));
}
RTree<Integer, Geometry> tree3 = RTree.create(entries);
for (Rectangle r : testRects) {
Set<Integer> res1 = new HashSet<Integer>(Observable.from(tree1.search(r)).map(RTreeTest.<Integer>toValue()).toList().toBlocking().single());
Set<Integer> res2 = new HashSet<Integer>(Observable.from(tree2.search(r)).map(RTreeTest.<Integer>toValue()).toList().toBlocking().single());
Set<Integer> res3 = new HashSet<Integer>(Observable.from(tree3.search(r)).map(RTreeTest.<Integer>toValue()).toList().toBlocking().single());
System.out.println("searchRect= rectangle(" + r.x1() + "," + r.y1() + "," + r.x2() + "," + r.y2() + ")");
System.out.println("res1.size=" + res1.size() + ",res2.size=" + res2.size() + ",res3.size=" + res3.size());
// System.out.println("res1=" + res1 + ",res2=" + res2 + ",res3=" + res3);
assertEquals(res1.size(), res2.size());
assertEquals(res1.size(), res3.size());
}
}
use of me.wobblyyyy.pathfinder2.geometry.Geometry in project rtree2 by davidmoten.
the class RTreeTest method testStandardRTreeSearch.
@Test
public void testStandardRTreeSearch() {
Rectangle r = rectangle(13.0, 23.0, 50.0, 80.0);
Point[] points = { point(59.0, 91.0), point(86.0, 14.0), point(36.0, 60.0), point(57.0, 36.0), point(14.0, 37.0) };
RTree<Integer, Geometry> tree = RTree.create();
for (int i = 0; i < points.length; i++) {
Point point = points[i];
System.out.println("point(" + point.x() + "," + point.y() + "), value=" + (i + 1));
tree = tree.add(i + 1, point);
}
System.out.println(tree.asString());
System.out.println("searching " + r);
Set<Integer> set = new HashSet<Integer>(Observable.from(tree.search(r)).map(RTreeTest.<Integer>toValue()).toList().toBlocking().single());
assertEquals(new HashSet<Integer>(asList(3, 5)), set);
}
use of me.wobblyyyy.pathfinder2.geometry.Geometry in project rtree2 by davidmoten.
the class RTreeTest method testVisualizer.
@Test
public void testVisualizer() {
List<Entry<Object, Geometry>> entries = createRandomEntries(1000);
int maxChildren = 8;
RTree<Object, Geometry> tree = RTree.maxChildren(maxChildren).create().add(entries);
tree.visualize(600, 600).save("target/tree.png");
RTree<Object, Geometry> tree2 = RTree.star().maxChildren(maxChildren).create().add(entries);
tree2.visualize(600, 600).save("target/tree2.png");
RTree<Object, Geometry> tree3 = RTree.maxChildren(maxChildren).create(entries);
tree3.visualize(600, 600).save("target/tree3.png");
}
use of me.wobblyyyy.pathfinder2.geometry.Geometry in project rtree2 by davidmoten.
the class RTreeTest method testStandardRTreeSearch2.
@Test
public void testStandardRTreeSearch2() {
Rectangle r = rectangle(10.0, 10.0, 50.0, 50.0);
Point[] points = { point(28.0, 19.0), point(29.0, 4.0), point(10.0, 63.0), point(34.0, 85.0), point(62.0, 45.0) };
RTree<Integer, Geometry> tree = RTree.create();
for (int i = 0; i < points.length; i++) {
Point point = points[i];
System.out.println("point(" + point.x() + "," + point.y() + "), value=" + (i + 1));
tree = tree.add(i + 1, point);
}
System.out.println(tree.asString());
System.out.println("searching " + r);
Set<Integer> set = new HashSet<Integer>(Observable.from(tree.search(r)).map(RTreeTest.<Integer>toValue()).toList().toBlocking().single());
assertEquals(new HashSet<Integer>(asList(1)), set);
}
Aggregations