function clampInt(min, max, input) {
    if (input < min) {
        return min;
    }
    else if (input > max) {
        return max;
    }
    return input;
}
Clamps an integer between two integers.

@return input when min <= input <= max, and either min or max
otherwise.