def testContainRects(self): for r in take(1000, G.rect): self.assertTrue(r.does_contain(r)) ix = r.intersect(G.intersectingWith(r)) self.assertTrue(r.does_contain(ix)) out = G.disjointWith(r) self.assertFalse(r.does_contain(out))
def testDegenerateContainer(self): """ Tests that an r-tree still works like a container even with highly overlapping rects. """ xs = [TstO(r) for r in take(1000, G.rect, 20.0)] tree = RTree() for x in xs: tree.insert(x, x.rect) self.invariants(tree) ws = [ x.leaf_obj() for x in tree.walk(lambda x, y: True) if x.is_leaf() ] for x in xs: self.assertTrue(x in ws)
def testPointQuery(self): xs = [TstO(r) for r in take(1000, G.rect, 0.01)] tree = RTree() for x in xs: tree.insert(x, x.rect) self.invariants(tree) for x in xs: qp = G.pointInside(x.rect) self.assertTrue(x.rect.does_containpoint(qp)) op = G.pointOutside(x.rect) rs = list([r.leaf_obj() for r in tree.query_point(qp)]) self.assertTrue(x in rs, "Not in results of len %d :(" % (len(rs))) rrs = list([r.leaf_obj() for r in tree.query_point(op)]) self.assertFalse(x in rrs)
def testRectQuery(self): xs = [TstO(r) for r in take(1000, G.rect, 0.01)] rt = RTree() for x in xs: rt.insert(x, x.rect) self.invariants(rt) for x in xs: qrect = G.intersectingWith(x.rect) orect = G.disjointWith(x.rect) self.assertTrue(qrect.does_intersect(x.rect)) p = G.pointInside(x.rect) res = list([ro.leaf_obj() for ro in rt.query_point(p)]) self.invariants(rt) self.assertTrue(x in res) res2 = list([r.leaf_obj() for r in rt.query_rect(qrect)]) self.assertTrue(x in res2) rres = list([r.leaf_obj() for r in rt.query_rect(orect)]) self.assertFalse(x in rres)
def testContainer(self): """ Test container-like behaviour. """ xs = [TstO(r) for r in take(100, G.rect, 0.1)] tree = RTree() for x in xs: tree.insert(x, x.rect) self.invariants(tree) ws = [ x.leaf_obj() for x in tree.walk(lambda x, y: True) if x.is_leaf() ] self.invariants(tree) rrs = collections.defaultdict(int) for w in ws: rrs[w] = rrs[w] + 1 for x in xs: self.assertEqual(rrs[x], 1)
def testContainPoint(self): rs = take(100, G.rect) for r in rs: self.assertTrue(r.does_containpoint(G.pointInside(r))) self.assertFalse(r.does_containpoint(G.pointOutside(r)))