MCPcopy Index your code
hub / github.com/CadQuery/cadquery / testMatrixFunctionality

Method testMatrixFunctionality

tests/test_cad_objects.py:449–512  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

447 self.assertEqual(str(eval(repr(m))), mRepr)
448
449 def testMatrixFunctionality(self):
450 # Test rotate methods
451 def matrix_almost_equal(m, target_matrix):
452 for r, row in enumerate(target_matrix):
453 for c, target_value in enumerate(row):
454 self.assertAlmostEqual(m[r, c], target_value)
455
456 root_3_over_2 = math.sqrt(3) / 2
457 m_rotate_x_30 = [
458 [1, 0, 0, 0],
459 [0, root_3_over_2, -1 / 2, 0],
460 [0, 1 / 2, root_3_over_2, 0],
461 [0, 0, 0, 1],
462 ]
463 mx = Matrix()
464 mx.rotateX(30 * DEG2RAD)
465 matrix_almost_equal(mx, m_rotate_x_30)
466
467 m_rotate_y_30 = [
468 [root_3_over_2, 0, 1 / 2, 0],
469 [0, 1, 0, 0],
470 [-1 / 2, 0, root_3_over_2, 0],
471 [0, 0, 0, 1],
472 ]
473 my = Matrix()
474 my.rotateY(30 * DEG2RAD)
475 matrix_almost_equal(my, m_rotate_y_30)
476
477 m_rotate_z_30 = [
478 [root_3_over_2, -1 / 2, 0, 0],
479 [1 / 2, root_3_over_2, 0, 0],
480 [0, 0, 1, 0],
481 [0, 0, 0, 1],
482 ]
483 mz = Matrix()
484 mz.rotateZ(30 * DEG2RAD)
485 matrix_almost_equal(mz, m_rotate_z_30)
486
487 # Test matrix multipy vector
488 v = Vector(1, 0, 0)
489 self.assertTupleAlmostEquals(
490 mz.multiply(v).toTuple(), (root_3_over_2, 1 / 2, 0), 7
491 )
492
493 # Test matrix multipy matrix
494 m_rotate_xy_30 = [
495 [root_3_over_2, 0, 1 / 2, 0],
496 [1 / 4, root_3_over_2, -root_3_over_2 / 2, 0],
497 [-root_3_over_2 / 2, 1 / 2, 3 / 4, 0],
498 [0, 0, 0, 1],
499 ]
500 mxy = mx.multiply(my)
501 matrix_almost_equal(mxy, m_rotate_xy_30)
502
503 # Test matrix inverse
504 vals4x4 = [[1, 2, 3, 4], [5, 1, 6, 7], [8, 9, 1, 10], [0, 0, 0, 1]]
505 vals4x4_invert = [
506 [-53 / 144, 25 / 144, 1 / 16, -53 / 144],

Callers

nothing calls this directly

Calls 9

rotateXMethod · 0.95
rotateYMethod · 0.95
rotateZMethod · 0.95
multiplyMethod · 0.95
MatrixClass · 0.85
VectorClass · 0.85
toTupleMethod · 0.45
inverseMethod · 0.45

Tested by

no test coverage detected