def test_polyline_circle_intersection(self, unit_circle): polyline = Polyline([ Line(Vector2(0, 0), Vector2(3, 4)), Line(Vector2(4, 5), Vector2(5, 6)) ]) assert polyline.intersects(unit_circle) assert unit_circle.intersects(polyline)
def test_polyline_polyline_no_intersection(self, polyline1): polyline2 = Polyline([ Line(Vector2(10, 23), Vector2(23, 42)), Line(Vector2(12, 10), Vector2(33, 44)) ]) assert not polyline1.intersects(polyline2) assert not polyline2.intersects(polyline1)
def _read_ground_line_config(self, ground_line_config): points = [Vector2(x) for x in ground_line_config["points"]] shape = Polyline.from_points(points) color = tuple(ground_line_config["color"]) width = ground_line_config["width"] graphic = PolylineGraphic(shape, color, width) return Ground(shape, graphic)
def test_setting_rotation_moves_sides_correctly(self, polyline1): polyline1.rotation = math.pi / 2 assert polyline_eq( polyline1, Polyline([ Line(Vector2(0, 0), Vector2(0, -2)), Line(Vector2(1, 0), Vector2(2, -2)) ]))
def test_setting_location_moves_sides_correctly(self, polyline1): polyline1.location = Vector2(1, 3) assert polyline_eq( polyline1, Polyline([ Line(Vector2(0 + 1, 0 + 3), Vector2(2 + 1, 0 + 3)), Line(Vector2(0 + 1, 1 + 3), Vector2(2 + 1, 2 + 3)) ]))
def test_location_plus_rotation_change_endpoints_correctly( self, polyline1): polyline1.location = Vector2(1, 3) polyline1.rotation = math.pi / 2 assert polyline_eq( polyline1, Polyline([ Line(Vector2(0 + 1, 0 + 3), Vector2(0 + 1, -2 + 3)), Line(Vector2(1 + 1, 0 + 3), Vector2(2 + 1, -2 + 3)) ]))
def polyline_graphic(self): polyline = Polyline.from_points( [Vector2(0, 0), Vector2(1, 2), Vector2(5, 4)]) return PolylineGraphic(polyline, (1, 2, 3), 2)
def test_polyline_polyline_intersection(self, polyline1): polyline2 = Polyline( [Line(Vector2(2.5 + 1, 3.5 - 1), Vector2(3 - 1, 4 + 1))]) assert polyline1.intersects(polyline2) assert polyline2.intersects(polyline1)
def polyline1(self): return Polyline([ Line(Vector2(2, 3), Vector2(3, 4)), Line(Vector2(4, 5), Vector2(5, 6)) ])
def test_from_points_fails_when_degenerate_lines(self): with pytest.raises(ValueError) as e: Polyline.from_points([Vector2(0, 0), Vector2(0, 0), Vector2(1, 3)]) assert "The Line must have a positive length" == str(e.value)
def test_from_points_sets_data_members_correctly(self): polyline = Polyline.from_points( [Vector2(0, 0), Vector2(0, 1), Vector2(1, 3)]) assert line_eq(polyline.lines[0], Line(Vector2(0, 0), Vector2(0, 1))) assert line_eq(polyline.lines[1], Line(Vector2(0, 1), Vector2(1, 3)))
def polyline1(self): return Polyline([ Line(Vector2(0, 0), Vector2(2, 0)), Line(Vector2(0, 1), Vector2(2, 2)) ])