@@ -40,13 +40,11 @@ static VALUE kdtree_persist(VALUE kdtree, VALUE io);
40
40
static VALUE kdtree_to_s (VALUE kdtree );
41
41
42
42
// 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 );
50
48
51
49
// io helpers
52
50
static void read_all (VALUE io , void * buf , int len );
@@ -63,8 +61,7 @@ static ID id_read, id_write, id_binmode;
63
61
64
62
static VALUE kdtree_alloc (VALUE klass ) {
65
63
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 );
68
65
kdtreep -> root = -1 ;
69
66
return obj ;
70
67
}
@@ -135,8 +132,7 @@ static VALUE kdtree_initialize(VALUE kdtree, VALUE arg) {
135
132
}
136
133
137
134
// 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 * ));
140
136
141
137
// read the nodes
142
138
kdtreep -> nodes = ALLOC_N (struct kdtree_node , kdtreep -> len );
@@ -160,8 +156,7 @@ static int comparey(const void *pa, const void *pb) {
160
156
return (a < b ) ? -1 : ((a > b ) ? 1 : 0 );
161
157
}
162
158
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 ) {
165
160
int (* compar )(const void * , const void * );
166
161
struct kdtree_node * m ;
167
162
int median ;
@@ -205,16 +200,15 @@ static VALUE kdtree_nearest(VALUE kdtree, VALUE x, VALUE y) {
205
200
n_index = -1 ;
206
201
n_dist = INT_MAX ;
207
202
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 );
210
204
if (n_index == -1 ) {
211
205
return -1 ;
212
206
}
213
207
return INT2NUM ((kdtreep -> nodes + n_index )-> id );
214
208
}
215
209
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 ) {
218
212
struct kdtree_node * n ;
219
213
float ad ;
220
214
int near , far ;
@@ -297,8 +291,8 @@ static VALUE kdtree_nearestk(VALUE kdtree, VALUE x, VALUE y, VALUE k) {
297
291
} else if (ki > MAX_K ) {
298
292
ki = MAX_K ;
299
293
}
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 );
302
296
303
297
// convert result to ruby array
304
298
ary = rb_ary_new ();
@@ -308,9 +302,8 @@ static VALUE kdtree_nearestk(VALUE kdtree, VALUE x, VALUE y, VALUE k) {
308
302
return ary ;
309
303
}
310
304
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 ) {
314
307
struct kdtree_node * n ;
315
308
float ad ;
316
309
int near , far ;
@@ -338,8 +331,7 @@ static void kdtree_nearestk0(struct kdtree_data *kdtreep, int i, float x,
338
331
}
339
332
kdtree_nearestk0 (kdtreep , near , x , y , k , depth + 1 , k_list , k_len , k_dist );
340
333
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 );
343
335
}
344
336
345
337
//
@@ -367,8 +359,7 @@ static void kdtree_nearestk0(struct kdtree_data *kdtreep, int i, float x,
367
359
// insert
368
360
//
369
361
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 ));
372
363
k_list [lo ].index = i ;
373
364
k_list [lo ].distance = d ;
374
365
@@ -422,8 +413,7 @@ static VALUE kdtree_persist(VALUE kdtree, VALUE io) {
422
413
}
423
414
424
415
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 * ));
427
417
write_all (io , kdtreep -> nodes , sizeof (struct kdtree_node ) * kdtreep -> len );
428
418
return io ;
429
419
}
@@ -438,8 +428,7 @@ static VALUE kdtree_to_s(VALUE kdtree) {
438
428
char buf [256 ];
439
429
KDTREEP ;
440
430
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 );
443
432
return rb_str_new (buf , strlen (buf ));
444
433
}
445
434
0 commit comments