private static float bound(float num, int min, int max) {
        if (Math.round(num) < min) {
            return min - 0.5f;
        }
        if (Math.round(num) >= max) {
            return max - 1 + 0.499999f;
        }
        return num;
    }