[chuck-dev] add methods to Std or Math

Michael Heuer heuermh at gmail.com
Mon Dec 31 15:53:15 EST 2012


Hello,

I find myself using the following all the time and was wondering how
difficult it would be to add them to Std or Math

    fun static int constrain(int value, int min, int max)
    {
        if (value < min)
        {
            return min;
        }
        if (value > max)
        {
            return max;
        }
        return value;
    }

    fun static float constrainf(float value, float min, float max)
    {
        if (value < min)
        {
           return min;
        }
        if (value > max)
        {
            return max;
        }
        return value;
    }

    fun static float interp(float value, float sourceMin, float
sourceMax, float targetMin, float targetMax)
    {
        return targetMin + (targetMax - targetMin) * ((value -
sourceMin) / (sourceMax - sourceMin));
    }

Thanks,

   michael


More information about the chuck-dev mailing list