1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
AVSValue Spline(AVSValue args, void*, IScriptEnvironment* env )
{
float *xa, *ya, *y2a;
int n;
float x,y;
int i;
bool cubic;
AVSValue coordinates;
x = args[0].float AsFloat(0);
coordinates = args[1];
cubic = args[2].AsBool(true);
n = coordinates.ArraySize() ;
if (n<4 || n&1) env->ThrowError("To few arguments for Spline");
n=n/2;
xa = new float[n+1];
ya = new float[n+1];
y2a = new float[n+1];
for (i=1; i<=n; i++) {
xa[i] = coordinates[(i-1)*2].AsFloat(0);
ya[i] = coordinates[(i-1)*2+1].AsFloat(0);
}
for (i=1; i<n; i++) {
if (xa[i] >= xa[i+1]) env->ThrowError("Spline: all x values have to be different and in ascending order!");
}
spline(xa, ya, n, y2a);
splint(xa, ya, y2a, n, x, y, cubic);
delete[] xa;
delete[] ya;
delete[] y2a;
return y;
}
|