Ejemplo n.º 1
0
def test_upright_arc_geometry(arc):
    p0 = path.make_path(arc)
    upright(arc)
    # ARC angles are always in counter-clockwise orientation around the
    # extrusion vector, therefore a reversed path vertex order:
    p1 = path.make_path(arc).reversed()
    assert path.have_close_control_vertices(p0, p1)
Ejemplo n.º 2
0
def test_upright_arc_dxf_attributes(arc):
    upright(arc)
    assert arc.dxf.extrusion.isclose(Z_AXIS)
    assert arc.dxf.center.isclose((-3, 4, -5))
    assert arc.dxf.radius == 2.0
    assert arc.dxf.start_angle == pytest.approx(105.0)
    assert arc.dxf.end_angle == pytest.approx(165.0)
Ejemplo n.º 3
0
def test_upright_insert():
    doc = ezdxf.new()
    blk = doc.blocks.new("example")
    blk.add_arc(
        center=(5, 0, 2),
        radius=3,
        start_angle=30,
        end_angle=150,
    )
    blk.add_lwpolyline(POLYLINE_POINTS)
    msp = doc.modelspace()
    blk_ref = msp.add_blockref(
        name="example",
        insert=(0, 0, 4),
        dxfattribs={
            "extrusion": (0, 0, -1),
            "rotation": -37,
        },
    )
    blk_ref_copy = blk_ref.copy()
    upright(blk_ref_copy)
    msp.add_entity(blk_ref_copy)

    assert blk_ref_copy.dxf.extrusion.isclose(Z_AXIS)
    for e0, e1 in zip(blk_ref.virtual_entities(),
                      blk_ref_copy.virtual_entities()):
        assert e0.dxftype() == e1.dxftype(), "same DXF type expected"
        p0 = path.make_path(e0)
        assert len(p0) > 0, "source path cannot be empty"
        p1 = path.make_path(e1)
        assert len(p1) > 0, "upright path cannot be empty"
        assert path.have_close_control_vertices(
            p0, p1), "expected same WCS representation"
Ejemplo n.º 4
0
def test_upright_circle_geometry(circle):
    circle.dxf.center = (0, 0)  # required for rotation!
    p0 = path.make_path(circle)
    upright(circle)
    # IMPORTANT: Circle has a different WCS representation as Path object
    # Rotated around the z-axis by 180 degrees AND reversed order, because
    # the start point is always at 0 degrees, determined by the OCS x-axis!
    p1 = path.make_path(circle).transform(Matrix44.z_rotate(math.pi))
    assert path.have_close_control_vertices(p0, p1.reversed())
Ejemplo n.º 5
0
def test_upright_polyline(factory):
    polyline = factory()
    p0 = path.make_path(polyline)
    assert p0.has_curves is True

    upright(polyline)
    assert polyline.dxf.extrusion.isclose(Z_AXIS)
    p1 = path.make_path(polyline)
    # vertex order do not change:
    assert path.have_close_control_vertices(p0, p1)
Ejemplo n.º 6
0
def test_upright_hatch_with_edge_path(all_edge_types_hatch):
    hatch = all_edge_types_hatch
    hatch.dxf.elevation = Vec3(0, 0, 4)
    hatch.dxf.extrusion = Vec3(0, 0, -1)
    assert hatch.dxf.extrusion.isclose(-Z_AXIS)

    p0 = path.make_path(hatch)
    assert p0.has_curves is True

    upright(hatch)
    assert hatch.dxf.extrusion.isclose(Z_AXIS)
    p1 = path.make_path(hatch)
    assert path.have_close_control_vertices(p0, p1)
Ejemplo n.º 7
0
def test_upright_hatch_with_polyline_path():
    hatch = Hatch.new(dxfattribs={
        "elevation": (0, 0, 4),
        "extrusion": (0, 0, -1),
    })
    hatch.paths.add_polyline_path([(x, y, b)
                                   for x, y, s, e, b in POLYLINE_POINTS])
    p0 = path.make_path(hatch)
    assert p0.has_curves is True

    upright(hatch)
    assert hatch.dxf.extrusion.isclose(Z_AXIS)
    p1 = path.make_path(hatch)
    assert path.have_close_control_vertices(p0, p1)
Ejemplo n.º 8
0
def test_safety_checks(circle):
    # invalid entities should be ignored silently
    upright(None)  # ignore None values
    upright(DXFEntity())  # ignore invalid DXF entity types
    upright(Text())  # ignore unsupported DXF entity types
    circle.destroy()
    upright(circle)  # ignore destroyed entities
    assert True is True
