Ejemplo n.º 1
0
def test_make_path_from_lwpolyline_with_bulges():
    pline = LWPolyline()
    pline.closed = True
    pline.append_points(POINTS, format="xyb")
    path = make_path(pline)
    assert path.start == (0, 0)
    assert path.end == (0, 0)  # closed
    assert any(cmd.type == Command.CURVE4_TO for cmd in path)
Ejemplo n.º 2
0
def test_lwpolyline_s_shape():
    from ezdxf.entities import LWPolyline
    pline = LWPolyline()
    pline.append_points(S_SHAPE, format='xyb')
    path = make_path(pline)
    assert path.start == (0, 0)
    assert path.end == (5, 2)  # closed
    assert any(cmd.type == Command.CURVE4_TO for cmd in path)
Ejemplo n.º 3
0
def _flip_lwpolyline(polyline: LWPolyline) -> None:
    flipped_points: List[Sequence[float]] = []
    for x, y, start_width, end_width, bulge in polyline.lwpoints:
        bulge = -bulge
        v = _flip_2d_vertex(Vec2(x, y))
        flipped_points.append((v.x, v.y, start_width, end_width, bulge))
    polyline.set_points(flipped_points, format="xyseb")
    _finalize_polyline(polyline.dxf)
Ejemplo n.º 4
0
def test_lwpolyline_with_bulges():
    from ezdxf.entities import LWPolyline
    pline = LWPolyline()
    pline.closed = True
    pline.append_points(POINTS, format='xyb')
    path = make_path(pline)
    assert path.start == (0, 0)
    assert path.end == (0, 0)  # closed
    assert any(cmd.type == Command.CURVE4_TO for cmd in path)
Ejemplo n.º 5
0
def _from_lwpolyline(lwpolyline: LWPolyline, **kwargs) -> 'Path':
    path = Path()
    tools.add_2d_polyline(
        path,
        lwpolyline.get_points('xyb'),
        close=lwpolyline.closed,
        ocs=lwpolyline.ocs(),
        elevation=lwpolyline.dxf.elevation,
    )
    return path
Ejemplo n.º 6
0
def test_make_path_from_full_circle_lwpolyline_issue_424():
    pline = LWPolyline()
    pline.closed = True
    points = [
        (39_482_129.9462793, 3_554_328.753243976, 1.0),
        (39_482_129.95781776, 3_554_328.753243976, 1.0),
    ]
    pline.append_points(points, format="xyb")
    path = make_path(pline)
    assert len(path) == 2
Ejemplo n.º 7
0
def test_make_path_from_full_circle_lwpolyline():
    pline = LWPolyline()
    pline.closed = True
    pline.append_points([(0, 0, 1), (1, 0, 1)], format="xyb")
    path = make_path(pline)
    assert path.start.isclose((0, 0))
    assert path.end.isclose((0, 0))
    assert len(path) == 4
    assert any(cmd.type == Command.CURVE4_TO for cmd in path)
    vertices = list(path.flattening(0.1))
    assert len(vertices) == 65
Ejemplo n.º 8
0
def test_source_of_copy_for_virtual_entity():
    e = LWPolyline()
    e.vertices = [(0, 0), (1, 0), (1, 1)]
    assert e.is_virtual is True
    c = e.copy()
    assert c.is_virtual is True, "copy should be a virtual entity"
    assert c.is_copy is True, "should be a copy"
    assert (c.source_of_copy is
            e), "should return the immediate source of the copy"
    assert (c.origin_of_copy is
            None), "has no real DXF entity as source of the copy"
Ejemplo n.º 9
0
def test_lwpolyline_lines():
    from ezdxf.entities import LWPolyline
    pline = LWPolyline()
    pline.append_points([(1, 1), (2, 1), (2, 2)], format='xy')
    path = make_path(pline)
    assert path.start == (1, 1)
    assert path.end == (2, 2)
    assert len(path) == 2

    pline.dxf.elevation = 1.0
    path = make_path(pline)
    assert path.start == (1, 1, 1)
    assert path.end == (2, 2, 1)
