Ejemplo n.º 1
0
def test_with_axes(py_c_vec):
    """Test the with_axes() constructor."""
    Vec, Angle, Matrix, parse_vec_str = py_c_vec

    for axis, u, v in [
        ('pitch', 'yaw', 'roll'),
        ('yaw', 'pitch', 'roll'),
        ('roll', 'pitch', 'yaw'),
    ]:
        for num in VALID_ZERONUMS:
            test_num = num % 360

            ang = Angle.with_axes(axis, num)
            assert ang[axis] == test_num
            assert getattr(ang, axis) == test_num
            # Other axes are zero.
            assert ang[u] == 0
            assert ang[v] == 0
            assert getattr(ang, u) == 0
            assert getattr(ang, v) == 0

    for a, b, c in iter_vec(('pitch', 'yaw', 'roll')):
        if a == b or b == c or a == c:
            continue
        for x, y, z in iter_vec(VALID_ZERONUMS):
            ang = Angle.with_axes(a, x, b, y, c, z)

            x %= 360
            y %= 360
            z %= 360

            assert ang[a] == x
            assert ang[b] == y
            assert ang[c] == z

            assert getattr(ang, a) == x
            assert getattr(ang, b) == y
            assert getattr(ang, c) == z
Ejemplo n.º 2
0
def _fill_norm_rotations() -> Dict[Tuple[Tuple[float, float, float], Tuple[
    float, float, float]], Matrix, ]:
    """Given a norm->norm rotation, return the angles producing that."""
    rotations = {}
    for norm_ax in 'xyz':
        for norm_mag in [-1, +1]:
            norm = Vec.with_axes(norm_ax, norm_mag)
            for angle_ax in ('pitch', 'yaw', 'roll'):
                for angle_mag in (-90, 90):
                    angle = Matrix.from_angle(
                        Angle.with_axes(angle_ax, angle_mag))
                    new_norm = norm @ angle
                    if new_norm != norm:
                        rotations[norm.as_tuple(), new_norm.as_tuple()] = angle
            # Assign a null rotation as well.
            rotations[norm.as_tuple(), norm.as_tuple()] = Matrix()
            rotations[norm.as_tuple(), (-norm).as_tuple()] = Matrix()
    return rotations