コード例 #1
0
 def test_circle_in_bbox_border(self):
     # contains have no need for `border` attributes. It always includes
     # border points.
     c = Circle(Vec2(0, 0), 4)
     r = BoundingBox.from_center(Vec2(0, 0), 8, 8)
     self.assertTrue(intersects(c, r))
     self.assertTrue(contains(r, c))
     self.assertFalse(contains(c, r))
コード例 #2
0
    def test_query(self):
        x = Circle(Vec2(30, 30), 10)
        y = Circle(Vec2(-10, -10), 10)
        z = Circle(Vec2(0, 0), 10)
        self.tree.insert(x, x)
        self.tree.insert(y, y)
        self.tree.insert(z, z)

        # Helper to ignore results order
        o = lambda x: list(sorted(x, key=lambda x: x.center.x))

        # Contains circle
        results = self.tree.query(
            BoundingBox.from_center(Vec2(30, 30), 22, 22))
        self.assertEqual(results, [x])
        # Intersect circle
        results = self.tree.query(
            BoundingBox.from_center(Vec2(20, 40), 10, 10))
        self.assertEqual(results, [x])
        # Is contained in circle
        results = self.tree.query(
            BoundingBox.from_center(Vec2(30, 30), 10, 10))
        self.assertEqual(results, [x])

        # Contains 2 circles
        results = self.tree.query(
            BoundingBox.from_center(Vec2(-5, -5), 32, 32))
        self.assertEqual(o(results), o([y, z]))
        # Intersect 2 circles
        results = self.tree.query(
            BoundingBox.from_center(Vec2(-10, 0), 2, 2))
        self.assertEqual(o(results), o([y, z]))
        # Contained in 2 circles
        results = self.tree.query(
            BoundingBox.from_center(Vec2(-5, -5), 2, 2))
        self.assertEqual(o(results), o([y, z]))

        # Contained in 1 of circles
        results = self.tree.query(
            BoundingBox.from_center(Vec2(-10, -10), 2, 2))
        self.assertEqual(results, [y])

        # Contain all circles
        results = self.tree.query(
            BoundingBox.from_center(Vec2(0, 0), 80, 80))
        self.assertEqual(o(results), o([x, y, z]))
コード例 #3
0
 def test_no_intersection(self):
     c = Circle(Vec2(0, 0), 2)
     r = BoundingBox.from_center(Vec2(10, 10), 2, 2)
     self.assertFalse(intersects(c, r))
     self.assertFalse(contains(c, r))
     self.assertFalse(contains(r, c))
コード例 #4
0
 def test_contains(self):
     b1 = BoundingBox.from_center(Vec2(0, 0), 4, 4)
     b2 = BoundingBox.from_center(Vec2(0, 0), 2, 2)
     self.assertTrue(intersects(b1, b2))
     self.assertTrue(contains(b1, b2))
     self.assertFalse(contains(b2, b1))
コード例 #5
0
 def test_border_intersection(self):
     c = Circle(Vec2(0, 0), 2)
     r = BoundingBox.from_center(Vec2(0, 4), 4, 4)
     self.assertFalse(intersects(c, r))
     self.assertTrue(intersects(c, r, border=True))
コード例 #6
0
 def test_intersection(self):
     c = Circle(Vec2(0, 0), 5)
     r = BoundingBox.from_center(Vec2(0, 6), 4, 4)
     self.assertTrue(intersects(c, r))
     self.assertFalse(contains(c, r))
     self.assertFalse(contains(r, c))
コード例 #7
0
 def test_bbox_in_circle(self):
     c = Circle(Vec2(0, 0), 10)
     r = BoundingBox.from_center(Vec2(0, 0), 2, 2)
     self.assertTrue(intersects(c, r))
     self.assertTrue(contains(c, r))
     self.assertFalse(contains(r, c))