def clip(value, min_v, max_v):
    """
    Clip the given value to be within a range
    https://stackoverflow.com/questions/9775731/clamping-floating-numbers-in-python
    """
    return max(min(value, max_v), min_v)