clamp

image This function clamps an input two an upper or lower bound, or min / max values. It returns the value a when t is less than a, the value t when t is between a and b, and the value b when t is greater than b.

Downloadclamp(t,a,b)   Returns a value t constrained by upper and lower bounds a and b.
/*
**  Usage:
**      clamp(t,a,b)
**
**  Arguments:
**      t       value, real
**      a       lower bound, real
**      b       upper bound, real
**
**  Returns:
**      (a) when (t < a), (b) when (t > b),
**      (t) otherwise
**
**  GMLscripts.com
*/

{
    if (argument0 < argument1) return argument1;
    if (argument0 > argument2) return argument2;
    return argument0;
}

Click if you've used this script[Please Login]
Projects: 2

 Contributor: xot


comments powered by Disqus