def norm_angle(a):
    """Normalizes an angle in degrees to -180 ~ +180 deg."""
    a = a % 360
    if a >= 0 and a <= 180:
        return a
    if a > 180:
        return -180 + (-180 + a)
    if a >= -180 and a < 0:
        return a
    return 180 + (a + 180)