@@ -40,13 +40,11 @@ static VALUE kdtree_persist(VALUE kdtree, VALUE io);
4040static VALUE kdtree_to_s (VALUE kdtree );
4141
4242// kdtree helpers
43- static int kdtree_build (struct kdtree_data * kdtreep , int min , int max ,
44- int depth );
45- static void kdtree_nearest0 (struct kdtree_data * kdtreep , int i , float x ,
46- float y , int depth , int * n_index , float * n_dist );
47- static void kdtree_nearestk0 (struct kdtree_data * kdtreep , int i , float x ,
48- float y , int k , int depth , kresult * k_list ,
49- int * k_len , float * k_dist );
43+ static int kdtree_build (struct kdtree_data * kdtreep , int min , int max , int depth );
44+ static void kdtree_nearest0 (struct kdtree_data * kdtreep , int i , float x , float y , int depth ,
45+ int * n_index , float * n_dist );
46+ static void kdtree_nearestk0 (struct kdtree_data * kdtreep , int i , float x , float y , int k , int depth ,
47+ kresult * k_list , int * k_len , float * k_dist );
5048
5149// io helpers
5250static void read_all (VALUE io , void * buf , int len );
@@ -63,8 +61,7 @@ static ID id_read, id_write, id_binmode;
6361
6462static VALUE kdtree_alloc (VALUE klass ) {
6563 struct kdtree_data * kdtreep ;
66- VALUE obj =
67- Data_Make_Struct (klass , struct kdtree_data , 0 , kdtree_free , kdtreep );
64+ VALUE obj = Data_Make_Struct (klass , struct kdtree_data , 0 , kdtree_free , kdtreep );
6865 kdtreep -> root = -1 ;
6966 return obj ;
7067}
@@ -135,8 +132,7 @@ static VALUE kdtree_initialize(VALUE kdtree, VALUE arg) {
135132 }
136133
137134 // read start of the struct
138- read_all (io , kdtreep ,
139- sizeof (struct kdtree_data ) - sizeof (struct kdtree_node * ));
135+ read_all (io , kdtreep , sizeof (struct kdtree_data ) - sizeof (struct kdtree_node * ));
140136
141137 // read the nodes
142138 kdtreep -> nodes = ALLOC_N (struct kdtree_node , kdtreep -> len );
@@ -160,8 +156,7 @@ static int comparey(const void *pa, const void *pb) {
160156 return (a < b ) ? -1 : ((a > b ) ? 1 : 0 );
161157}
162158
163- static int kdtree_build (struct kdtree_data * kdtreep , int min , int max ,
164- int depth ) {
159+ static int kdtree_build (struct kdtree_data * kdtreep , int min , int max , int depth ) {
165160 int (* compar )(const void * , const void * );
166161 struct kdtree_node * m ;
167162 int median ;
@@ -205,16 +200,15 @@ static VALUE kdtree_nearest(VALUE kdtree, VALUE x, VALUE y) {
205200 n_index = -1 ;
206201 n_dist = INT_MAX ;
207202
208- kdtree_nearest0 (kdtreep , kdtreep -> root , NUM2DBL (x ), NUM2DBL (y ), 0 , & n_index ,
209- & n_dist );
203+ kdtree_nearest0 (kdtreep , kdtreep -> root , NUM2DBL (x ), NUM2DBL (y ), 0 , & n_index , & n_dist );
210204 if (n_index == -1 ) {
211205 return -1 ;
212206 }
213207 return INT2NUM ((kdtreep -> nodes + n_index )-> id );
214208}
215209
216- static void kdtree_nearest0 (struct kdtree_data * kdtreep , int i , float x ,
217- float y , int depth , int * n_index , float * n_dist ) {
210+ static void kdtree_nearest0 (struct kdtree_data * kdtreep , int i , float x , float y , int depth ,
211+ int * n_index , float * n_dist ) {
218212 struct kdtree_node * n ;
219213 float ad ;
220214 int near , far ;
@@ -297,8 +291,8 @@ static VALUE kdtree_nearestk(VALUE kdtree, VALUE x, VALUE y, VALUE k) {
297291 } else if (ki > MAX_K ) {
298292 ki = MAX_K ;
299293 }
300- kdtree_nearestk0 (kdtreep , kdtreep -> root , NUM2DBL (x ), NUM2DBL (y ), ki , 0 ,
301- k_list , & k_len , & k_dist );
294+ kdtree_nearestk0 (kdtreep , kdtreep -> root , NUM2DBL (x ), NUM2DBL (y ), ki , 0 , k_list , & k_len ,
295+ & k_dist );
302296
303297 // convert result to ruby array
304298 ary = rb_ary_new ();
@@ -308,9 +302,8 @@ static VALUE kdtree_nearestk(VALUE kdtree, VALUE x, VALUE y, VALUE k) {
308302 return ary ;
309303}
310304
311- static void kdtree_nearestk0 (struct kdtree_data * kdtreep , int i , float x ,
312- float y , int k , int depth , kresult * k_list ,
313- int * k_len , float * k_dist ) {
305+ static void kdtree_nearestk0 (struct kdtree_data * kdtreep , int i , float x , float y , int k , int depth ,
306+ kresult * k_list , int * k_len , float * k_dist ) {
314307 struct kdtree_node * n ;
315308 float ad ;
316309 int near , far ;
@@ -338,8 +331,7 @@ static void kdtree_nearestk0(struct kdtree_data *kdtreep, int i, float x,
338331 }
339332 kdtree_nearestk0 (kdtreep , near , x , y , k , depth + 1 , k_list , k_len , k_dist );
340333 if (ad * ad < * k_dist ) {
341- kdtree_nearestk0 (kdtreep , far , x , y , k , depth + 1 , k_list , k_len ,
342- k_dist );
334+ kdtree_nearestk0 (kdtreep , far , x , y , k , depth + 1 , k_list , k_len , k_dist );
343335 }
344336
345337 //
@@ -367,8 +359,7 @@ static void kdtree_nearestk0(struct kdtree_data *kdtreep, int i, float x,
367359 // insert
368360 //
369361
370- memmove (k_list + lo + 1 , k_list + lo ,
371- (* k_len - lo ) * sizeof (struct kresult ));
362+ memmove (k_list + lo + 1 , k_list + lo , (* k_len - lo ) * sizeof (struct kresult ));
372363 k_list [lo ].index = i ;
373364 k_list [lo ].distance = d ;
374365
@@ -422,8 +413,7 @@ static VALUE kdtree_persist(VALUE kdtree, VALUE io) {
422413 }
423414
424415 write_all (io , KDTREE_MAGIC , 4 );
425- write_all (io , kdtreep ,
426- sizeof (struct kdtree_data ) - sizeof (struct kdtree_node * ));
416+ write_all (io , kdtreep , sizeof (struct kdtree_data ) - sizeof (struct kdtree_node * ));
427417 write_all (io , kdtreep -> nodes , sizeof (struct kdtree_node ) * kdtreep -> len );
428418 return io ;
429419}
@@ -438,8 +428,7 @@ static VALUE kdtree_to_s(VALUE kdtree) {
438428 char buf [256 ];
439429 KDTREEP ;
440430
441- sprintf (buf , "#<%s:%p nodes=%d>" , rb_obj_classname (kdtree ), (void * )kdtree ,
442- kdtreep -> len );
431+ sprintf (buf , "#<%s:%p nodes=%d>" , rb_obj_classname (kdtree ), (void * )kdtree , kdtreep -> len );
443432 return rb_str_new (buf , strlen (buf ));
444433}
445434
0 commit comments