You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

boxstep

The boxstep function is somewhere between step and smoothstep. It is the result of the convolution of a box filter with a step edge. The width of the box filter is (b - a) and the slope of the ramp is 1/width.

boxstep

boxstep(a, b, x)
Returns 0 when (x <= a), 1 when (x >= b), a linear transition from 0 to 1 when (a < x < b), or (-1) on error (a == b).
COPY/// @func   boxstep(a, b, x)
///
/// @desc   Returns 0 when (x <= a), 1 when (x >= b), a linear transition
///         from 0 to 1 when (a < x < b), or (-1) on error (a == b). 
///
/// @param  {real}      a           lower bound
/// @param  {real}      b           upper bound
/// @param  {real}      x           value
///
/// @return {real}      value between 0 and 1
///
/// GMLscripts.com/license

function boxstep(a, b, x)
{
    if (a == b) return (-1);
    var p = (x - a) / (b - a);
    return clamp(p, 0, 1);
}

Contributors: xot

GitHub: View · Commits · Blame · Raw