/*
Computes the primitive of the Function (whose value for the first point is 0)
and returns it as a new Function.
The newly created function shares the X vector with the previous one.
*/
static VALUE function_primitive(VALUE self)
{
long size = function_sanity_check(self);
const double *x = Dvector_Data_for_Read(get_x_vector(self),NULL);
const double *y = Dvector_Data_for_Read(get_y_vector(self),NULL);
VALUE primitive = Dvector_Create();
long i = 0;
double val = 0;
while(i < (size - 1))
{
Dvector_Push_Double(primitive, val);
val += (y[i] + y[i+1]) * (x[i+1] - x[i]) * 0.5;
i++;
}
Dvector_Push_Double(primitive, val);
return Function_Create(get_x_vector(self), primitive);
}