private static int Clamp(int min, int max, int value) { return Math.Max (min, Math.Min (max, value)); }