Exemplo n.º 1
0
 def setup(self):
     points = [(1, 1), (-1, 1), (-1, -1), (1, -1), (.1, .1), (-.1, .1),
               (-.1, -.1), (.1, -.1)]
     self.angles = Polygon.get_angles_for_points_from_point((0, 0), points)
     self.relative_angles = [
         Polygon.delta_angle(a, 90) for a in self.angles
     ]
Exemplo n.º 2
0
 def build_polygon(self):
     if self._n_parts_alive <= 1:
         self._callback("broken")
         raise PartConnectionError("Not enough parts")
     lines = []
     for part, next_part in self._pairwise():
         lines.append(Line([(part.position.x, part.position.z), (next_part.position.x, next_part.position.z)]))
     polygon = Polygon(lines)
     #if self.validate_connection_function(polygon):
     return polygon
Exemplo n.º 3
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.º 4
0
 def __init__(self, polygon: Polygon, material: OpenGLMaterial):
     self.material = material
     self.polygon = polygon
     self.line_triples: Dict[Line, Tuple[Line, Line]] = {
         t: (p, n)
         for p, t, n in polygon.lines_outer_triplets()
     }
     self.line_faces: Dict[Line, Tuple[OpenGLFace, OpenGLFace]] = {
         l: self.make_faces(l)
         for l in polygon.lines
     }
     faces = list(chain(*self.line_faces.values()))
     for line in polygon.lines:
         line.observe(self.line_callback, "move")
         self.line_callback(line)
     super().__init__(faces, [])
Exemplo n.º 5
0
 def setup(self):
     self.target = Polygon.manufacture([(-5, 0), (-2, -3), (1, 0), (-2, 3)])
Exemplo n.º 6
0
 def setup(self):
     self.target = Polygon.manufacture([(-5, -5), (5, -5), (5, 5), (-5, 5)])
Exemplo n.º 7
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.º 8
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
Exemplo n.º 9
0
 def setup(self):
     points = [(0, 0), (1, 1), (-1, 1), (-1, -1), (1, -1), (.1, .1),
               (-.1, .1), (-.1, -.1), (.1, -.1)]
     self.hull = Polygon.convex_hull(points)