Esempio n. 1
0
def test_load_malformed_circle():
    circle = Circle.from_text(MALFORMED_CIRCLE)
    assert circle.dxf.layer == "LY_EZDXF"
    assert circle.dxf.linetype == "LT_EZDXF"
    assert circle.dxf.color == 7
    assert circle.dxf.center.isclose((1, 2, 3))
    assert circle.dxf.radius == 2.0
Esempio n. 2
0
def test_circle_fast_translation():
    circle = Circle.new(
        dxfattribs={'center': (2, 3, 4), 'extrusion': Vector.random()})
    ocs = circle.ocs()
    offset = Vector(1, 2, 3)
    center = ocs.to_wcs(circle.dxf.center) + offset
    circle.translate(*offset)
    assert ocs.to_wcs(circle.dxf.center).isclose(center, abs_tol=1e-9)
Esempio n. 3
0
def test_circle_default_ocs():
    circle = Circle.new(dxfattribs={'center': (2, 3, 4), 'thickness': 2})
    # 1. rotation - 2. scaling - 3. translation
    m = Matrix44.chain(Matrix44.scale(2, 2, 3), Matrix44.translate(1, 1, 1))
    # default extrusion is (0, 0, 1), therefore scale(2, 2, ..) is a uniform scaling in the xy-play of the OCS
    circle.transform(m)

    assert circle.dxf.center == (5, 7, 13)
    assert circle.dxf.extrusion == (0, 0, 1)
    assert circle.dxf.thickness == 6
Esempio n. 4
0
def test_circle_to_code():
    from ezdxf.entities.circle import Circle
    entity = Circle.new(handle='ABBA', owner='0', dxfattribs={
        'color': '7',
        'center': (1, 2, 3),
        'radius': 2,
    })
    new_entity = translate_to_code_and_execute(entity)
    for name in ('color', 'center', 'radius'):
        assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
Esempio n. 5
0
def test_circle_non_uniform_scaling():
    circle = Circle.new(dxfattribs={'center': (2, 3, 4), 'extrusion': (0, 1, 0),
                                    'thickness': 2})
    # extrusion in WCS y-axis, therefore scale(2, ..., 3) is a non uniform
    # scaling in the xy-play of the OCS which is the xz-plane of the WCS
    with pytest.raises(NonUniformScalingError):
        circle.transform(Matrix44.scale(2, 2, 3))

    # source values unchanged after exception
    assert circle.dxf.center == (2, 3, 4)
    assert circle.dxf.extrusion == (0, 1, 0)
    assert circle.dxf.thickness == 2
Esempio n. 6
0
def test_circle_to_code():
    from ezdxf.entities.circle import Circle

    entity = Circle.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "color": "7",
            "center": (1, 2, 3),
            "radius": 2,
        },
    )
    new_entity = translate_to_code_and_execute(entity)
    for name in ("color", "center", "radius"):
        assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
Esempio n. 7
0
def test_circle_user_ocs():
    center = (2, 3, 4)
    extrusion = (0, 1, 0)

    circle = Circle.new(
        dxfattribs={'center': center, 'extrusion': extrusion, 'thickness': 2})
    ocs = OCS(extrusion)
    v = ocs.to_wcs(center)  # (-2, 4, 3)
    v = Vector(v.x * 2, v.y * 4, v.z * 2)
    v += (1, 1, 1)
    # and back to OCS, extrusion is unchanged
    result = ocs.from_wcs(v)

    m = Matrix44.chain(Matrix44.scale(2, 4, 2), Matrix44.translate(1, 1, 1))
    circle.transform(m)
    assert circle.dxf.center == result
    assert circle.dxf.extrusion == (0, 1, 0)
    assert circle.dxf.thickness == 8  # in WCS y-axis
Esempio n. 8
0
def test_extrusion_can_not_be_a_null_vector():
    circle = Circle.new(dxfattribs={'extrusion': (0, 0, 0)})
    assert circle.dxf.extrusion == (0, 0, 1), 'expected default extrusion'
Esempio n. 9
0
def test_zero_radius():
    circle = Circle.new(dxfattribs={'radius': 0})
    assert circle.dxf.radius == 0, 'Radius == 0 is valid'
Esempio n. 10
0
def test_negative_radius():
    circle = Circle.new(dxfattribs={'radius': -1})
    assert circle.dxf.radius == -1, 'Radius < 0 is valid'
Esempio n. 11
0
def test_zero_radius():
    circle = Circle.new(dxfattribs={"radius": 0})
    assert circle.dxf.radius == 0, "Radius == 0 is valid"
Esempio n. 12
0
def test_circle_flattening(radius, sagitta, count):
    circle = Circle.new(dxfattribs={"radius": radius})
    assert len(list(circle.flattening(sagitta))) == count