/*! gcc -std=c89 -pedantic -Wall -g -o test2 test2.c libkdtree.a -lm */ /* Extended test program, contributed by David Underhill */ #include #include #include #include #include #include #include "kdtree.h" #define DEF_NUM_PTS 10 /* returns the distance squared between two dims-dimensional double arrays */ static double dist_sq( double *a1, double *a2, int dims ); /* get a random double between -10 and 10 */ static double rd( void ); int main(int argc, char **argv) { int i, num_pts = DEF_NUM_PTS; void *ptree; char *data, *pch; struct kdres *presults; double pos[3], dist; double pt[3] = { 0, 0, 1 }; double radius = 10; if(argc > 1 && isdigit(argv[1][0])) { num_pts = atoi(argv[1]); } if(!(data = malloc(num_pts))) { perror("malloc failed"); return 1; } srand( time(0) ); /* create a k-d tree for 3-dimensional points */ ptree = kd_create( 3 ); /* add some random nodes to the tree (assert nodes are successfully inserted) */ for( i=0; i= 0 ) { diff = (a1[dims] - a2[dims]); dist_sq += diff*diff; } return dist_sq; } static double rd( void ) { return (double)rand()/RAND_MAX * 20.0 - 10.0; }