Polynomial Knot script
All  1  2-3

Previous
Next
 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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  bemfarmer
5279.3 In reply to 5279.2 
Thank you very much Michael.
You make it seem so simple.
Spent a few hours on google looking at anonymous functions, dynamic function renaming, eval, functions in an array...
Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages: All  1  2-3