def wrap_angle(x):
    """Wraps an angle between 0 and 360 degrees

    Args:
        x: the angle to wrap
    Returns:
        a new angle on the interval [0, 360]
    """
    if x < 0:
        x = 360 - x
    elif x > 360:
        x = x - 360
    return x