def test_vec_identities(py_c_vec) -> None: """Check that vectors in the same axis as the rotation don't get spun.""" Vec, Angle, Matrix, parse_vec_str = py_c_vec for ang in range(0, 360, 13): # Check the two constructors match. assert_rot(Matrix.from_pitch(ang), Matrix.from_angle(Angle(pitch=ang))) assert_rot(Matrix.from_yaw(ang), Matrix.from_angle(Angle(yaw=ang))) assert_rot(Matrix.from_roll(ang), Matrix.from_angle(Angle(roll=ang))) # Various magnitudes to test for mag in (-250, -1, 0, 1, 250): assert_vec(Vec(y=mag) @ Matrix.from_pitch(ang), 0, mag, 0) assert_vec(Vec(z=mag) @ Matrix.from_yaw(ang), 0, 0, mag) assert_vec(Vec(x=mag) @ Matrix.from_roll(ang), mag, 0, 0)
def test_vec_basic_pitch(py_c_vec) -> None: """Check each direction rotates appropriately in pitch.""" Vec, Angle, Matrix, parse_vec_str = py_c_vec assert_vec(Vec(200, 0, 0) @ Matrix.from_pitch(0), 200, 0, 0) assert_vec(Vec(0, 0, 150) @ Matrix.from_pitch(0), 0, 0, 150) assert_vec(Vec(200, 0, 0) @ Matrix.from_pitch(90), 0, 0, -200) assert_vec(Vec(0, 0, 150) @ Matrix.from_pitch(90), 150, 0, 0) assert_vec(Vec(200, 0, 0) @ Matrix.from_pitch(180), -200, 0, 0) assert_vec(Vec(0, 0, 150) @ Matrix.from_pitch(180), 0, 0, -150) assert_vec(Vec(200, 0, 0) @ Matrix.from_pitch(270), 0, 0, 200) assert_vec(Vec(0, 0, 150) @ Matrix.from_pitch(270), -150, 0, 0)
def test_matrix_roundtrip_pitch(py_c_vec): """Check converting to and from a Matrix does not change values.""" Vec, Angle, Matrix, parse_vec_str = py_c_vec # We can't directly check the resulted value, some of these produce # gimbal lock and can't be recovered. # So instead check the rotation matrix is the same. for pitch in range(0, 360, 45): old_ang = Angle(pitch, 0, 0) new_ang = Matrix.from_pitch(pitch).to_angle() assert_rot( Matrix.from_angle(old_ang), Matrix.from_angle(new_ang), (old_ang, new_ang), )