def test_border_intersection(self):
     c1 = Circle(Vec2(0, 0), 2)
     c2 = Circle(Vec2(3, 4), 3)
     self.assertFalse(intersects(c1, c2))
     self.assertTrue(intersects(c1, c2, border=True))
     self.assertFalse(contains(c1, c2))
     self.assertFalse(contains(c2, c1))
 def test_bbox_in_circle_border(self):
     # Egyptian triangle (3, 4, 5)
     c = Circle(Vec2(0, 0), 5)
     r = BoundingBox([Vec2(-3, -4), Vec2(3, 4)])
     self.assertTrue(intersects(c, r))
     self.assertTrue(contains(c, r))
     self.assertFalse(contains(r, c))
 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))
Beispiel #4
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]))
 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))
 def test_corner_intersection(self):
     # Egyptian triangle (3, 4, 5)
     c = Circle(Vec2(0, 0), 5)
     r = BoundingBox([Vec2(3, 4), Vec2(5, 6)])
     self.assertFalse(intersects(c, r))
     self.assertTrue(intersects(c, r, border=True))
 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))
 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))
 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))
 def test_intersects(self):
     c1 = Circle(Vec2(0, 0), 4)
     c2 = Circle(Vec2(2, 2), 4)
     self.assertTrue(intersects(c1, c2))
     self.assertFalse(contains(c1, c2))
     self.assertFalse(contains(c2, c1))
 def test_no_intersection(self):
     c1 = Circle(Vec2(0, 0), 2)
     c2 = Circle(Vec2(10, 10), 2)
     self.assertFalse(intersects(c1, c2))
     self.assertFalse(contains(c1, c2))
     self.assertFalse(contains(c2, c1))