def clip (x, min, max):
	"""
	Constrain a given value (x) to be between two (ordered) bounds: min
	and max.  Returns x if it is between the bounds, otherwise returns
	the nearer bound
	"""
	if (x < min): return min
	if (x > max): return max
	return x