MCPcopy
hub / github.com/CadQuery/cadquery / test_iterators

Method test_iterators

tests/test_cadquery.py:5733–5779  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5731 assert vtk.GetNumberOfPolys() == 2
5732
5733 def test_iterators(self):
5734
5735 w = Workplane().box(1, 1, 1)
5736 s = w.val()
5737 f = w.faces(">Z").val()
5738
5739 # check ancestors
5740 res1 = list(s.Edges()[0].ancestors(s, "Face"))
5741 assert len(res1) == 2
5742 assert w.faces(">Z").edges(">X").ancestors("Face").size() == 2
5743 assert w.faces(">Z").edges(">X or <X").ancestors("Face").size() == 3
5744
5745 # check siblings
5746 res2 = list(f.siblings(s, "Edge"))
5747 assert len(res2) == 4
5748 assert w.faces(">Z").siblings("Edge").size() == 4
5749
5750 res3 = list(f.siblings(s, "Edge", 2))
5751 assert len(res3) == 1
5752 assert w.faces(">Z").siblings("Edge", 2).size() == 1
5753
5754 res4 = list(f.siblings(s, "Edge").siblings(s, "Edge"))
5755 assert len(res4) == 2
5756 assert w.faces(">Z").siblings("Edge").siblings("Edge").size() == 2
5757
5758 # check regular iterator
5759 res5 = list(s)
5760 assert len(res5) == 1
5761 assert isinstance(res5[0], Shell)
5762
5763 # check ordered iteration for wires
5764 w = Workplane().polygon(5, 1).val()
5765 edges = list(w)
5766
5767 for e1, e2 in zip(edges, edges[1:]):
5768 assert (e2.startPoint() - e1.endPoint()).Length == approx(0.0)
5769
5770 # check ancestors on a compound
5771 w = Workplane().pushPoints([(0, 0), (2, 0)]).box(1, 1, 1)
5772 c = w.val()
5773 fs = w.faces(">Z").combine().val()
5774
5775 res6 = list(fs.ancestors(c, "Solid"))
5776 assert len(res6) == 2
5777
5778 res7 = list(fs.siblings(c, "Edge", 2))
5779 assert len(res7) == 2
5780
5781 def test_map_apply_filter_sort(self):
5782

Callers

nothing calls this directly

Calls 14

WorkplaneClass · 0.85
boxMethod · 0.80
EdgesMethod · 0.80
startPointMethod · 0.80
endPointMethod · 0.80
pushPointsMethod · 0.80
valMethod · 0.45
facesMethod · 0.45
ancestorsMethod · 0.45
sizeMethod · 0.45
edgesMethod · 0.45
siblingsMethod · 0.45

Tested by

no test coverage detected