def test_fromPoints_onePoint(self): points = [Point(0, 1, 1)] bbox = BBox.fromPoints(points) self.assertEqual(bbox.lowerX, 0) self.assertEqual(bbox.lowerY, 1) self.assertEqual(bbox.upperX, 0) self.assertEqual(bbox.upperY, 1)
def test_fromPoints_emptylist(self): points = [] bbox = BBox.fromPoints(points) self.assertEqual(bbox.lowerX, None) self.assertEqual(bbox.lowerY, None) self.assertEqual(bbox.upperX, None) self.assertEqual(bbox.upperY, None)
def test_bboxQuery_largedata(self): points = [Point(x, y, 1) for x, y in combinations(range(-200, 200), 2)] correct = list(filter(lambda f: f[0] >= -10 and f[0] <= 10 and f[1] >= -10 and f[1] <= 10, points)) tree = RangeTree() tree.create(points) bbox = BBox(-10, -10, 10, 10) result = tree.bboxQuery(bbox) self.assertEqual(len(result), len(correct)) self.assertEqual(set(correct), set(result))
def get_points(): try: args = request.args.to_dict() bbox = BBox(float(args['lowerx']), float(args['lowery']), float(args['upperx']), float(args['uppery'])) except GeometryException: return make_response('Geometry Exception: invalid bounding box', 400) except TypeError: return make_response( 'Invalid inputs. Please use float args for lowerx, lowery, upperx, uppery', 400) return jsonify([p.heatPoint() for p in tree.bboxQuery(bbox)])
def test_fromPoints_multiPoint(self): points = [ Point(0, 1, 1), Point(2, 1, 1), Point(-8, 6, 1), Point(9, -1, 1), ] bbox = BBox.fromPoints(points) self.assertEqual(bbox.lowerX, -8) self.assertEqual(bbox.lowerY, -1) self.assertEqual(bbox.upperX, 9) self.assertEqual(bbox.upperY, 6)
def test_bboxQuery_miss(self): points = [ Point(-2, 1, 1), Point(-1, 0, 1), Point(-2, 0, 1), Point(-2, 0, 1), Point(0, 0, 1), Point(1, 0, 1), Point(3, 3, 1), ] tree = RangeTree() tree.create(points) bbox = BBox(5, 5, 7, 7) result = tree.bboxQuery(bbox) self.assertEqual(result, [])
def test_bboxQuery_simple(self): points = [ Point(-2, 1, 1), Point(-1, 0, 1), Point(-2, 0, 1), Point(0, 0, 1), Point(1, 0, 1), Point(3, 3, 1), ] correct = [ Point(-2, 1, 1), Point(-1, 0, 1), Point(-2, 0, 1), ] tree = RangeTree() tree.create(points) bbox = BBox(-2.5, -2, -0.5, 2) result = tree.bboxQuery(bbox) self.assertEqual(len(result), len(correct)) self.assertEqual(set(result), set(correct))
def test_intersects_nonOverlapping(self): oneBox = BBox(1, 1, 2, 2) twoBox = BBox(3, 3, 4, 4) self.assertFalse(oneBox.intersects(twoBox)) self.assertFalse(twoBox.intersects(oneBox))
def test_intersects_overlapping(self): oneBox = BBox(0, 0, 1, 1) twoBox = BBox(-1, -1, .5, .5) self.assertTrue(oneBox.intersects(twoBox)) self.assertTrue(twoBox.intersects(oneBox))
def test_intersects_within(self): littleBox = BBox(-1, -1, 1, 1) bigBox = BBox(-2, -2, 2, 2) self.assertTrue(littleBox.intersects(bigBox)) self.assertTrue(bigBox.intersects(littleBox))
def test_isWithin_contains(self): littleBox = BBox(-1, -1, 1, 1) bigBox = BBox(-2, -2, 2, 2) self.assertFalse(bigBox.isWithin(littleBox))
def test_isWithin_nonOverlapping(self): oneBox = BBox(1, 1, 2, 2) twoBox = BBox(3, 3, 4, 4) self.assertFalse(oneBox.isWithin(twoBox))
def test_isWithin_overlapping(self): oneBox = BBox(0, 0, 1, 1) twoBox = BBox(-1, -1, .5, .5) self.assertFalse(oneBox.isWithin(twoBox))
def test_isWithin_happyCase(self): littleBox = BBox(-1, -1, 1, 1) bigBox = BBox(-2, -2, 2, 2) self.assertTrue(littleBox.isWithin(bigBox))