def bound_value(lower, val, higher): return min(max(val, lower), higher)