Ejemplo n.º 1
0
    def test_intersection_with_other_boundingbox(self):
        """
        Tests that bounding box intersects itself with other bounding boxes.
        """
        for rect_set in self.rect_sets:
            rect1 = rect_set[0]
            rect2 = rect_set[1]
            expectedArea = rect_set[2]
            expectedPercentage = rect_set[3]

            box1 = BoundingBox(*rect1)
            box2 = BoundingBox(*rect2)

            intersection = box1.intersect_with(box2)
            number_of_common_pixels = intersection.get_area()

            # Which one is the smaller rectangle?
            area_box1 = box1.get_area()
            area_box2 = box2.get_area()

            lesser_area = min(area_box1, area_box2)
            percentage = round((number_of_common_pixels / lesser_area) * 100,
                               2)

            self.assertEqual(number_of_common_pixels, expectedArea)
            self.assertEqual(percentage, expectedPercentage)
Ejemplo n.º 2
0
 def test_area(self):
     """
     Tests that bounding box knows its area.
     """
     box = BoundingBox(10, 10, 20, 20)
     self.assertEqual(box.get_area(), 400)