clamp method

int clamp(
  1. int min,
  2. int max
)

Implementation

int clamp(int min, int max) {
  if (this < min) {
    return min;
  } else if (this > max) {
    return max;
  } else {
    return this;
  }
}