Ejemplo n.º 9
0
def test_upright_quadrilaterals(cls):
    solid = cls.new(
        dxfattribs={
            "vtx0": (1, 1),
            "vtx1": (2, 1),
            "vtx2": (2, 2),
            "vtx3": (1, 2),
            "extrusion": (0, 0, -1),
        })
    p0 = path.make_path(solid)
    assert len(p0) == 4

    upright(solid)
    assert solid.dxf.extrusion.isclose(Z_AXIS)
    p1 = path.make_path(solid)
    # same vertex order as source entity
    assert path.have_close_control_vertices(p0, p1)
Ejemplo n.º 10
0
def test_upright_ellipse():
    ellipse = Ellipse.new(
        dxfattribs={
            "center": (5, 5, 5),
            "major_axis": (5, 0, 0),
            "ratio": 0.5,
            "start_param": 0.5,
            "end_param": 1.5,
            "extrusion": (0, 0, -1),
        })
    p0 = path.make_path(ellipse)
    assert p0.has_curves is True

    upright(ellipse)
    assert ellipse.dxf.extrusion.isclose(Z_AXIS)
    p1 = path.make_path(ellipse)
    # has reversed vertex order of source entity:
    assert path.have_close_control_vertices(p0, p1.reversed())
Ejemplo n.º 11
0
            0.0,
            0.0,
            2.91547594742265,
            8.746427842267952,
            11.6619037896906,
            11.6619037896906,
            11.6619037896906,
            11.6619037896906,
        ],
        degree=3,
        periodic=0,
    )
    return hatch


doc = ezdxf.new()
msp = doc.modelspace()
hatch = all_edge_types_hatch(elevation=4, extrusion=(0, 0, -1))
msp.add_entity(hatch)

hatch_copy = hatch.copy()
hatch_copy.dxf.layer = "upright"
hatch_copy.dxf.color = 6

upright(hatch_copy)
msp.add_entity(hatch_copy)
p = path.make_path(hatch_copy)
path.render_lwpolylines(msp, [p], dxfattribs={"layer": "paths"})

doc.saveas(DIR / "upright_hatch.dxf")
Ejemplo n.º 12
0
def test_upright_circle_dxf_attributes(circle):
    upright(circle)
    assert circle.dxf.extrusion.isclose(Z_AXIS)
    assert circle.dxf.center.isclose((-3, 4))
    assert circle.dxf.radius == 2.0
Ejemplo n.º 13
0
msp.add_line((0, 0), arc.end_point, dxfattribs={"color": ezdxf.const.BLUE})

# copy arc
mirrored_arc = arc.copy()
msp.add_entity(mirrored_arc)

# mirror copy
mirrored_arc.transform(Matrix44.scale(-1, 1, 1))

# This creates an inverted extrusion vector:
assert mirrored_arc.dxf.extrusion.isclose((0, 0, -1))

start_point_inv = mirrored_arc.start_point
end_point_inv = mirrored_arc.end_point

upright(mirrored_arc)
# OCS is aligned with WCS:
assert mirrored_arc.dxf.extrusion.isclose((0, 0, 1))

# start- and end points are swapped after applying upright()
assert mirrored_arc.start_point.isclose(end_point_inv)
assert mirrored_arc.end_point.isclose(start_point_inv)

# draw lines to the start- and end point of the mirrored ARC
msp.add_line((0, 0), mirrored_arc.start_point, dxfattribs={"color": ezdxf.const.GREEN})
msp.add_line((0, 0), mirrored_arc.end_point, dxfattribs={"color": ezdxf.const.BLUE})


doc.set_modelspace_vport(15)
doc.saveas(DIR / "upright_arc.dxf")
Ejemplo n.º 14
0
blk = doc.blocks.new("example")
blk.add_arc(
    center=(5, 0, 2),
    radius=3,
    start_angle=30,
    end_angle=150,
)
blk.add_lwpolyline(POLYLINE_POINTS)
blk.add_line((0, 0), (10, 0), dxfattribs={"color": 1})
blk.add_line((0, 0), (0, 10), dxfattribs={"color": 3})
blk.add_line((0, 0, 0), (0, 0, 10), dxfattribs={"color": 5})

msp = doc.modelspace()
blk_ref = msp.add_blockref(
    name="example",
    insert=(0, 0, 4),
    dxfattribs={
        "extrusion": (0, 0, -1),
        "layer": "original",
        "rotation": -37
    },
)

blk_ref_copy = blk_ref.copy()
blk_ref_copy.dxf.layer = "upright"

upright(blk_ref_copy)
msp.add_entity(blk_ref_copy)

doc.saveas(DIR / "upright_insert.dxf")