def test_transform_set_invalid(self): """Setting the Node transform with an invalid value.""" n = Node() with self.assertRaises(TypeError, msg="Setting transform with an invalid value (a string) did not raise a TypeError."): n.transform = "spoon" with self.assertRaises(TypeError, msg="Setting transform with an invalid value (None) did not raise a TypeError."): n.transform = None
def test_transform(self): """Setting the Node transform.""" # build initial tree a = Node() b = Node(a, translate(1,2,3)) c = Node(b, translate(10,20,30)) d1 = Node(c, translate(100,200,300)) d2 = Node(c, translate(200,400,600)) e = Node(d1, translate(1000,2000,3000)) # define new transform m = translate(20,40,60) # set c's transform c.transform = m # is c.transform correct? self.assertTransformAlmostEqual(c.transform, translate(20,40,60), delta = 1e-14, msg = "Transform matrix was set correctly.") # have the root transforms been correctly propagated to this nodes children, parent nodes should be unaffected self.assertTransformAlmostEqual(a._root_transform, AffineMatrix3D(), delta = 1e-14, msg ="Root node's root transform should not have been modified by change of transform.") self.assertTransformAlmostEqual(a._root_transform_inverse, AffineMatrix3D(), delta = 1e-14, msg ="Root node's inverse root transform should not have been modified by change of transform.") self.assertTransformAlmostEqual(b._root_transform, translate(1,2,3), delta = 1e-14, msg = "Parent's root transform should not have been modified by change of transform.") self.assertTransformAlmostEqual(b._root_transform_inverse, translate(1,2,3).inverse(), delta = 1e-14, msg = "Parent's inverse root transform should not have been modified by change of transform.") self.assertTransformAlmostEqual(c._root_transform, translate(21,42,63), delta = 1e-14, msg = "Root transform has not correctly propagated for node c.") self.assertTransformAlmostEqual(c._root_transform_inverse, translate(21,42,63).inverse(), delta = 1e-14, msg = "Inverse root transform has not correctly propagated for node c.") self.assertTransformAlmostEqual(d1._root_transform, translate(121,242,363), delta = 1e-14, msg = "Root transform has not correctly propagated to node's 1st immediate child.") self.assertTransformAlmostEqual(d1._root_transform_inverse, translate(121,242,363).inverse(), delta = 1e-14, msg = "Inverse root transform has not correctly propagated to node's 1st immediate child.") self.assertTransformAlmostEqual(d2._root_transform, translate(221,442,663), delta = 1e-14, msg = "Root transform has not correctly propagated to node's 2nd immediate child.") self.assertTransformAlmostEqual(d2._root_transform_inverse, translate(221,442,663).inverse(), delta = 1e-14, msg = "Inverse root transform has not correctly propagated to node's 2nd immediate child.") self.assertTransformAlmostEqual(e._root_transform, translate(1121,2242,3363), delta = 1e-14, msg = "Root transform has not correctly propagated to node's distant children.") self.assertTransformAlmostEqual(e._root_transform_inverse, translate(1121,2242,3363).inverse(), delta = 1e-14, msg = "Inverse root transform has not correctly propagated to node's distant children.")