Exemplo n.º 1
0
def test_union_Comp2Radius():
    elem1 = et.Element("sphere", { "radius" : "2.5*mm" })
    elem2 = et.Element("cylinder", { "height" : "5.*mm", "radius" : "1.*mm" })
    op = operations.Union()
    op.addComp(components.Sphere(elem1))
    op.addComp(components.Cylinder(elem2))
    assert(op[1].radius == 1)
Exemplo n.º 2
0
def test_union_str():
    elem1 = et.Element("sphere", { "radius" : "2.5*mm" })
    elem2 = et.Element("cylinder", { "height" : "5.*mm", "radius" : "1.*mm" })
    test = operations.Union()
    test.addComp(components.Sphere(elem1))
    test.addComp(components.Cylinder(elem2))
    sol = """union() {
    sphere(r = 2.5, $fn=100);
    cylinder(h = 5.0, r = 1.0, $fn=100, center=true);
}"""
    assert("{0!s}".format(test) == sol)
Exemplo n.º 3
0
def test_parsercore():
    fname = os.path.abspath("./tests/pytest/test_xmls/parser_test.xml")
    p = Parser(fname)
    test = p.rootelems[0]
    sol = operations.Dilation(3.0)
    vector = et.Element("axis", {
        "beam": "1.0",
        "transversal": "0.0",
        "vertical": "0.0"
    })
    op1 = operations.Rotation("90.*deg", vector)
    vector = et.Element("vector", {
        "beam": "0.*mm",
        "transversal": "0.*mm",
        "vertical": "5.*cm"
    })
    op2 = operations.Translation(vector)
    op3 = operations.Reflection("(1, 1, 0)")
    op4 = operations.Difference()
    op5 = operations.Intersection()
    comp1 = et.Element("block", {
        "width": "20.*mm",
        "height": "20.*mm",
        "thickness": "20.*mm"
    })
    comp2 = et.Element("sphere", {"radius": "20.*mm"})
    comp3 = et.Element("pyramid", {
        "thickness": "20.*mm",
        "width": "20.*mm",
        "height": "10.*mm"
    })
    op5.addComp(components.Block(comp1))
    op5.addComp(components.Sphere(comp2))
    op5.addComp(components.Pyramid(comp3))
    op6 = operations.Union()
    comp4 = et.Element("cone", {"height": "20.*mm", "radius": "20.*mm"})
    comp5 = et.Element("cylinder", {"height": "10.*mm", "radius": "20.*mm"})
    comp6 = et.Element("torus", {"major": "30.*mm", "minor": "20.*mm"})
    op6.addComp(components.Cone(comp4))
    op6.addComp(components.Cylinder(comp5))
    op6.addComp(components.Torus(comp6))
    op4.addComp(op5)
    op4.addComp(op6)
    op3.body = op4
    op2.body = op3
    op1.body = op2
    sol.body = op1
    assert (test == sol)