def remap(v, in_range, out_range):
    """rescales a value from one range to another"""
    in_v_norm = (in_range[1]-v)/(in_range[1]-in_range[0])
    clamped_norm = min(1, max(0, in_v_norm))
    return out_range[0] + clamped_norm*(out_range[1] - out_range[0])