def test_flattening_by_ellipse(lwpolyline1: LWPolyline):
    entities = list(lwpolyline1.virtual_entities())
    for e in entities:
        if e.dxftype() == "ARC":
            ellipse = Ellipse.from_arc(e)
            points = list(ellipse.flattening(MAX_SAGITTA))
            assert len(points) > 0
Ejemplo n.º 11
0
def lwpolyline():
    pline = LWPolyline.new(dxfattribs={
        "elevation": 4,
        "extrusion": (0, 0, -1),
    })
    pline.set_points(POLYLINE_POINTS)
    return pline
Ejemplo n.º 12
0
def test_fix_invalid_located_acdb_entity_group_codes():
    polyline = LWPolyline.from_text(LWPOLYLINE)

    print(str(polyline))
    print(f'Layer: {polyline.dxf.layer}')

    assert polyline.dxf.layer == 'Offline'
    assert polyline.dxf.color == 3
Ejemplo n.º 13
0
def to_lwpolylines(
    paths: Iterable[Path],
    *,
    distance: float = MAX_DISTANCE,
    segments: int = MIN_SEGMENTS,
    extrusion: "Vertex" = Z_AXIS,
    dxfattribs=None,
) -> Iterable[LWPolyline]:
    """Convert the given `paths` into :class:`~ezdxf.entities.LWPolyline`
    entities.
    The `extrusion` vector is applied to all paths, all vertices are projected
    onto the plane normal to this extrusion vector. The default extrusion vector
    is the WCS z-axis. The plane elevation is the distance from the WCS origin
    to the start point of the first path.

    Args:
        paths: iterable of :class:`Path` objects
        distance:  maximum distance, see :meth:`Path.flattening`
        segments: minimum segment count per Bézier curve
        extrusion: extrusion vector for all paths
        dxfattribs: additional DXF attribs

    Returns:
        iterable of :class:`~ezdxf.entities.LWPolyline` objects

    .. versionadded:: 0.16

    """
    if isinstance(paths, Path):
        paths = [paths]
    else:
        paths = list(paths)
    if len(paths) == 0:
        return []

    extrusion = Vec3(extrusion)
    reference_point = paths[0].start
    dxfattribs = dict(dxfattribs or {})
    if not Z_AXIS.isclose(extrusion):
        ocs, elevation = _get_ocs(extrusion, reference_point)
        paths = tools.transform_paths_to_ocs(paths, ocs)
        dxfattribs["elevation"] = elevation
        dxfattribs["extrusion"] = extrusion
    elif reference_point.z != 0:
        dxfattribs["elevation"] = reference_point.z

    for path in tools.single_paths(paths):
        if len(path) > 0:
            p = LWPolyline.new(dxfattribs=dxfattribs)
            p.append_points(path.flattening(distance, segments), format="xy")
            yield p
def lwpolyline1():
    e = LWPolyline.new(dxfattribs={
        "layer": "0",
        "linetype": "Continuous",
        "color": 0,
        "flags": 0,
        "const_width": 0.0,
        "elevation": 2.999999999999999e99,
        "extrusion": (0.0, 0.0, 1.0),
    }, )
    e.set_points([
        (297888, 108770, 0.0, 0.0, 0.0512534542487669),
        (297930, 108335, 0.0, 0.0, 0.0),
    ])
    return e
def lwpolyline() -> LWPolyline:
    # Issue 414 shows an error in the bounding box calculation for a closed
    # LWPOLYLINE representing a filled circle (const_width=0.45) and an
    # inverted extrusion (0, 0, -1).
    #
    # original data of the LWPOLYLINE:
    # [
    #     (-43710.28841108403, 19138.631023711587, 0.0, 0.0, -1.0),
    #     (-43710.28841108403, 19139.079023711445, 0.0, 0.0, -1.0),
    # ]
    # simplified test data:
    points = [(-10.0, 1.0, 0.0, 0.0, -1.0), (-10.0, 1.45, 0.0, 0.0, -1.0)]
    pline = LWPolyline.new(dxfattribs={
        "extrusion": (0, 0, -1),
        "const_width": 0.45
    })
    pline.append_points(points)
    pline.close()
    return pline