Points3D accepts + - / * operators both in Grasshopper canvas AND Rhinocommon/c# script
(apart from mupliplying or dividing one point with another…)
To make it accepts points and numbers you have to make the inputs enter as generic “object” and only later cast them as points or numbers (“x = (int) y;” is casting object y to x as int type).
Also, to make it fast you’ll want to have the c# script load its input/sources as Lists:
Lastly, by using System.Threading.Tasks you can make your code use all your processor threads.
Note: I created a pre-determined size array to store results (object[] c = new object[n];); this is to ensure that each thread/process works without the risk of “colliding” with others (for example by accessing the same object simultaneously, causing your pc to explode).
Code:
using System.Threading.Tasks;
private void RunScript(List<System.Object> A, List<System.Object> B, List<double> t, ref object C)
{
int n = A.Count;
object[] c = new object[n];
Parallel.For(0, n, i => {
//for(int i = 0;i < n;i++){
if(A[i] is double && B[i] is double){
double a = (double) A[i];
double b = (double) B[i];
c[i] = (b - a) * t[i] + a;
}
if(A[i] is Rhino.Geometry.Point3d && B[i] is Rhino.Geometry.Point3d){
Rhino.Geometry.Point3d a = (Rhino.Geometry.Point3d) A[i];
Rhino.Geometry.Point3d b = (Rhino.Geometry.Point3d) B[i];
c[i] = (b - a) * t[i] + a;
}
//}
});
C = c;
}
Thank you for the detailed explanation @maje90.
This works really great! and how about in the case that I just want to use a single value in the “t” parameter,
Do I need to clone a single value with my list for it to work?
Thank you again!