def test_numpy_interop(): rot = Quat.from_rotation_on_axis(2, np.pi / 2) trans = Vec3(1, 1, 1) # fmt: off np_T = np.array([ [0, -1, 0, 1], [1, 0, 0, 1], [0, 0, 1, 1], [0, 0, 0, 1], ]) # fmt: on T_a_b = Transform(rot, trans) T_a_b_from_mat4 = Transform.from_mat4_numpy(np_T) T_a_b_from_quatvec3 = Transform.from_quat_vec3_numpy( np.concatenate((rot.to_xyzw_numpy(), trans.to_numpy())) ) assert T_a_b == T_a_b_from_mat4 assert T_a_b == T_a_b_from_quatvec3 assert T_a_b_from_quatvec3 == T_a_b_from_mat4 np_mat4_T = T_a_b.to_mat4_numpy() np_quatvec3_T = T_a_b.to_quat_vec3_numpy() assert np.allclose( np_quatvec3_T, np.concatenate((rot.to_xyzw_numpy(), trans.to_numpy())) ) assert np.allclose(np_mat4_T, np_T)
def test_inverse(): t = Transform(Quat.from_axis_angle(Vec3(1, 1, 1), np.pi / 2), Vec3(4, 5, 6)) t_inv = t.inverse() t_identity_one = t * t_inv t_identity_two = t_inv * t np_identity = np.diag((1, 1, 1, 1)) t_fromnp = Transform.from_mat4_numpy(np_identity) assert np.allclose(t_identity_one.to_mat4_numpy(), np_identity) assert np.allclose(t_identity_two.to_mat4_numpy(), np_identity) assert np.allclose(t_identity_one.to_mat4_numpy(), t_identity_two.to_mat4_numpy()) assert t_identity_one == t_fromnp assert t_identity_two == t_fromnp assert t_identity_one == t_identity_two