Ejemplo n.º 1
0
def test_write_dxf():
    entity = LWPolyline.from_text(LWPOLYLINE)
    collector = TagCollector()
    entity.export_dxf(collector)
    assert len(collector.tags) == 0, "do not export empty polylines"
    entity.append((1, 2))
    entity.export_dxf(collector)
    result = collector.tags
    expected = basic_tags_from_text(RESULT1)
    assert result == expected
Ejemplo n.º 2
0
def test_lwpolyline_transform_interface():
    pline = LWPolyline()
    pline.set_points([(0, 0), (2, 0), (1, 1)], format='xy')
    pline.translate(1, 1, 1)
    vertices = list(pline.vertices())
    assert vertices[0] == (1, 1)
    assert vertices[1] == (3, 1)
    assert vertices[2] == (2, 2)
    assert pline.dxf.elevation == 1
    assert Vector(0, 0, 1).isclose(pline.dxf.extrusion)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
def test_default_init():
    dxfclass = LWPolyline()
    assert dxfclass.dxftype() == "LWPOLYLINE"
    assert dxfclass.dxf.handle is None
    assert dxfclass.dxf.owner is None
    assert dxfclass.dxf.hasattr("const_width") is False
Ejemplo n.º 9
0
def entity():
    return LWPolyline.from_text(LWPOLYLINE)
Ejemplo n.º 10
0
def test_raises_dxf_structure_error_for_missing_AcDbPolyline_subclass():
    with pytest.raises(DXFStructureError):
        LWPolyline.from_text(LWPOLYLINE_ERR)
Ejemplo n.º 11
0
def test_has_arc():
    pline = LWPolyline()
    assert pline.has_arc is False
    pline.lwpoints.append((0, 0, 0, 0, 1))
    assert pline.has_arc is True
Ejemplo n.º 12
0
def test_has_const_width():
    pline = LWPolyline()
    assert pline.has_width is False
    pline.dxf.const_width = 1
    assert pline.has_width is True
Ejemplo n.º 13
0
def lwpolyline():
    entity = LWPolyline.new(dxfattribs={'layer': 'LAY', 'color': 1})
    entity.set_points(POINTS, format='xyb')
    return entity
Ejemplo n.º 14
0
def test_default_init():
    dxfclass = LWPolyline()
    assert dxfclass.dxftype() == 'LWPOLYLINE'
    assert dxfclass.dxf.handle is None
    assert dxfclass.dxf.owner is None
Ejemplo n.º 15
0
def lwpolyline(points, dxfattribs=None):
    line = LWPolyline.new(dxfattribs=dxfattribs)
    line.set_points(points)
    return line
Ejemplo n.º 16
0
def test_has_any_end_width():
    pline = LWPolyline()
    assert pline.has_width is False
    pline.lwpoints.append((0, 0, 0, 0.1, 0))
    assert pline.has_width is True
Ejemplo n.º 17
0
def lwpolyline():
    entity = LWPolyline.new(dxfattribs={"layer": "LAY", "color": 1})
    entity.set_points(POINTS, format="xyb")
    return entity