clamp

Hi,

I would like to see a clamp function in ofMath, which could be a useful thing. Maybe something like this:

  
  
float ofClampf(float val, float min, float max) {  
	if (val > max) return max;  
	if (val < min) return min;  
	return val;  
}  
  

no?

ciao
/cj

good suggestion! -

I actually needed that recently, because I kept writing MAX(…, MIN(…, …)) to do the same thing. We might make it a #define – it’ll get in the next release for sure.

thanks!!
zach