<div dir="ltr">Hey Michael,<div><br></div><div style>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. </div>
<div style><br></div><div style>spencer</div><div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Dec 31, 2012 at 12:53 PM, Michael Heuer <span dir="ltr"><<a href="mailto:heuermh@gmail.com" target="_blank">heuermh@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I find myself using the following all the time and was wondering how<br>
difficult it would be to add them to Std or Math<br>
<br>
    fun static int constrain(int value, int min, int max)<br>
    {<br>
        if (value < min)<br>
        {<br>
            return min;<br>
        }<br>
        if (value > max)<br>
        {<br>
            return max;<br>
        }<br>
        return value;<br>
    }<br>
<br>
    fun static float constrainf(float value, float min, float max)<br>
    {<br>
        if (value < min)<br>
        {<br>
           return min;<br>
        }<br>
        if (value > max)<br>
        {<br>
            return max;<br>
        }<br>
        return value;<br>
    }<br>
<br>
    fun static float interp(float value, float sourceMin, float<br>
sourceMax, float targetMin, float targetMax)<br>
    {<br>
        return targetMin + (targetMax - targetMin) * ((value -<br>
sourceMin) / (sourceMax - sourceMin));<br>
    }<br>
<br>
Thanks,<br>
<br>
   michael<br>
_______________________________________________<br>
chuck-dev mailing list<br>
<a href="mailto:chuck-dev@lists.cs.princeton.edu">chuck-dev@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-dev" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-dev</a><br>
<br>
</blockquote></div><br></div>