Example #1
0
def test_wipeout_creator_interface():
    layout = VirtualLayout()
    wipeout = layout.add_wipeout([(150, 100), (250, 100), (250, 200),
                                  (150, 200)])
    assert wipeout.dxftype() == "WIPEOUT"
    assert wipeout.dxf.insert == (150, 100, 0)
    assert wipeout.dxf.u_pixel == (100, 0, 0)
    assert wipeout.dxf.v_pixel == (0, 100, 0)
    assert wipeout.dxf.image_size == (1, 1)
    assert wipeout.dxf.flags == 7
    assert wipeout.dxf.clipping == 1
    assert wipeout.dxf.clip_mode == 0

    path = wipeout.boundary_path
    assert path[0].isclose(Vec2(-0.5, 0.5))
    assert path[1].isclose(Vec2(0.5, 0.5))
    assert path[2].isclose(Vec2(0.5, -0.5))
    assert path[3].isclose(Vec2(-0.5, -0.5))
    assert path[4] == path[0]

    path = wipeout.boundary_path_wcs()
    assert path[0] == (150, 100)
    assert path[1] == (250, 100)
    assert path[2] == (250, 200)
    assert path[3] == (150, 200)
    assert path[0] == path[-1]
def polymesh():
    msp = VirtualLayout()
    polymesh = msp.add_polymesh((3, 3))
    for m in range(3):
        for n in range(3):
            polymesh.set_mesh_vertex((m, n), (m, n))
    return polymesh
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"
Example #4
0
def test_add_leader():
    msp = VirtualLayout()
    leader = msp.add_leader(vertices=VERTICES)
    assert leader.dxftype() == "LEADER"
    assert leader.dxf.annotation_type == 3
    assert len(leader.vertices) == 3
    assert leader.vertices == VERTICES
Example #5
0
def test_add_leader():
    msp = VirtualLayout()
    leader = msp.new_entity('LEADER', {})  # type: Leader
    assert leader.dxftype() == 'LEADER'
    assert leader.dxf.annotation_type == 3
    leader.vertices.append(Vector(0, 0, 0))
    assert len(leader.vertices) == 1
    assert leader.vertices[0] == (0, 0, 0)
Example #6
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
Example #7
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),
        },
    )
Example #8
0
def test_polyline3d_closed():
    msp = VirtualLayout()
    polyline3d = msp.add_polyline3d([(0, 0, 0), (1, 0, 0), (2, 2, 2)], dxfattribs={'closed': True})
    assert polyline3d.is_closed is True
    result = list(polyline3d.virtual_entities())
    assert len(result) == 3
    # The closing element is the first LINE entity.
    # This is an implementation detail and can change in the future!
    line = result[0]
    assert line.dxftype() == 'LINE'
    assert line.dxf.start == (2, 2, 2)
    assert line.dxf.end == (0, 0, 0)
def test_polyline3d_virtual_entities():
    msp = VirtualLayout()
    polyline3d = msp.add_polyline3d([(0, 0, 0), (1, 0, 0), (2, 2, 2)])
    result = list(polyline3d.virtual_entities())
    assert len(result) == 2
    line = result[0]
    assert line.dxftype() == 'LINE'
    assert line.dxf.start == (0, 0, 0)
    assert line.dxf.end == (1, 0, 0)
    line = result[1]
    assert line.dxftype() == 'LINE'
    assert line.dxf.start == (1, 0, 0)
    assert line.dxf.end == (2, 2, 2)
Example #10
0
def ellipse():
    layout = VirtualLayout()
    return layout.add_ellipse(
        center=(1999.488177113287, -1598.02265357955, 0.0),
        major_axis=(629.968069297, 0.0, 0.0),
        ratio=0.495263197,
        start_param=-1.261396328799999,
        end_param=-0.2505454928,
        dxfattribs={
            "layer": "0",
            "linetype": "Continuous",
            "color": 3,
            "extrusion": (0.0, 0.0, -1.0),
        },
    )
Example #11
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]
Example #12
0
 def test_explode_entity_into_layout(self, text):
     layout = VirtualLayout()
     entities = text2path.explode(text,
                                  kind=Kind.LWPOLYLINES,
                                  target=layout)
     assert len(entities) == len(layout), \
         "expected all entities added to the target layout"
