Exemplo n.º 1
0
 def __init__(self, view_class=BaseView):
     self.meshes = {}
     self.mesh_factory = factory
     self._view_class = view_class
     self.pre_factorized_views = []
     if view_class == BaseView:
         above_camera = MutableOffsets(0, -100, 0)
         zero = MutableOffsets(0, 0, 0)
         no_angle = MutableDegrees(0, 0, 0)
         no_acceleration = MutableOffsets(0, 0, 0)
         no_torque = MutableDegrees(0, 0, 0)
         bb = Polygon.manufacture([(0, 0)])
         self.dummy_model = BaseModel(position=above_camera, rotation=no_angle,
                                      movement=zero, spin=no_angle, acceleration=no_acceleration,
                                      torque=no_torque, bounding_box=bb)
         self.pre_factorized_views = [self._prefactorize() for i in range(200)]
Exemplo n.º 2
0
 def setup(self):
     self.target = Polygon.manufacture([(-5, 0), (-2, -3), (1, 0), (-2, 3)])
Exemplo n.º 3
0
 def setup(self):
     self.target = Polygon.manufacture([(-5, -5), (5, -5), (5, 5), (-5, 5)])
Exemplo n.º 4
0
 def setup(self):
     poly1 = Polygon.manufacture([(-5, 0), (-2, -3), (1, 0), (-2, 3)])
     poly2 = Polygon.manufacture([(5, 0), (2, -3), (-1, 0), (2, 3)])
     self.bb_intersection = poly1.bounding_box_intersects(poly2)
     self.intersects, self.x, self.y = poly1.intersection_point(poly2)
Exemplo n.º 5
0
    def test_moving_left_and_freezing_moves_all_original_xes_of_lines_left(
            self):
        self.target.set_position_rotation(-1, 0, 0)
        self.target.freeze()
        assert set([line.original_x1 for line in self.target.lines]) == {-6, 4}


class TestPolygonArea(object):
    def setup(self):
        self.target = ClosedPolygon.manufacture([(-1, -1), (-1, 1), (1, 1),
                                                 (1, -1)])

    def test_area_is_four(self):
        assert self.target.area() == 4

    def test_centroid(self):
        assert self.target._centroid() == (0, 0)


p1 = Polygon.manufacture([(0.46, -1.21), (1.29, -1.78), (1.86, -0.95),
                          (1.03, -0.38)])
p2 = Polygon.manufacture([(0.5, 0.5), (-0.5, 0.5), (-0.5, -0.5), (0.5, -0.5)])


@pytest.mark.parametrize("line1,line2", product(p1.lines, p2.lines))
def test_lines_that_should_not_intersect(line1, line2):
    if line1.bounding_box_intersects(line2):
        intersects, x, y = line1.intersection_point(line2)
        assert not intersects