Polynomial Knot script

 From:  Michael Gibson
5279.2 In reply to 5279.1 
Hi Brian,

> I would like to place the If Else statements outside of the for loop, and have them "rename" the EvalPolyKnotxxx,
> in the for loop, to the correct function to use to calculate the control points of the curve.


There isn't really anything wrong with how you have it now, since the time required to do those if /else parts will be extremely small in comparison to any of the calls to MoI since the MoI calls work by using inter-process communication for every call.

So if you're worried about it from a performance standpoint I'd say not to worry about it for that case.

But the way you could make it work like you are describing would be to make a variable that holds the function to be called - in JavaScript a variable can hold a function in the same way that it can hold a piece of data.

So you could do something like this (not actually tested so there might be a typo or something):

code:
var func;

if ( knottype == '3_1' )
   func = EvalPolyKnot3_1;
else if ( knottype == '4_1' )
   func = EvalPolyKnot4_1;
else
   return;

for ( var i = 0; i < numpoints; ++i )
{
      // Call whatever function the 'func' variable currently holds.
      var pt = func( t2, len, mir );

      .....
}


I think that's the kind of function "rename" thing that you're asking about - basically you put the function into a variable itself to do that.

- Michael