static int clamp ( int value , int upperLimit ) { if ( value < 0 ) { return value + ( - 1 * ( int ) Math . floor ( value / ( float ) upperLimit ) ) * upperLimit ; } else { return value % upperLimit ; } }
Clamps the value to a number between 0 and the upperLimit