#include // to use realloc #include // to use NAN #include // to use printf double* getpoint(double* points, unsigned dim, unsigned id){ double* out = malloc(dim * sizeof(double)); for(unsigned i=0; i < dim; i++){ out[i] = points[id*dim+i]; } return out; } /* dot product of two vectors */ double dotproduct(double* p1, double* p2, unsigned dim){ double out = 0; for(unsigned i=0; i < dim; i++){ out += p1[i] * p2[i]; } return out; } /* middle of segment [p1,p2] */ double* middle(double* p1, double* p2, unsigned dim){ double* out = malloc(dim * sizeof(double)); for(unsigned i=0; i 0 ? 1 : -1); } void qsortu(unsigned* vector, unsigned length){ qsort(vector, length, sizeof(unsigned), cmpfunc); } double square(double x){ return x*x; } /* append to a vector of unsigned */ void appendu(unsigned x, unsigned** array, unsigned length, unsigned* flag){ *flag = 1; for(unsigned i=0; i