Example #13
0
def test_poly_mesh_to_primitive():
    from ezdxf.layouts import VirtualLayout
    vl = VirtualLayout()
    poly_mesh = vl.add_polymesh(size=(4, 4))
    for x in range(4):
        for y in range(4):
            poly_mesh.set_mesh_vertex((x, y), (x, y, 1.0))

    p = disassemble.make_primitive(poly_mesh)
    assert p.is_empty is False
    assert p.path is None
    mesh_builder = p.mesh
    assert mesh_builder is not None

    assert len(mesh_builder.vertices) == 16
    assert len(mesh_builder.faces) == 9
    assert len(list(p.vertices())) == 16
Example #14
0
def test_boundary_path_wcs():
    from ezdxf.layouts import VirtualLayout

    layout = VirtualLayout()
    e = cast(
        Wipeout,
        layout.new_entity(
            "WIPEOUT",
            dxfattribs={
                "layer": "0",
                "class_version": 0,
                "insert": (150.0, 100.0, 0.0),
                "u_pixel": (100.0, 0.0, 0.0),
                "v_pixel": (0.0, 100.0, 0.0),
                "image_size": (1.0, 1.0, 0.0),
                "image_def_handle": "0",
                "flags": 7,
                "clipping": 1,
                "brightness": 50,
                "contrast": 50,
                "fade": 0,
                "image_def_reactor_handle": "0",
                "clipping_boundary_type": 2,
                "count_boundary_points": 5,
                "clip_mode": 0,
            },
        ),
    )
    e.set_boundary_path([
        (-0.5, 0.5),
        (0.5, 0.5),
        (0.5, -0.5),
        (-0.5, -0.5),
        (-0.5, 0.5),
    ])
    path = e.boundary_path_wcs()
    assert path[0] == (150, 100)
    assert path[1] == (250, 100)
    assert path[2] == (250, 200)
    assert path[3] == (150, 200)
    assert path[0] == path[-1]
Example #15
0
def test_flattening_issue():
    from ezdxf.layouts import VirtualLayout

    layout = VirtualLayout()
    # this configuration caused an math domain error in distance_point_line_3d()
    # sqrt() of negative number, cause by floating point imprecision for very
    # small numbers.
    e = layout.add_spline(
        degree=2,
        dxfattribs={
            "layer": "0",
            "linetype": "Continuous",
            "color": 84,
            "lineweight": 0,
            "extrusion": (0.0, 0.0, 1.0),
            "flags": 12,
            "knot_tolerance": 1e-09,
            "control_point_tolerance": 1e-10,
        },
    )
    e.control_points = [
        (696603.8306266892, 5711646.357537143, -2.8298889e-09),
        (696603.8352219285, 5711646.36068357, -2.8298889e-09),
        (696603.8392015211, 5711646.363408451, -2.8298889e-09),
    ]
    e.knots = [
        -6.110343499933633,
        -6.110343499933633,
        -6.110343499933633,
        -4.326590114514485,
        -4.326590114514485,
        -4.326590114514485,
    ]
    e.weights = [
        1.607007851100765,
        1.731310340973351,
        1.731310340973339,
    ]
    points = list(e.flattening(0.01))
    assert len(points) > 4
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)
Example #17
0
def test_boundary_path_wcs():
    from ezdxf.layouts import VirtualLayout
    layout = VirtualLayout()
    e = cast(
        Wipeout,
        layout.new_entity(
            'WIPEOUT',
            dxfattribs={
                'layer': "0",
                'class_version': 0,
                'insert': (150.0, 100.0, 0.0),
                'u_pixel': (100.0, 0.0, 0.0),
                'v_pixel': (0.0, 100.0, 0.0),
                'image_size': (1.0, 1.0, 0.0),
                'image_def_handle': "0",
                'flags': 7,
                'clipping': 1,
                'brightness': 50,
                'contrast': 50,
                'fade': 0,
                'image_def_reactor_handle': "0",
                'clipping_boundary_type': 2,
                'count_boundary_points': 5,
                'clip_mode': 0,
            },
        ))
    e.set_boundary_path([
        (-0.5, 0.5),
        (0.5, 0.5),
        (0.5, -0.5),
        (-0.5, -0.5),
        (-0.5, 0.5),
    ])
    path = e.boundary_path_wcs()
    assert path[0] == (150, 100)
    assert path[1] == (250, 100)
    assert path[2] == (250, 200)
    assert path[3] == (150, 200)
    assert path[0] == path[-1]
