예제 #1
0
    def test_intersection(self):
        # type: (RectangleTestCase) -> None
        p1 = (0.0, 0.75)
        p2 = (1.0, 1.75)
        r1 = Rectangle(p1, p2)

        p3 = (0.5, 0.0)
        p4 = (1.5, 1.0)
        r2 = Rectangle(p3, p4)

        p5 = (1.0, 1.0)
        p6 = (2.0, 2.0)
        r3 = Rectangle(p5, p6)

        p7 = (1.5, 0.0)
        p8 = (2.0, 1.0)
        r4 = Rectangle(p7, p8)

        p9 = (0.5, 1.0)
        r5 = Rectangle(p9, p2)

        p10 = (0.5, 1.75)
        r6 = Rectangle(p1, p10)

        p1_intersect = (0.5, 0.75)
        p2_intersect = (1.0, 1.0)
        r_intersect_expected = Rectangle(p1_intersect, p2_intersect)
        r_intersect = r1.intersection(r2)

        # Intersection of Rectangles
        self.assertTrue(r1.overlaps(r2))
        self.assertTrue(not r1.overlaps(r3))
        self.assertTrue(not r1.overlaps(r4))
        self.assertTrue(r1.overlaps(r5))
        self.assertTrue(r1.overlaps(r6))
        self.assertTrue(r2.overlaps(r1))
        self.assertTrue(not r2.overlaps(r3))
        self.assertTrue(not r2.overlaps(r4))
        self.assertTrue(not r3.overlaps(r1))
        self.assertTrue(not r3.overlaps(r2))
        self.assertTrue(not r3.overlaps(r4))
        self.assertTrue(not r4.overlaps(r1))
        self.assertTrue(not r4.overlaps(r2))
        self.assertTrue(not r4.overlaps(r3))

        #####
        self.assertEqual(r_intersect, r_intersect_expected)
        self.assertEqual(r1.intersection(r5), r5)
        self.assertEqual(r1.intersection(r6), r6)
        self.assertEqual(r5.intersection(r1), r5)
        self.assertEqual(r6.intersection(r1), r6)
예제 #2
0
    def test_concatenation(self):
        # type: (RectangleTestCase) -> None
        p1 = (0.0, 0.75)
        p2 = (1.0, 1.75)
        r1 = Rectangle(p1, p2)

        p3 = (0.5, 0.0)
        p4 = (1.5, 1.0)
        r2 = Rectangle(p3, p4)

        p5 = (1.0, 1.0)
        p6 = (2.0, 2.0)
        r3 = Rectangle(p5, p6)

        p7 = (1.5, 0.0)
        p8 = (2.0, 1.0)
        r4 = Rectangle(p7, p8)

        p9 = (0.5, 1.0)
        r5 = Rectangle(p9, p2)

        p10 = (0.5, 1.75)
        r6 = Rectangle(p1, p10)

        r_intersect = r1.intersection(r2)

        # Concatenation of Rectangles
        self.assertTrue(not r1.is_concatenable(r2))
        self.assertTrue(not r1.is_concatenable(r3))
        self.assertTrue(not r1.is_concatenable(r4))
        self.assertTrue(not r1.is_concatenable(r5))
        self.assertTrue(not r1.is_concatenable(r6))
        self.assertTrue(not r2.is_concatenable(r1))
        self.assertTrue(not r2.is_concatenable(r3))
        self.assertTrue(r2.is_concatenable(r4))
        self.assertTrue(not r2.is_concatenable(r5))
        self.assertTrue(not r2.is_concatenable(r6))
        self.assertTrue(not r3.is_concatenable(r1))
        self.assertTrue(not r3.is_concatenable(r2))
        self.assertTrue(not r4.is_concatenable(r1))
        self.assertTrue(r4.is_concatenable(r2))
        self.assertTrue(not r5.is_concatenable(r1))
        self.assertTrue(not r5.is_concatenable(r2))
        self.assertTrue(not r5.is_concatenable(r6))
        self.assertTrue(not r6.is_concatenable(r1))
        self.assertTrue(not r6.is_concatenable(r2))
        self.assertTrue(not r6.is_concatenable(r5))

        self.assertEqual(r1, r_intersect.concatenate(r5).concatenate(r6))
        self.assertEqual(r4, r2.concatenate(r4).intersection(r4))
예제 #3
0
    def test_volumes(self):
        # type: (RectangleTestCase) -> None
        p1 = (0.0, 0.75)
        p2 = (1.0, 1.75)
        r1 = Rectangle(p1, p2)

        p3 = (0.5, 0.0)
        p4 = (1.5, 1.0)
        r2 = Rectangle(p3, p4)

        p5 = (1.0, 1.0)
        p6 = (2.0, 2.0)
        r3 = Rectangle(p5, p6)

        r_intersect = r1.intersection(r2)

        # Volumes
        self.assertEqual(r1.volume(), r2.volume())
        self.assertEqual(r3.volume(), r1.volume())
        self.assertEqual(r3.volume(), r2.volume())

        self.assertGreater(r1.volume(), r_intersect.volume())
        self.assertGreater(r2.volume(), r_intersect.volume())