librtree 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/rtree/rtree.c +70 -29
- data/lib/rtree.rb +25 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 636adac7b1df4b79407c5d7402aa101d4362379dc7c325e7283c81eb2faeb94e
|
4
|
+
data.tar.gz: ee8da51ba25d5e5648ee9b511a0507beb0b1bb5325b1c5dcfbb499e01cf9fb77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6a7c7d731a9d09caf84e9e9c1b7133cdbadad297efe09af3875f5f97352740c7c9786c6ceb3c74665110b2b248b2c59ab712b9e3bb3b8e195e946745648f840
|
7
|
+
data.tar.gz: 2be108c80ff14fc3d2d5ba0ebead91a07e0a537d8a7a4ded460fdec4645ff41eb3412a765d02edc3d7fff87dc04b9dc7c2d0af4516b70e14464e51c556f379f9
|
data/ext/rtree/rtree.c
CHANGED
@@ -1,26 +1,48 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include <ruby/io.h>
|
3
|
+
#include <ruby/version.h>
|
3
4
|
|
4
5
|
#include <rtree.h>
|
6
|
+
#include <rtree/package.h>
|
5
7
|
|
6
8
|
#include <errno.h>
|
7
9
|
#include <stdint.h>
|
8
10
|
|
9
|
-
|
11
|
+
|
12
|
+
static void lrt_dfree(void *p)
|
10
13
|
{
|
11
|
-
rtree_t
|
12
|
-
|
14
|
+
rtree_destroy((rtree_t*)p);
|
15
|
+
}
|
16
|
+
|
17
|
+
static size_t lrt_dsize(const void *p)
|
18
|
+
{
|
19
|
+
return rtree_bytes((const rtree_t*)p);
|
13
20
|
}
|
14
21
|
|
22
|
+
static rb_data_type_t type = {
|
23
|
+
.wrap_struct_name = "rtree-wrap",
|
24
|
+
.function = {
|
25
|
+
.dmark = NULL,
|
26
|
+
.dfree = lrt_dfree,
|
27
|
+
.dsize = lrt_dsize,
|
28
|
+
#if RUBY_API_VERSION_CODE < 20700
|
29
|
+
.reserved = { NULL, NULL }
|
30
|
+
#else
|
31
|
+
.dcompact = NULL,
|
32
|
+
.reserved = { NULL }
|
33
|
+
#endif
|
34
|
+
},
|
35
|
+
.parent = NULL,
|
36
|
+
.data = NULL,
|
37
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
38
|
+
};
|
39
|
+
|
15
40
|
static VALUE lrt_alloc(VALUE cls)
|
16
41
|
{
|
17
42
|
rtree_t *rtree;;
|
18
|
-
|
19
43
|
if ((rtree = rtree_alloc()) == NULL)
|
20
44
|
rb_raise(rb_eNoMemError, "failed to alloc rtree");
|
21
|
-
|
22
|
-
VALUE obj = Data_Wrap_Struct(cls, NULL, lrt_free, rtree);
|
23
|
-
return obj;
|
45
|
+
return TypedData_Wrap_Struct(cls, &type, rtree);
|
24
46
|
}
|
25
47
|
|
26
48
|
static VALUE lrt_init(VALUE self, VALUE dim_obj, VALUE flags_obj)
|
@@ -32,7 +54,7 @@ static VALUE lrt_init(VALUE self, VALUE dim_obj, VALUE flags_obj)
|
|
32
54
|
state_flags_t flags = FIX2UINT(flags_obj);
|
33
55
|
|
34
56
|
rtree_t *rtree;
|
35
|
-
|
57
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
36
58
|
|
37
59
|
if ((rtree_init(rtree, dim, flags)) != 0)
|
38
60
|
rb_raise(rb_eNoMemError, "failed to init rtree");
|
@@ -43,7 +65,7 @@ static VALUE lrt_init(VALUE self, VALUE dim_obj, VALUE flags_obj)
|
|
43
65
|
static VALUE lrt_release(VALUE self)
|
44
66
|
{
|
45
67
|
rtree_t *rtree;
|
46
|
-
|
68
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
47
69
|
rtree_destroy(rtree);
|
48
70
|
return self;
|
49
71
|
}
|
@@ -51,7 +73,7 @@ static VALUE lrt_release(VALUE self)
|
|
51
73
|
static VALUE lrt_height(VALUE self)
|
52
74
|
{
|
53
75
|
rtree_t *rtree;
|
54
|
-
|
76
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
55
77
|
return INT2NUM(rtree_height(rtree));
|
56
78
|
}
|
57
79
|
|
@@ -61,7 +83,7 @@ static VALUE lrt_add_rect(VALUE self, VALUE id_obj, VALUE coord_obj)
|
|
61
83
|
Check_Type(id_obj, T_FIXNUM);
|
62
84
|
|
63
85
|
rtree_t *rtree;
|
64
|
-
|
86
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
65
87
|
|
66
88
|
rtree_id_t
|
67
89
|
id = FIX2ULONG(id_obj);
|
@@ -119,7 +141,7 @@ static VALUE lrt_update(VALUE self)
|
|
119
141
|
rb_raise(rb_eArgError, "Expected block");
|
120
142
|
|
121
143
|
rtree_t *rtree;
|
122
|
-
|
144
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
123
145
|
|
124
146
|
size_t len = 2 * state_dims(rtree->state);
|
125
147
|
int err = rtree_update(rtree, update_cb, &len);
|
@@ -155,7 +177,7 @@ static VALUE lrt_search(VALUE self, VALUE coord_obj)
|
|
155
177
|
Check_Type(coord_obj, T_ARRAY);
|
156
178
|
|
157
179
|
rtree_t *rtree;
|
158
|
-
|
180
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
159
181
|
|
160
182
|
size_t
|
161
183
|
len = RARRAY_LEN(coord_obj),
|
@@ -198,9 +220,7 @@ static VALUE deserialise(VALUE cls, VALUE io_obj, deserialise_t *f)
|
|
198
220
|
rb_raise(rb_eRuntimeError, "Failed read from stream");
|
199
221
|
}
|
200
222
|
|
201
|
-
|
202
|
-
|
203
|
-
return obj;
|
223
|
+
return TypedData_Wrap_Struct(cls, &type, rtree);
|
204
224
|
}
|
205
225
|
|
206
226
|
static VALUE lrt_json_read(VALUE cls, VALUE io_obj)
|
@@ -239,9 +259,7 @@ static VALUE lrt_csv_read(VALUE cls,
|
|
239
259
|
rb_raise(rb_eRuntimeError, "Failed read from stream");
|
240
260
|
}
|
241
261
|
|
242
|
-
|
243
|
-
|
244
|
-
return obj;
|
262
|
+
return TypedData_Wrap_Struct(cls, &type, rtree);
|
245
263
|
}
|
246
264
|
|
247
265
|
/* serialisation */
|
@@ -259,7 +277,7 @@ static VALUE serialise(VALUE self, VALUE io_obj, serialise_t *f)
|
|
259
277
|
FILE *fp = rb_io_stdio_file(io);
|
260
278
|
|
261
279
|
rtree_t *rtree;
|
262
|
-
|
280
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
263
281
|
|
264
282
|
int err = f(rtree, fp);
|
265
283
|
if (err != 0)
|
@@ -282,8 +300,8 @@ static VALUE lrt_identical(VALUE self, VALUE other)
|
|
282
300
|
{
|
283
301
|
rtree_t *rtree_self, *rtree_other;
|
284
302
|
|
285
|
-
|
286
|
-
|
303
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree_self);
|
304
|
+
TypedData_Get_Struct(other, rtree_t, &type, rtree_other);
|
287
305
|
|
288
306
|
if (rtree_identical(rtree_self, rtree_other))
|
289
307
|
return Qtrue;
|
@@ -294,7 +312,7 @@ static VALUE lrt_identical(VALUE self, VALUE other)
|
|
294
312
|
static VALUE lrt_clone(VALUE self)
|
295
313
|
{
|
296
314
|
rtree_t *rtree;
|
297
|
-
|
315
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
298
316
|
|
299
317
|
rtree_t *clone;
|
300
318
|
errno = 0;
|
@@ -306,16 +324,13 @@ static VALUE lrt_clone(VALUE self)
|
|
306
324
|
rb_raise(rb_eRuntimeError, "Failed clone");
|
307
325
|
}
|
308
326
|
|
309
|
-
|
310
|
-
VALUE obj = Data_Wrap_Struct(cls, NULL, lrt_free, clone);
|
311
|
-
|
312
|
-
return obj;
|
327
|
+
return TypedData_Wrap_Struct(CLASS_OF(self), &type, clone);
|
313
328
|
}
|
314
329
|
|
315
330
|
static VALUE state_size_access(VALUE self, size_t (*f)(const state_t*))
|
316
331
|
{
|
317
332
|
rtree_t *rtree;
|
318
|
-
|
333
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
319
334
|
return INT2NUM(f(rtree->state));
|
320
335
|
}
|
321
336
|
|
@@ -352,10 +367,32 @@ static VALUE lrt_branching_factor(VALUE self)
|
|
352
367
|
static VALUE lrt_unit_sphere_volume(VALUE self)
|
353
368
|
{
|
354
369
|
rtree_t *rtree;
|
355
|
-
|
370
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
356
371
|
return DBL2NUM(state_unit_sphere_volume(rtree->state));
|
357
372
|
}
|
358
373
|
|
374
|
+
static VALUE lrt_size(VALUE self)
|
375
|
+
{
|
376
|
+
rtree_t *rtree;
|
377
|
+
TypedData_Get_Struct(self, rtree_t, &type, rtree);
|
378
|
+
return INT2NUM(rtree_bytes(rtree));
|
379
|
+
}
|
380
|
+
|
381
|
+
static VALUE lrt_version(VALUE self)
|
382
|
+
{
|
383
|
+
return rb_str_new_cstr(rtree_package_version);
|
384
|
+
}
|
385
|
+
|
386
|
+
static VALUE lrt_bugreport(VALUE self)
|
387
|
+
{
|
388
|
+
return rb_str_new_cstr(rtree_package_bugreport);
|
389
|
+
}
|
390
|
+
|
391
|
+
static VALUE lrt_url(VALUE self)
|
392
|
+
{
|
393
|
+
return rb_str_new_cstr(rtree_package_url);
|
394
|
+
}
|
395
|
+
|
359
396
|
void Init_rtree(void)
|
360
397
|
{
|
361
398
|
VALUE cls = rb_const_get(rb_cObject, rb_intern("RTreeC"));
|
@@ -372,12 +409,16 @@ void Init_rtree(void)
|
|
372
409
|
rb_define_method(cls, "bsrt_write", lrt_bsrt_write, 1);
|
373
410
|
rb_define_method(cls, "eq?", lrt_identical, 1);
|
374
411
|
rb_define_method(cls, "dim", lrt_dim, 0);
|
412
|
+
rb_define_method(cls, "size", lrt_size, 0);
|
375
413
|
rb_define_method(cls, "page_size", lrt_page_size, 0);
|
376
414
|
rb_define_method(cls, "node_size", lrt_node_size, 0);
|
377
415
|
rb_define_method(cls, "rect_size", lrt_rect_size, 0);
|
378
416
|
rb_define_method(cls, "branch_size", lrt_branch_size, 0);
|
379
417
|
rb_define_method(cls, "branching_factor", lrt_branching_factor, 0);
|
380
418
|
rb_define_method(cls, "unit_sphere_volume", lrt_unit_sphere_volume, 0);
|
419
|
+
rb_define_singleton_method(cls, "version", lrt_version, 0);
|
420
|
+
rb_define_singleton_method(cls, "bugreport", lrt_bugreport, 0);
|
421
|
+
rb_define_singleton_method(cls, "url", lrt_url, 0);
|
381
422
|
rb_define_singleton_method(cls, "json_read", lrt_json_read, 1);
|
382
423
|
rb_define_singleton_method(cls, "bsrt_read", lrt_bsrt_read, 1);
|
383
424
|
rb_define_singleton_method(cls, "csv_read", lrt_csv_read, 3);
|
data/lib/rtree.rb
CHANGED
@@ -120,6 +120,21 @@ class RTree < RTreeC
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
+
# @return [Array<Integer>] version of librtree
|
124
|
+
def version
|
125
|
+
@version ||= super.split('.').map(&:to_i)
|
126
|
+
end
|
127
|
+
|
128
|
+
# @return [String] email address for librtree bug reports
|
129
|
+
def bugreport
|
130
|
+
super
|
131
|
+
end
|
132
|
+
|
133
|
+
# @return [String] librtree homepage
|
134
|
+
def url
|
135
|
+
super
|
136
|
+
end
|
137
|
+
|
123
138
|
# @!visibility private
|
124
139
|
def split_flag(split)
|
125
140
|
case split
|
@@ -307,6 +322,16 @@ class RTree < RTreeC
|
|
307
322
|
super
|
308
323
|
end
|
309
324
|
|
325
|
+
# @return [Integer] the total bytes allocated for the instance
|
326
|
+
# @note This method traverses the entire tree summing the
|
327
|
+
# contributions for each node (rather than maintaining a
|
328
|
+
# running count). Performance-minded users may wish to
|
329
|
+
# cache this value (invalidating the cache when calling
|
330
|
+
# {#add_rect} of course).
|
331
|
+
def size
|
332
|
+
super
|
333
|
+
end
|
334
|
+
|
310
335
|
# @return [Integer] the bytes in a page of memory
|
311
336
|
def page_size
|
312
337
|
super
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: librtree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J.J. Green
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
- !ruby/object:Gem::Version
|
127
127
|
version: '0'
|
128
128
|
requirements:
|
129
|
-
- The librtree library (1.0.
|
129
|
+
- The librtree library (1.0.3 or later)
|
130
130
|
rubygems_version: 3.1.2
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|