Example #18
0
def test_poly_face_mesh_to_primitive():
    from ezdxf.layouts import VirtualLayout
    from ezdxf.render.forms import cube
    vl = VirtualLayout()
    poly_face_mesh = cube().render_polyface(vl)
    assert poly_face_mesh.dxftype() == "POLYLINE"

    p = disassemble.make_primitive(poly_face_mesh)
    assert p.is_empty is False
    assert p.path is None
    mesh_builder = p.mesh
    assert mesh_builder is not None

    assert len(mesh_builder.vertices) == 8
    assert len(mesh_builder.faces) == 6
    assert len(list(p.vertices())) == 8
def test_polyface_virtual_entities():
    from ezdxf.render.forms import cube

    msp = VirtualLayout()
    polyface = cube().render_polyface(msp)
    result = list(polyface.virtual_entities())

    assert len(result) == 6
    assert result[0].dxftype() == '3DFACE'
    vertices = set()
    for face in result:
        for vertex in face:
            vertices.add(vertex)
    assert len(vertices) == 8
    assert (-0.5, -0.5, -0.5) in vertices
    assert (0.5, 0.5, 0.5) in vertices
Example #20
0
def test_mesh_entity_to_primitive():
    from ezdxf.layouts import VirtualLayout
    from ezdxf.render.forms import cube
    vl = VirtualLayout()
    mesh_entity = cube().render(vl)
    assert mesh_entity.dxftype() == "MESH"

    p = disassemble.make_primitive(mesh_entity)
    assert p.is_empty is False
    assert p.path is None
    mesh_builder = p.mesh
    assert mesh_builder is not None
    assert p.is_empty is False

    assert len(mesh_builder.vertices) == 8
    assert len(mesh_builder.faces) == 6
    assert len(list(p.vertices())) == 8
Example #21
0
 def virtual_entities(self,
                      name: str,
                      insert: 'Vertex' = NULLVEC,
                      size: float = 0.625,
                      rotation: float = 0,
                      *,
                      dxfattribs: Dict = None) -> Iterable['DXFGraphic']:
     """ Yield arrow components as virtual DXF entities. """
     from ezdxf.layouts import VirtualLayout
     if name in self:
         layout = VirtualLayout()
         dxfattribs = dxfattribs or {}
         ARROWS.render_arrow(
             layout,
             name,
             insert=insert,
             size=size,
             rotation=rotation,
             dxfattribs=dxfattribs,
         )
         yield from iter(layout)
Example #22
0
    def virtual_entities(self,
                         name: str,
                         insert: Vertex = NULLVEC,
                         size: float = 0.625,
                         rotation: float = 0,
                         *,
                         dxfattribs=None) -> Iterator["DXFGraphic"]:
        """Returns all arrow components as virtual DXF entities."""
        from ezdxf.layouts import VirtualLayout

        if name in self:
            layout = VirtualLayout()
            ARROWS.render_arrow(
                layout,
                name,
                insert=insert,
                size=size,
                rotation=rotation,
                dxfattribs=dxfattribs,
            )
            yield from iter(layout)
Example #23
0
def layout():
    return VirtualLayout()
Example #24
0
def msp():
    state = ezdxf.options.use_matplotlib
    ezdxf.options.use_matplotlib = False
    yield VirtualLayout()
    ezdxf.options.use_matplotlib = state
Example #25
0
def solid_entities():
    lay = VirtualLayout()
    lay.add_solid(translate(square(1), (-10, -10)))
    lay.add_solid(translate(square(1), (10, 10)))
    return lay
Example #26
0
def points1():
    lay = VirtualLayout()
    lay.add_point((-1, -2, -3))
    lay.add_point((4, 5, 6))
    return lay
def cube_polyface():
    layout = VirtualLayout()
    p = layout.add_polyface()
    p.append_faces(cube().faces_as_vertices())
    return p
Example #28
0
def test_render_arrow():
    layout = VirtualLayout()
    ARROWS.render_arrow(layout, ARROWS.closed, insert=(0, 0, 0))
    assert len(layout) > 0
Example #29
0
def circle():
    lay = VirtualLayout()
    lay.add_circle((0, 0), radius=100)
    return lay
Example #30
0
def msp():
    return VirtualLayout()