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

Method testNthDistance

tests/test_selectors.py:390–502  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

388 self.assertAlmostEqual(e.Center().z, 0)
389
390 def testNthDistance(self):
391 c = Workplane("XY").pushPoints([(-2, 0), (2, 0)]).box(1, 1, 1)
392
393 # 2nd face
394 val = c.faces(selectors.DirectionNthSelector(Vector(1, 0, 0), 1)).val()
395 self.assertAlmostEqual(val.Center().x, -1.5)
396
397 # 2nd face with inversed selection vector
398 val = c.faces(selectors.DirectionNthSelector(Vector(-1, 0, 0), 1)).val()
399 self.assertAlmostEqual(val.Center().x, 1.5)
400
401 # 2nd last face
402 val = c.faces(selectors.DirectionNthSelector(Vector(1, 0, 0), -2)).val()
403 self.assertAlmostEqual(val.Center().x, 1.5)
404
405 # Last face
406 val = c.faces(selectors.DirectionNthSelector(Vector(1, 0, 0), -1)).val()
407 self.assertAlmostEqual(val.Center().x, 2.5)
408
409 # check if the selected face if normal to the specified Vector
410 self.assertAlmostEqual(val.normalAt().cross(Vector(1, 0, 0)).Length, 0.0)
411
412 # repeat the test using string based selector
413
414 # 2nd face
415 val = c.faces(">(1,0,0)[1]").val()
416 self.assertAlmostEqual(val.Center().x, -1.5)
417 val = c.faces(">X[1]").val()
418 self.assertAlmostEqual(val.Center().x, -1.5)
419
420 # 2nd face with inversed selection vector
421 val = c.faces(">(-1,0,0)[1]").val()
422 self.assertAlmostEqual(val.Center().x, 1.5)
423 val = c.faces("<X[1]").val()
424 self.assertAlmostEqual(val.Center().x, 1.5)
425
426 # 2nd last face
427 val = c.faces(">X[-2]").val()
428 self.assertAlmostEqual(val.Center().x, 1.5)
429
430 # Last face
431 val = c.faces(">X[-1]").val()
432 self.assertAlmostEqual(val.Center().x, 2.5)
433
434 # check if the selected face if normal to the specified Vector
435 self.assertAlmostEqual(val.normalAt().cross(Vector(1, 0, 0)).Length, 0.0)
436
437 # test selection of multiple faces with the same distance
438 c = (
439 Workplane("XY")
440 .box(1, 4, 1, centered=(False, True, False))
441 .faces("<Z")
442 .box(2, 2, 2, centered=(True, True, False))
443 .faces(">Z")
444 .box(1, 1, 1, centered=(True, True, False))
445 )
446
447 # select 2nd from the bottom (NB python indexing is 0-based)

Callers

nothing calls this directly

Calls 13

WorkplaneClass · 0.85
VectorClass · 0.85
boxMethod · 0.80
pushPointsMethod · 0.80
crossMethod · 0.80
transformedMethod · 0.80
valMethod · 0.45
facesMethod · 0.45
CenterMethod · 0.45
normalAtMethod · 0.45
valsMethod · 0.45

Tested by

no test coverage detected