[chuck-dev] add methods to Std or Math

Spencer Salazar spencer at ccrma.stanford.edu
Wed Jan 2 19:33:47 EST 2013


Hey Michael,

Yeah, these are super useful functions. I have these and a few others
defined in a public class called "Std2" whose source file is in my chugin
directory. ChucK executes .ck files in the chugin directory at launch, so
they are pretty much available for general usage on my system. I think in
the future it would make sense/be easy to have these builtin to the
language itself though.

spencer



On Mon, Dec 31, 2012 at 12:53 PM, Michael Heuer <heuermh at gmail.com> wrote:

> 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
> _______________________________________________
> chuck-dev mailing list
> chuck-dev at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-dev/attachments/20130102/28810d33/attachment.html>


More information about the chuck-dev mailing list