Example #1
0
    def test_same_intersect(self):
        """
        Tests that a rectangle overlaps with itself
        """
        a = r.Rectangle(2, 2, 8, 8)

        # the same rect should overlap
        self.assertTrue(r.Rectangle.intersect(a, a))
Example #2
0
    def test_types_of_overlap(self):
        """
        Test different types of overlap
        """
        # top, left, bottom, right
        a = r.Rectangle(2, 2, 8, 8)
        c = r.Rectangle(4, 4, 8, 8)
        d = r.Rectangle(2, 2, 6, 6)
        e = r.Rectangle(2, 4, 8, 8)
        f = r.Rectangle(2, 2, 8, 6)

        # One rectangle overlapping with bottom right
        self.assertTrue(r.Rectangle.intersect(a, c))

        # Top left
        self.assertTrue(r.Rectangle.intersect(a, d))

        # Top right
        self.assertTrue(r.Rectangle.intersect(a, e))

        # Bottom left
        self.assertTrue(r.Rectangle.intersect(a, f))
Example #3
0
    def test_conglomeration(self):
        """
        Test that the complete bounding rectangle is returned.
        """
        # top, left, bottom, right
        a = r.Rectangle(2, 2, 8, 8)
        c = r.Rectangle(4, 4, 8, 8)
        d = r.Rectangle(2, 2, 6, 6)
        e = r.Rectangle(2, 4, 8, 8)
        f = r.Rectangle(2, 2, 8, 6)

        g = r.Rectangle(2, 2, 16, 16)
        h = r.Rectangle(15, 15, 16, 16)

        self.assertEqual(a, r.Rectangle.merge_rects([a, c, d, e, f]))

        self.assertEqual(g, r.Rectangle.merge_rects([a, h]))
Example #4
0
    def test_types_of_non_overlap(self):
        """
        Test different types of non-overlap
        """
        # top, left, bottom, right
        a = r.Rectangle(2, 2, 8, 8)
        c = r.Rectangle(10, 10, 16, 16)
        d = r.Rectangle(2, 8, 8, 12)
        e = r.Rectangle(8, 2, 10, 8)
        f = r.Rectangle(8, 8, 16, 16)
        g = r.Rectangle(0, 0, 2, 2)

        self.assertFalse(r.Rectangle.intersect(a, c))
        self.assertFalse(r.Rectangle.intersect(a, d))
        self.assertFalse(r.Rectangle.intersect(a, e))
        self.assertFalse(r.Rectangle.intersect(a, f))
        self.assertFalse(r.Rectangle.intersect(a, g))
Example #5
0
 def setUp(self):
     self.global_rect = r.Rectangle(3, 3, 9, 9)
Example #6
0
    def setUp(self):
        # one of these days I'm going to change the openCV interface to make more sense...
        self.google_rectangles = [
            r.Rectangle(193, 279, 236, 297),
            r.Rectangle(255, 279, 275, 294),
            r.Rectangle(241, 282, 250, 294),
            r.Rectangle(343, 279, 353, 294),
            r.Rectangle(353, 279, 410, 298),
            r.Rectangle(316, 279, 333, 294),
            r.Rectangle(275, 280, 310, 294),
            r.Rectangle(272, 279, 274, 293),
            r.Rectangle(237, 279, 240, 294),
            r.Rectangle(391, 225, 428, 240),
            r.Rectangle(319, 226, 338, 237),
            r.Rectangle(341, 225, 387, 240),
            r.Rectangle(228, 226, 273, 237),
            r.Rectangle(178, 225, 224, 240),
            r.Rectangle(559, 151, 573, 171),
            r.Rectangle(29, 152, 43, 167),
            r.Rectangle(396, 44, 437, 89),
            r.Rectangle(334, 44, 376, 108),
            r.Rectangle(286, 44, 331, 89),
            r.Rectangle(238, 44, 283, 89),
            r.Rectangle(382, 21, 392, 87),
            r.Rectangle(382, 21, 392, 87),
            r.Rectangle(167, 19, 235, 89),
            r.Rectangle(167, 19, 235, 89),
        ]

        self.G_blue = r.Rectangle(14, 6, 84, 74)
        self.o_red = r.Rectangle(39, 77, 84, 122)
        self.o_yellow = r.Rectangle(39, 125, 84, 170)
        self.g_blue = r.Rectangle(39, 173, 103, 215)
        self.l_green = r.Rectangle(16, 221, 82, 231)
        self.e_red = r.Rectangle(39, 235, 84, 276)
        self.google_rectangles_small = [
            self.G_blue,
            self.o_red,
            self.o_yellow,
            self.g_blue,
            self.l_green,
            self.e_red,
        ]