def test_2d_polyline_including_width_to_primitive():
    from ezdxf.layouts import VirtualLayout

    vl = VirtualLayout()

    p1 = (0, 0, 1, 1, 0)
    p2 = (2, 0, 0, 0, 0)
    lwp = vl.add_lwpolyline([p1, p2], dxfattribs={"elevation": 1})
    p2d = vl.add_polyline2d([p1, p2],
                            format="xyseb",
                            dxfattribs={"elevation": (0, 0, 1)})

    for e in [lwp, p2d]:
        p = disassemble.make_primitive(e)
        assert p.is_empty is False
        assert p.path is None
        assert (
            p.mesh
            is not None), "2D polylines including width should create a mesh"
        vertices = list(p.vertices())
        assert len(vertices) == 4

        box = BoundingBox(vertices)
        assert box.extmin.isclose((0, -0.5, 1)), "vertices should be in WCS"
        assert box.extmax.isclose((2, 0.5, 1)), "vertices should be in WCS"
Beispiel #2
0
def test_append_formatted_vertices():
    msp = VirtualLayout()
    p = msp.add_polyline2d([(1, 2, .5), (3, 4, .7)], format='xyb')
    assert len(p) == 2
    v1 = p.vertices[0]
    assert v1.dxf.location == (1, 2)
    assert v1.dxf.bulge == 0.5
    v2 = p.vertices[1]
    assert v2.dxf.location == (3, 4)
    assert v2.dxf.bulge == 0.7
Beispiel #3
0
def polyline2d():
    from ezdxf.layouts import VirtualLayout

    layout = VirtualLayout()
    return layout.add_polyline2d(
        POLYLINE_POINTS,
        format="xyseb",
        dxfattribs={
            "elevation": (0, 0, 4),
            "extrusion": (0, 0, -1),
        },
    )
Beispiel #4
0
def test_2d_3d_polyline_to_primitive():
    from ezdxf.layouts import VirtualLayout
    vl = VirtualLayout()

    p1 = Vec3(1, 1)
    p2 = Vec3(2, 2)
    p3 = Vec3(3, 3)
    e2d = vl.add_polyline2d([p1, p2, p3])
    e3d = vl.add_polyline3d([p1, p2, p3])
    for e in [e2d, e3d]:
        p = disassemble.make_primitive(e)
        assert p.is_empty is False
        assert p.path is not None
        assert p.mesh is None
        assert list(p.vertices()) == [p1, p2, p3]
def test_polyline2d_closed():
    # Create a circle by 2D POLYLINE:
    msp = VirtualLayout()
    polyline = msp.add_polyline2d(points=[(0, 0, 1), (1, 0, 1)], format='xyb')
    polyline.close(True)

    result = list(polyline.virtual_entities())
    assert len(result) == 2

    e = result[0]
    assert e.dxftype() == 'ARC'
    assert e.dxf.center == (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)