コード例 #1
0
def test_edge_interface():

    s1 = (Sketch().segment((0, 0), (1, 0)).segment(
        (1, 1)).segment(1, 180).close().assemble())

    assert len(s1._faces.Faces()) == 1
    assert s1._faces.Area() == approx(1)

    s2 = Sketch().arc((0, 0), (1, 1), (0, 2)).close().assemble()

    assert len(s2._faces.Faces()) == 1
    assert s2._faces.Area() == approx(pi / 2)

    s3 = Sketch().arc((0, 0), (1, 1), (0, 2)).arc((-1, 1), (0, 0)).assemble()

    assert len(s3._faces.Faces()) == 1
    assert s3._faces.Area() == approx(pi)

    s4 = Sketch().arc((0, 0), 1, 0, 90)

    assert len(s4.vertices()._selection) == 2
    assert s4.vertices(">Y")._selection[0].Center().y == approx(1)

    s5 = Sketch().arc((0, 0), 1, 0, -90)

    assert len(s5.vertices()._selection) == 2
    assert s5.vertices(">Y")._selection[0].Center().y == approx(0)

    s6 = Sketch().arc((0, 0), 1, 90, 360)

    assert len(s6.vertices()._selection) == 1
コード例 #2
0
def test_selectors():

    s = Sketch().push([(-2, 0), (2, 0)]).rect(1, 1).rect(0.5, 0.5,
                                                         mode="s").reset()

    assert len(s._selection) == 0

    s.vertices()

    assert len(s._selection) == 16

    s.reset()

    assert len(s._selection) == 0

    s.edges()

    assert len(s._selection) == 16

    s.reset().wires()

    assert len(s._selection) == 4

    s.reset().faces()

    assert len(s._selection) == 2

    s.reset().vertices("<Y")

    assert len(s._selection) == 4

    s.reset().edges("<X or >X")

    assert len(s._selection) == 2

    s.tag("test").reset()

    assert len(s._selection) == 0

    s.select("test")

    assert len(s._selection) == 2

    s.reset().wires()

    assert len(s._selection) == 4

    s.reset().wires(LengthNthSelector(1))

    assert len(s._selection) == 2
コード例 #3
0
def test_face_interface():

    s1 = Sketch().rect(1, 2, 45)

    assert s1._faces.Area() == approx(2)
    assert s1.vertices(">X")._selection[0].toTuple()[0] == approx(1.5 /
                                                                  sqrt(2))

    s2 = Sketch().circle(1)

    assert s2._faces.Area() == approx(pi)

    s3 = Sketch().ellipse(2, 0.5)

    assert s3._faces.Area() == approx(pi)

    s4 = Sketch().trapezoid(2, 0.5, 45)

    assert s4._faces.Area() == approx(0.75)

    s4 = Sketch().trapezoid(2, 0.5, 45)

    assert s4._faces.Area() == approx(0.75)

    s5 = Sketch().slot(3, 2)

    assert s5._faces.Area() == approx(6 + pi)
    assert s5.edges(">Y")._selection[0].Length() == approx(3)

    s6 = Sketch().regularPolygon(1, 5)

    assert len(s6.vertices()._selection) == 5
    assert s6.vertices(">Y")._selection[0].toTuple()[1] == approx(1)

    s7 = Sketch().polygon([(0, 0), (0, 1), (1, 0)])

    assert len(s7.vertices()._selection) == 3
    assert s7._faces.Area() == approx(0.5)

    with raises(ValueError):
        Sketch().face(Sketch().rect(1, 1)._faces)