def test_GivenPlaneAndGivenPointArray_ReturnIfPlaneContainsPoints(self):
     plane = Plane((1, 2, 3), (1, 1, 1))
     points = array(
         [
             (1, 2, 3),
             (0, 0, 0),
             (2, 2, 2)
         ])
     contained = array(
         [
             True,
             False,
             True
         ])
     assert_array_equal(plane.contains(points), contained)
 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
 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
 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
 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
Beispiel #6
0
class TestContains:
    @pytest.mark.parametrize(('plane', 'point', 'contained'), [
        (Plane((0, 0, 0), (0, 0, 1)), (0, 0, 0), True),
        (Plane((0, 0, 0), (0, 0, 1)), (1, 0, 0), True),
        (Plane((0, 0, 0), (0, 0, 1)), (0, 1, 0), True),
        (Plane((0, 0, 0), (0, 0, 1)), (0, 0, 1), False),
        (Plane((0, 0, 1), (0, 0, 1)), (0, 0, 0), False),
        (Plane((0, 0, 1), (0, 0, 1)), (0, 0, 1), True),
        (Plane((0, 0, 1), (0, 0, 1)), (0, 0, 2), False),
    ])
    def test_GivenPlaneAndGivenPoint_ReturnIfPlaneContainsPoint(
            self, plane, point, contained):
        assert plane.contains(point) is contained

    def test_GivenPlaneAndGivenPointArray_ReturnIfPlaneContainsPoints(self):
        plane = Plane((1, 2, 3), (1, 1, 1))
        points = array([(1, 2, 3), (0, 0, 0), (2, 2, 2)])
        contained = array([True, False, True])
        assert_array_equal(plane.contains(points), contained)
Beispiel #7
0
 def test_GivenPlaneAndGivenPointArray_ReturnIfPlaneContainsPoints(self):
     plane = Plane((1, 2, 3), (1, 1, 1))
     points = array([(1, 2, 3), (0, 0, 0), (2, 2, 2)])
     contained = array([True, False, True])
     assert_array_equal(plane.contains(points), contained)