def test_three_overlapping(self):
        # type: () -> None
        """
         __ ___ __ __
        | 1| 1 | 3| 3|  
        |__|_2_|_2|__| 

         __ ___ __ __
        | 1| 2 | 4| 6|  
        |__|_3_|_5|__| 
        
        """
        poly1 = Polygon3D([(0, 1, 0), (0, 0, 0), (2, 0, 0), (2, 1, 0)])
        poly2 = Polygon3D([(3, 1, 0), (3, 0, 0), (1, 0, 0), (1, 1, 0)])
        poly3 = Polygon3D([(2, 1, 0), (2, 0, 0), (4, 0, 0), (4, 1, 0)])
        adjacencies = [(poly1, poly2), (poly2, poly3)]
        poly1 = Polygon3D([(0, 1, 0), (0, 0, 0), (1, 0, 0), (1, 1, 0)])
        poly2 = Polygon3D([(2, 1, 0), (2, 0, 0), (1, 0, 0), (1, 1, 0)])
        poly3 = Polygon3D([(1, 1, 0), (1, 0, 0), (2, 0, 0), (2, 1, 0)])
        poly4 = Polygon3D([(2, 1, 0), (2, 0, 0), (3, 0, 0), (3, 1, 0)])
        poly5 = Polygon3D([(3, 1, 0), (3, 0, 0), (2, 0, 0), (2, 1, 0)])
        poly6 = Polygon3D([(3, 1, 0), (3, 0, 0), (4, 0, 0), (4, 1, 0)])
        expected = [poly1, poly2, poly3, poly4, poly5, poly6]

        result = intersect(*adjacencies[0])
        result.extend(intersect(*adjacencies[1]))

        assert len(minimal_set(result)) == len(minimal_set(expected))
        for poly in expected:
            assert poly in result
    def test_simple_overlap(self):
        # type: () -> None
        """
        The intersect function should return four surfaces.
         __ ___ __ 
        | 1| 1 |  |  
        |__|_2_|_2| 

         __ ___ __ 
        | 1| 3 |  |  
        |__|_4_|_2| 

        """
        poly1 = Polygon3D([(0, 1, 0), (0, 0, 0), (2, 0, 0), (2, 1, 0)])
        poly2 = Polygon3D([(3, 1, 0), (3, 0, 0), (1, 0, 0), (1, 1, 0)])
        adjacencies = [(poly1, poly2)]
        poly1 = Polygon3D([(0, 1, 0), (0, 0, 0), (1, 0, 0), (1, 1, 0)])
        poly2 = Polygon3D([(3, 1, 0), (3, 0, 0), (2, 0, 0), (2, 1, 0)])
        poly3 = Polygon3D([(1, 1, 0), (1, 0, 0), (2, 0, 0), (2, 1, 0)])
        poly4 = Polygon3D([(2, 1, 0), (2, 0, 0), (1, 0, 0), (1, 1, 0)])
        result = intersect(*adjacencies[0])
        expected = [poly1, poly2, poly3, poly4]
        assert len(result) == len(expected)
        for poly in expected:
            assert poly in result
 def test_vertically_offset(self):
     # type: () -> None
     """
      ___
     |_1_|
     | 1 |
     |_2_|
     |_2_|
      ___
     |_1_|
     | 2 |
     |_3_|
     |_4_|
      
     """
     poly1 = Polygon3D([(0, 0, 1), (0, 0, 0), (2, 0, 0), (2, 0, 1)])
     poly2 = Polygon3D([(3, 0, 1), (3, 0, 0), (1, 0, 0), (1, 0, 1)])
     adjacencies = [(poly1, poly2)]
     poly1 = Polygon3D([(0, 0, 1), (0, 0, 0), (1, 0, 0), (1, 0, 1)])
     poly2 = Polygon3D([(3, 0, 1), (3, 0, 0), (2, 0, 0), (2, 0, 1)])
     poly3 = Polygon3D([(1, 0, 1), (1, 0, 0), (2, 0, 0), (2, 0, 1)])
     poly4 = Polygon3D([(2, 0, 1), (2, 0, 0), (1, 0, 0), (1, 0, 1)])
     result = intersect(*adjacencies[0])
     expected = [poly1, poly2, poly3, poly4]
     assert len(result) == len(expected)
     for poly in expected:
         assert poly in result
    def test_double_overlap(self):
        # type: () -> None
        """
         __________
        |__1_______| 
        | 1 | 2 |1 |
        |_2_|   |2_|
        |__________|
        
         __________
        |__1________| 
        | 2 | 4 | 5 |
        |_3_|   |_6_|
        |___________|
        
        """
        poly1 = Polygon3D([(0, 2, 0), (0, 0, 0), (3, 0, 0), (3, 2, 0)])
        poly2 = Polygon3D(
            [
                (3, 3, 0),
                (3, 1, 0),
                (2, 1, 0),
                (2, 2, 0),
                (1, 2, 0),
                (1, 1, 0),
                (0, 1, 0),
                (0, 3, 0),
            ]
        )
        adjacencies = [(poly1, poly2)]

        poly1 = Polygon3D([(3, 3, 0), (3, 2, 0), (0, 2, 0), (0, 3, 0)])
        poly2 = Polygon3D([(0, 2, 0), (0, 1, 0), (1, 1, 0), (1, 2, 0)])
        poly3 = Polygon3D([(1, 2, 0), (1, 1, 0), (0, 1, 0), (0, 2, 0)])
        poly4 = Polygon3D(
            [
                (1, 2, 0),
                (1, 1, 0),
                (0, 1, 0),
                (0, 0, 0),
                (3, 0, 0),
                (3, 1, 0),
                (2, 1, 0),
                (2, 2, 0),
            ]
        )
        poly5 = Polygon3D([(2, 2, 0), (2, 1, 0), (3, 1, 0), (3, 2, 0)])
        poly6 = Polygon3D([(3, 2, 0), (3, 1, 0), (2, 1, 0), (2, 2, 0)])

        result = intersect(*adjacencies[0])
        expected = [poly1, poly2, poly3, poly4, poly5, poly6]
        assert len(result) == len(expected)
        assert len(result) == len(expected)
        for poly in expected:
            assert poly in result
    def test_simple_match(self):
        # type: () -> None
        """
        The intersect function should just return the two polygons.
         ___  
        | 1 |
        |_2_| 

        """
        poly1 = Polygon3D([(0, 1, 0), (0, 0, 0), (1, 0, 0), (1, 1, 0)])
        poly2 = Polygon3D([(1, 1, 0), (1, 0, 0), (0, 0, 0), (0, 1, 0)])
        adjacencies = [(poly1, poly2)]
        result = intersect(*adjacencies[0])
        expected = [poly1, poly2]
        assert len(result) == len(expected)
        for poly in expected:
            assert poly in result
    def test_simple_hole(self):
        # type: () -> None
        """
         _________ 
        | 1 ___   |  
        |  | 2 |  |
        |  |___|  | 
        |_________|
        
         ________ 
        |\ ___   |  
        |1| 2 | 4|
        | |_3_|  | 
        |/_______|
        
        """
        poly1 = Polygon3D([(0, 4, 0), (0, 0, 0), (4, 0, 0), (4, 4, 0)])
        poly2 = Polygon3D([(2, 2, 0), (2, 1, 0), (1, 1, 0), (1, 2, 0)])
        adjacencies = [(poly1, poly2)]

        poly1 = Polygon3D(
            [(0, 4, 0), (0, 0, 0), (1, 1, 0), (1, 2, 0)]
        )  # smaller section
        poly2 = Polygon3D([(1, 2, 0), (1, 1, 0), (2, 1, 0), (2, 2, 0)])  # inverse hole
        poly3 = Polygon3D([(2, 2, 0), (2, 1, 0), (1, 1, 0), (1, 2, 0)])  # hole
        poly4 = Polygon3D(
            [
                (4, 4, 0),
                (0, 4, 0),
                (1, 2, 0),
                (2, 2, 0),
                (2, 1, 0),
                (1, 1, 0),
                (0, 0, 0),
                (4, 0, 0),
            ]
        )  # larger section
        result = intersect(*adjacencies[0])
        expected = [poly1, poly2, poly3, poly4]
        assert len(result) == len(expected)
        for poly in expected:
            assert poly in result