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

Function test_solid

tests/test_free_functions.py:267–315  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

265
266
267def test_solid():
268
269 b = box(1, 1, 1)
270 b_large = box(10, 10, 1)
271 b_small = box(0.1, 0.1, 0.1).moved(b_large)
272 sphere1 = sphere(0.1).moved(b_large)
273 sphere2 = sphere1.moved(x=2)
274
275 # solid
276 s1 = solid(b.Faces())
277 s2 = solid(*b.Faces())
278
279 assert s1.Volume() == approx(1)
280 assert s2.Volume() == approx(1)
281
282 # solid with voids
283 b1 = box(0.1, 0.1, 0.1)
284
285 s3 = solid(b.Faces(), b1.moved([(0.2, 0, 0.5), (-0.2, 0, 0.5)]).Faces())
286
287 assert s3.Volume() == approx(1 - 2 * 0.1 ** 3)
288
289 # solid from shells
290 s4 = solid(b.shells())
291
292 assert s4.Volume() == approx(1)
293
294 # check history handling
295 hist = History()
296 s4 = solid(
297 b.Faces(), b1.moved([(0.2, 0, 0.5), (-0.2, 0, 0.5)]).Faces(), history=hist
298 )
299
300 final_faces = s4.Faces()
301 final_faces_history = hist[-1]._images
302 for f in final_faces:
303 assert f in final_faces_history
304
305 # solid with multiple periodic voids
306 s5 = solid(b_large.Faces(), inner=sphere1.Faces() + sphere2.Faces())
307
308 assert s5.isValid()
309 assert s5.Volume() == approx(b_large.Volume() - 2 * sphere1.Volume())
310
311 # solid with multiple simple voids
312 s6 = solid(b_large.Faces(), inner=b_small.Faces() + b_small.moved(x=1).Faces())
313
314 assert s6.isValid()
315 assert s6.Volume() == approx(b_large.Volume() - 2 * b_small.Volume())
316
317
318def test_edgeOn():

Callers

nothing calls this directly

Calls 9

HistoryClass · 0.90
boxFunction · 0.85
sphereFunction · 0.85
solidFunction · 0.85
VolumeMethod · 0.80
isValidMethod · 0.80
movedMethod · 0.45
FacesMethod · 0.45
shellsMethod · 0.45

Tested by

no test coverage detected