コード例 #1
0
 def test_ComplexPolygon_ReturnCorrectPolygons_0(self):
     polygon = SimplePolygon(
         vertices=array([
             (0, 0, 0),
             (4, 0, 0),
             (2, 2, 0),
             (4, 4, 0),
             (0, 4, 0)
         ]))
     plane = Plane(
         point_in_plane=array([1, 0, 0]),
         normal_vector=array([1, 0, 0]))
     actual = split_by_plane(
         object_to_split=polygon,
         plane=plane)
     expected = [
         SimplePolygon(
             vertices=array([
                 (1, 4, 0),
                 (0, 4, 0),
                 (0, 0, 0),
                 (1, 0, 0)
             ])),
         SimplePolygon(
             vertices=array([
                 (1, 0, 0),
                 (4, 0, 0),
                 (2, 2, 0),
                 (4, 4, 0),
                 (1, 4, 0)
             ]))
     ]
     assert actual == expected
コード例 #2
0
 def test_FourthQuadrantLShapedPolygonWithShortEdgeOnPlane_ReturnCorrectPolygons(self, normal_vector):
     polygon = SimplePolygon(
         vertices=array([
             (-1, -1, 0),
             (0, -1, 0),
             (0, 0, 0),
             (1, 0, 0),
             (1, 1, 0),
             (-1, 1, 0)
         ]))
     plane = Plane(
         point_in_plane=array([0, 0, 0]),
         normal_vector=normal_vector)
     actual = split_by_plane(
         object_to_split=polygon,
         plane=plane)
     expected = [
         SimplePolygon(
             vertices=array([
                 (-1, -1, 0),
                 (0, -1, 0),
                 (0, 0, 0),
                 (-1, 0, 0)
             ])),
         SimplePolygon(
             vertices=array([
                 (1, 0, 0),
                 (1, 1, 0),
                 (-1, 1, 0),
                 (-1, 0, 0)
             ]))
     ]
     assert actual == expected
コード例 #3
0
 def test_ConcavePolygonThatIsNotSplit_ReturnCorrectPolygons(self):
     polygon = SimplePolygon(vertices=array([(0, 0, 0), (1, 0,
                                                         0), (1, 1,
                                                              0), (0, 1,
                                                                   0)]))
     plane = Plane(point_in_plane=array([2, 0, 0]),
                   normal_vector=array([1, 0, 0]))
     actual = split_by_plane(object_to_split=polygon, plane=plane)
     expected = [
         SimplePolygon(vertices=array([(0, 0, 0), (1, 0, 0), (1, 1,
                                                              0), (0, 1,
                                                                   0)]))
     ]
     assert actual == expected
コード例 #4
0
 def test_ComplexPolygon_ReturnCorrectPolygons_1(self):
     polygon = SimplePolygon(
         vertices=array([(0, 0, 0), (4, 0, 0), (2, 2, 0), (4, 4,
                                                           0), (0, 4, 0)]))
     plane = Plane(point_in_plane=array([2, 0, 0]),
                   normal_vector=array([1, 0, 0]))
     actual = split_by_plane(object_to_split=polygon, plane=plane)
     expected = [
         SimplePolygon(vertices=array([(2, 4, 0), (0, 4, 0), (0, 0,
                                                              0), (2, 0,
                                                                   0)])),
         SimplePolygon(vertices=array([(2, 0, 0), (4, 0, 0), (2, 2, 0)])),
         SimplePolygon(vertices=array([(2, 2, 0), (4, 4, 0), (2, 4, 0)]))
     ]
     assert actual == expected
コード例 #5
0
 def test_SimplePolygonWithSegmentOnPlane_ReturnCorrectPolygon(
         self, point_in_plane, normal_vector):
     polygon = SimplePolygon(vertices=array([(0, 0, 0), (1, 0,
                                                         0), (1, 1,
                                                              0), (0, 1,
                                                                   0)]))
     plane = Plane(point_in_plane=point_in_plane,
                   normal_vector=normal_vector)
     actual = split_by_plane(object_to_split=polygon, plane=plane)
     expected = [
         SimplePolygon(vertices=array([(0, 0, 0), (1, 0, 0), (1, 1,
                                                              0), (0, 1,
                                                                   0)]))
     ]
     assert actual == expected
コード例 #6
0
 def test_FourthQuadrantLShapedPolygonWithShortEdgeOnPlane_ReturnCorrectPolygons(
         self, normal_vector):
     polygon = SimplePolygon(
         vertices=array([(-1, -1,
                          0), (0, -1, 0), (0, 0, 0), (1, 0,
                                                      0), (1, 1,
                                                           0), (-1, 1, 0)]))
     plane = Plane(point_in_plane=array([0, 0, 0]),
                   normal_vector=normal_vector)
     actual = split_by_plane(object_to_split=polygon, plane=plane)
     expected = [
         SimplePolygon(vertices=array([(-1, -1,
                                        0), (0, -1, 0), (0, 0, 0), (-1, 0,
                                                                    0)])),
         SimplePolygon(vertices=array([(1, 0, 0), (1, 1, 0), (-1, 1,
                                                              0), (-1, 0,
                                                                   0)]))
     ]
     assert actual == expected
コード例 #7
0
 def test_SimplePolygonWithSegmentOnPlane_ReturnCorrectPolygon(self, point_in_plane, normal_vector):
     polygon = SimplePolygon(
         vertices=array([
             (0, 0, 0),
             (1, 0, 0),
             (1, 1, 0),
             (0, 1, 0)
         ]))
     plane = Plane(
         point_in_plane=point_in_plane,
         normal_vector=normal_vector)
     actual = split_by_plane(
         object_to_split=polygon,
         plane=plane)
     expected = [
         SimplePolygon(
             vertices=array([
                 (0, 0, 0),
                 (1, 0, 0),
                 (1, 1, 0),
                 (0, 1, 0)
             ]))
     ]
     assert actual == expected
コード例 #8
0
 def test_ConcavePolygonThatIsNotSplit_ReturnCorrectPolygons(self):
     polygon = SimplePolygon(
         vertices=array([
             (0, 0, 0),
             (1, 0, 0),
             (1, 1, 0),
             (0, 1, 0)
         ]))
     plane = Plane(
         point_in_plane=array([2, 0, 0]),
         normal_vector=array([1, 0, 0]))
     actual = split_by_plane(
         object_to_split=polygon,
         plane=plane)
     expected = [
         SimplePolygon(
             vertices=array([
                 (0, 0, 0),
                 (1, 0, 0),
                 (1, 1, 0),
                 (0, 1, 0)
             ]))
     ]
     assert actual == expected