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

Function test_distribute

tests/test_sketch.py:107–204  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

105
106
107def test_distribute():
108
109 with raises(ValueError):
110 Sketch().rect(2, 2).faces().distribute(5)
111
112 with raises(ValueError):
113 Sketch().rect(2, 2).distribute(5)
114
115 with raises(ValueError):
116 Sketch().circle(1).wires().distribute(0, 0, 1)
117
118 s1 = Sketch().circle(4, mode="c", tag="c").edges(tag="c").distribute(3)
119
120 assert len(s1._selection) == approx(3)
121
122 s1.rect(1, 1)
123
124 assert s1._faces.Area() == approx(3)
125 assert len(s1._faces.Faces()) == 3
126 assert len(s1.reset().vertices("<X")._selection) == 2
127
128 for f in s1._faces.Faces():
129 assert f.Center().Length == approx(4)
130
131 s2 = (
132 Sketch()
133 .circle(4, mode="c", tag="c")
134 .edges(tag="c")
135 .distribute(3, rotate=False)
136 .rect(1, 1)
137 )
138
139 assert s2._faces.Area() == approx(3)
140 assert len(s2._faces.Faces()) == 3
141 assert len(s2.reset().vertices("<X")._selection) == 4
142
143 for f in s2._faces.Faces():
144 assert f.Center().Length == approx(4)
145
146 s3 = (
147 Sketch().circle(4, mode="c", tag="c").edges(tag="c").distribute(3, 0.625, 0.875)
148 )
149
150 assert len(s3._selection) == approx(3)
151
152 s3.rect(1, 0.5).reset().vertices("<X")
153
154 assert s3._selection[0].toTuple() == approx(
155 (-3.358757210636101, -3.005203820042827, 0.0)
156 )
157
158 s3.reset().vertices(">X")
159
160 assert s3._selection[0].toTuple() == approx(
161 (3.358757210636101, -3.005203820042827, 0.0)
162 )
163
164 s4 = Sketch().arc((0, 0), 4, 180, 180).edges().distribute(3, 0.25, 0.75)

Callers

nothing calls this directly

Calls 15

SketchClass · 0.90
distributeMethod · 0.80
resetMethod · 0.80
arcMethod · 0.80
segmentMethod · 0.80
facesMethod · 0.45
rectMethod · 0.45
wiresMethod · 0.45
circleMethod · 0.45
edgesMethod · 0.45
AreaMethod · 0.45
FacesMethod · 0.45

Tested by

no test coverage detected