def test_default_new(): entity = LWPolyline.new(handle='ABBA', owner='0', dxfattribs={ 'color': 7, 'const_width': 2, }) assert entity.dxf.layer == '0' assert entity.dxf.color == 7 assert entity.dxf.const_width == 2. assert len(entity) == 0 entity.append((1, 2)) assert len(entity) == 1 assert entity.dxf.count == 1 with pytest.raises(DXFAttributeError): # count not writeable entity.dxf.count = 2
def test_lwpolyline_to_code(): from ezdxf.entities.lwpolyline import LWPolyline entity = LWPolyline.new(handle='ABBA', owner='0', dxfattribs={ 'color': '7', }) entity.set_points([ (1, 2, 0, 0, 0), (4, 3, 0, 0, 0), (7, 8, 0, 0, 0), ]) new_entity = translate_to_code_and_execute(entity) for name in ('color', 'count'): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name) for np, ep in zip(new_entity.get_points(), entity.get_points()): assert np == ep
def test_default_new(): entity = LWPolyline.new( handle="ABBA", owner="0", dxfattribs={ "color": 7, "const_width": 2, }, ) assert entity.dxf.layer == "0" assert entity.dxf.color == 7 assert entity.dxf.const_width == 2.0 assert len(entity) == 0 entity.append((1, 2)) assert len(entity) == 1 assert entity.dxf.count == 1 with pytest.raises(DXFAttributeError): # count not writeable entity.dxf.count = 2
def test_lwpolyline_to_code(): from ezdxf.entities.lwpolyline import LWPolyline entity = LWPolyline.new( handle="ABBA", owner="0", dxfattribs={ "color": "7", }, ) entity.set_points([ (1, 2, 0, 0, 0), (4, 3, 0, 0, 0), (7, 8, 0, 0, 0), ]) new_entity = translate_to_code_and_execute(entity) for name in ("color", "count"): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name) for np, ep in zip(new_entity.get_points(), entity.get_points()): assert np == ep
def test_closed_polyline(): lwpolyline = LWPolyline.new() # Create a circle by LWPOLYLINE: lwpolyline.set_points([(0, 0, 1), (1, 0, 1)], format='xyb') lwpolyline.close(True) result = list(lwpolyline.virtual_entities()) assert len(result) == 2 e = result[0] assert e.dxftype() == 'ARC' assert e.dxf.center.isclose((0.5, 0)) assert e.dxf.radius == 0.5 assert math.isclose(e.dxf.start_angle, 180, abs_tol=1e-12) assert math.isclose(e.dxf.end_angle, 0, abs_tol=1e-12) e = result[1] assert e.dxftype() == 'ARC' assert e.dxf.center.isclose((0.5, 0)) assert e.dxf.radius == 0.5 assert math.isclose(e.dxf.start_angle, 0, abs_tol=1e-12) assert math.isclose(abs(e.dxf.end_angle), 180, abs_tol=1e-12)
def lwpolyline(points, dxfattribs=None): line = LWPolyline.new(dxfattribs=dxfattribs) line.set_points(points) return line
def lwpolyline(): entity = LWPolyline.new(dxfattribs={'layer': 'LAY', 'color': 1}) entity.set_points(POINTS, format='xyb') return entity
def lwpolyline(): entity = LWPolyline.new(dxfattribs={"layer": "LAY", "color": 1}) entity.set_points(POINTS, format="xyb") return entity