package eu.mhsl.minenet.minigames.util;

public class NumberUtil {
    public static double map(double oldValue, double oldMin, double oldMax, double newMin, double newMax) {
        double out =  (((oldValue - oldMin) * (newMax - newMin)) / (oldMax - oldMin)) + newMin;
        if(out > newMax) out = newMax;
        if(out < newMin) out = newMin;

        return out;
    }

    public static <T extends Comparable<T>> T clamp(T val, T min, T max) {
        if (val.compareTo(min) < 0) return min;
        else if (val.compareTo(max) > 0) return max;
        else return val;
    }
}
