librtree 1.0.4 → 1.0.5
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/CHANGELOG.md +5 -0
- data/ext/rtree/lib/bindex.c +16 -0
- data/ext/rtree/lib/error.c +1 -1
- data/ext/rtree/lib/mk/Hdr.mk +9 -3
- data/ext/rtree/lib/package.c +1 -1
- data/ext/rtree/lib/postscript.c +1 -0
- data/ext/rtree/rtree.c +9 -10
- data/lib/rtree.rb +62 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b945bd1abd981557382119ef56ebde1c6bd1f3e75dfa0ca4656b43a59c99d833
|
4
|
+
data.tar.gz: 9af9d2d1317582970d0b27fd43c2947472d66be2383f29bdb7f3d8d19743a897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 752765087a236c6ae456475af539ffafb72f02ba13521ff75c094e997c367b717f6d3166e97146a9bc45f2b58581ec6b292aea1faaababf18e6f57d2b8cbc705
|
7
|
+
data.tar.gz: 6aa633e4d38ca15f6a4dc6392870cb0ec8d3713bb15b53a9142b06a00a8e7d295eb5a5f57494eb72cdfdf2b9f8098b86e4703f310a9b3382b39d47df971f29d0
|
data/CHANGELOG.md
CHANGED
data/ext/rtree/lib/bindex.c
CHANGED
@@ -20,6 +20,22 @@
|
|
20
20
|
#define UL_BYTES sizeof(unsigned long)
|
21
21
|
#define UL_BITS (UL_BYTES << 3)
|
22
22
|
|
23
|
+
/*
|
24
|
+
config.h may contain HAVE___BUILTIN_CTZL defined from an autoconf
|
25
|
+
check (for the standalone C library, there will be such a check),
|
26
|
+
but in the embedded case, performing that check may be tricky, so
|
27
|
+
in that case we fall-back onto the __has_builtin macro which has
|
28
|
+
been present in clang for many years, and in gcc since version 10.
|
29
|
+
*/
|
30
|
+
|
31
|
+
#ifndef HAVE___BUILTIN_CTZL
|
32
|
+
#ifdef __has_builtin
|
33
|
+
#if __has_builtin(__builtin_ctzl)
|
34
|
+
#define HAVE___BUILTIN_CTZL 1
|
35
|
+
#endif
|
36
|
+
#endif
|
37
|
+
#endif
|
38
|
+
|
23
39
|
/* see note on branch_sizeof in branch.c */
|
24
40
|
|
25
41
|
static size_t bindex_sizeof(size_t n)
|
data/ext/rtree/lib/error.c
CHANGED
@@ -23,7 +23,7 @@ const char* strerror_rtree(int err)
|
|
23
23
|
{ RTREE_ERR_NOCSV, "Compiled without CSV support" },
|
24
24
|
{ RTREE_ERR_JANSSON, "Error from the Jansson library" },
|
25
25
|
{ RTREE_ERR_NOJSON, "Compiled without JSON support" },
|
26
|
-
{
|
26
|
+
{ RTREE_ERR_NOBSRT, "Compiled without BSRT support" },
|
27
27
|
{ RTREE_ERR_GETBRANCH, "Error getting branch" },
|
28
28
|
{ RTREE_ERR_GETCHILD, "Error getting child node" },
|
29
29
|
{ RTREE_ERR_NODECLONE, "Error cloning node" },
|
data/ext/rtree/lib/mk/Hdr.mk
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
-
HDR := rtree
|
2
|
-
rtree/
|
3
|
-
rtree/
|
1
|
+
HDR := rtree.h \
|
2
|
+
rtree/error.h \
|
3
|
+
rtree/extent.h \
|
4
|
+
rtree/node.h \
|
5
|
+
rtree/package.h \
|
6
|
+
rtree/postscript.h \
|
7
|
+
rtree/search.h \
|
8
|
+
rtree/state.h \
|
9
|
+
rtree/types.h
|
data/ext/rtree/lib/package.c
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
#include "rtree/package.h"
|
7
7
|
|
8
|
-
const char rtree_package_version[] = "1.3.
|
8
|
+
const char rtree_package_version[] = "1.3.1";
|
9
9
|
const char rtree_package_name[] = "librtree";
|
10
10
|
const char rtree_package_url[] = "https://gitlab.com/jjg/librtree";
|
11
11
|
const char rtree_package_bugreport[] = "j.j.green@gmx.co.uk";
|
data/ext/rtree/lib/postscript.c
CHANGED
data/ext/rtree/rtree.c
CHANGED
@@ -35,7 +35,7 @@ static VALUE rt_init(VALUE self, VALUE dim_obj, VALUE flags_obj)
|
|
35
35
|
Check_Type(dim_obj, T_FIXNUM);
|
36
36
|
size_t dim = FIX2ULONG(dim_obj);
|
37
37
|
|
38
|
-
Check_Type(
|
38
|
+
Check_Type(flags_obj, T_FIXNUM);
|
39
39
|
state_flags_t flags = FIX2UINT(flags_obj);
|
40
40
|
|
41
41
|
rtree_t *rtree;
|
@@ -241,7 +241,7 @@ static VALUE rt_csv_read(VALUE cls,
|
|
241
241
|
Check_Type(dim_obj, T_FIXNUM);
|
242
242
|
size_t dim = FIX2ULONG(dim_obj);
|
243
243
|
|
244
|
-
Check_Type(
|
244
|
+
Check_Type(flags_obj, T_FIXNUM);
|
245
245
|
state_flags_t flags = FIX2UINT(flags_obj);
|
246
246
|
|
247
247
|
rtree_t *rtree;
|
@@ -415,14 +415,13 @@ static VALUE rt_postscript(VALUE self,
|
|
415
415
|
Check_Type(axis_obj, T_FIXNUM);
|
416
416
|
extent_axis_t axis = FIX2UINT(axis_obj);
|
417
417
|
|
418
|
-
rtree_postscript_t opt =
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
};
|
418
|
+
rtree_postscript_t opt = {
|
419
|
+
.style = style,
|
420
|
+
.axis = axis,
|
421
|
+
.extent = extent,
|
422
|
+
.margin = margin,
|
423
|
+
.title = "librtree-ruby output"
|
424
|
+
};
|
426
425
|
|
427
426
|
int err;
|
428
427
|
if ((err = rtree_postscript(rtree, &opt, fp)) != 0)
|
data/lib/rtree.rb
CHANGED
@@ -15,7 +15,7 @@ require 'fcntl'
|
|
15
15
|
# @author RTree J. J. Green
|
16
16
|
#
|
17
17
|
# A Ruby native extension implementing the R-tree spatial index of
|
18
|
-
# Guttman-Green. The code is an
|
18
|
+
# Guttman-Green. The code is an embedded version of
|
19
19
|
# {http://soliton.vm.bytemark.co.uk/pub/jjg/en/code/librtree librtree}.
|
20
20
|
#
|
21
21
|
# Use
|
@@ -69,6 +69,21 @@ class RTree < RTreeBase
|
|
69
69
|
module IOUtil
|
70
70
|
extend self
|
71
71
|
|
72
|
+
# @!visibility private
|
73
|
+
#
|
74
|
+
def io_with_mode(arg, mode)
|
75
|
+
case arg
|
76
|
+
when String, Pathname
|
77
|
+
File.open(arg, mode) do |io|
|
78
|
+
yield io
|
79
|
+
end
|
80
|
+
when File, IO
|
81
|
+
yield arg
|
82
|
+
else
|
83
|
+
raise TypeError, arg
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
72
87
|
# @!visibility private
|
73
88
|
#
|
74
89
|
def deserialise(string, encoding)
|
@@ -138,15 +153,19 @@ class RTree < RTreeBase
|
|
138
153
|
|
139
154
|
class << self
|
140
155
|
|
141
|
-
# Create a new RTree instance from JSON stream
|
142
|
-
# @param
|
156
|
+
# Create a new RTree instance from JSON path or stream
|
157
|
+
# @param io_arg [String|IO] a path or readable stream
|
143
158
|
# @return [RTree] the newly instantiated RTree
|
144
159
|
# @see #json_write
|
145
|
-
# @example
|
160
|
+
# @example Using a path
|
161
|
+
# rtree = RTree.json_read('rtree.json')
|
162
|
+
# @example Using a stream
|
146
163
|
# rtree = File.open('rtree.json', 'r') { |io| RTree.json_read(io) }
|
147
164
|
#
|
148
|
-
def json_read(
|
149
|
-
|
165
|
+
def json_read(io_arg)
|
166
|
+
RTree::IOUtil.io_with_mode(io_arg, 'r') do |io|
|
167
|
+
super(io)
|
168
|
+
end
|
150
169
|
end
|
151
170
|
|
152
171
|
# Create a new RTree instance from JSON string
|
@@ -159,15 +178,17 @@ class RTree < RTreeBase
|
|
159
178
|
end
|
160
179
|
|
161
180
|
# Create a new RTree instance from BSRT (binary serialised R-tree)
|
162
|
-
# stream
|
163
|
-
# @param
|
181
|
+
# path or stream
|
182
|
+
# @param io_arg [String|IO] a path or readable stream
|
164
183
|
# @return [RTree] the newly instantiated RTree
|
165
184
|
# @see #bsrt_write
|
166
|
-
# @example Read from
|
167
|
-
# rtree =
|
185
|
+
# @example Read from path
|
186
|
+
# rtree = RTree.bsrt_read('rtree.bsrt')
|
168
187
|
#
|
169
|
-
def bsrt_read(
|
170
|
-
|
188
|
+
def bsrt_read(io_arg)
|
189
|
+
RTree::IOUtil.io_with_mode(io_arg, 'rb') do |io|
|
190
|
+
super(io)
|
191
|
+
end
|
171
192
|
end
|
172
193
|
|
173
194
|
# Create a new RTree instance from BSRT (binary serialised R-tree)
|
@@ -180,8 +201,8 @@ class RTree < RTreeBase
|
|
180
201
|
deserialise(bsrt, Encoding::BINARY) { |io| bsrt_read(io) }
|
181
202
|
end
|
182
203
|
|
183
|
-
# Build a new RTree instance from CSV stream
|
184
|
-
# @param
|
204
|
+
# Build a new RTree instance from CSV path or stream
|
205
|
+
# @param io_arg [String|IO] a path or readable stream
|
185
206
|
# @param dim [Integer] the dimension of the tree
|
186
207
|
# @param split [:linear, :quadratic, :greene] See {#initialize}
|
187
208
|
# @param node_page [Integer] See {#initialize}
|
@@ -192,9 +213,11 @@ class RTree < RTreeBase
|
|
192
213
|
# useful feature is the reason that the dimension is a required
|
193
214
|
# argument).
|
194
215
|
#
|
195
|
-
def csv_read(
|
216
|
+
def csv_read(io_arg, dim, split: :quadratic, node_page: 0)
|
196
217
|
flags = split_flag(split) | node_page_flag(node_page)
|
197
|
-
|
218
|
+
RTree::IOUtil.io_with_mode(io_arg, 'r') do |io|
|
219
|
+
super(io, dim, flags)
|
220
|
+
end
|
198
221
|
end
|
199
222
|
|
200
223
|
# Build a new RTree instance from CSV string
|
@@ -363,26 +386,28 @@ class RTree < RTreeBase
|
|
363
386
|
super
|
364
387
|
end
|
365
388
|
|
366
|
-
# Serialise to JSON
|
367
|
-
# @param
|
389
|
+
# Serialise to JSON
|
390
|
+
# @param io_arg [String|IO] a path or writable stream
|
368
391
|
# @return [self]
|
369
392
|
# @see .json_read
|
370
393
|
# @example Write to file
|
371
|
-
#
|
394
|
+
# rtree.json_write('rtree.json')
|
372
395
|
#
|
373
|
-
def json_write(
|
374
|
-
super
|
396
|
+
def json_write(io_arg)
|
397
|
+
RTree::IOUtil.io_with_mode(io_arg, 'w') { |io| super(io) }
|
398
|
+
self
|
375
399
|
end
|
376
400
|
|
377
|
-
# Serialise to BSRT (binary serialised R-tree)
|
378
|
-
# @param
|
401
|
+
# Serialise to BSRT (binary serialised R-tree)
|
402
|
+
# @param io_arg [String|IO] a path or writable stream
|
379
403
|
# @return [self]
|
380
404
|
# @see .bsrt_read
|
381
405
|
# @example Write to file
|
382
|
-
#
|
406
|
+
# rtree.bsrt_write('rtree.bsrt')
|
383
407
|
#
|
384
|
-
def bsrt_write(
|
385
|
-
super
|
408
|
+
def bsrt_write(io_arg)
|
409
|
+
RTree::IOUtil.io_with_mode(io_arg, 'wb') { |io| super(io) }
|
410
|
+
self
|
386
411
|
end
|
387
412
|
|
388
413
|
# Serialise to JSON string
|
@@ -476,7 +501,7 @@ class RTree < RTreeBase
|
|
476
501
|
|
477
502
|
# Create a PostScript plot of the RTree
|
478
503
|
#
|
479
|
-
# @param
|
504
|
+
# @param io_arg [String|IO] a path or writeable stream
|
480
505
|
# @param style [RTree::Style] a style object describing the fill
|
481
506
|
# colour and stroke width and colour for each level of the tree.
|
482
507
|
# @param height [Float] the height of the plot in units of PostScript
|
@@ -487,7 +512,7 @@ class RTree < RTreeBase
|
|
487
512
|
# @param margin [Float] extra space around the plot in units of
|
488
513
|
# PostScript point (1/72 inch), default zero
|
489
514
|
#
|
490
|
-
def postscript(
|
515
|
+
def postscript(io_arg, style, height: nil, width: nil, margin: 0)
|
491
516
|
if height && width then
|
492
517
|
raise ArgumentError, 'cannot specify both height and width'
|
493
518
|
end
|
@@ -498,7 +523,9 @@ class RTree < RTreeBase
|
|
498
523
|
axis = AXIS_WIDTH
|
499
524
|
extent = width || 216
|
500
525
|
end
|
501
|
-
|
526
|
+
RTree::IOUtil.io_with_mode(io_arg, 'w') do |io|
|
527
|
+
super(style, axis, extent, margin, io)
|
528
|
+
end
|
502
529
|
end
|
503
530
|
|
504
531
|
private
|
@@ -523,7 +550,7 @@ class RTree < RTreeBase
|
|
523
550
|
|
524
551
|
end
|
525
552
|
|
526
|
-
# @author RTree::Style J.
|
553
|
+
# @author RTree::Style J.J. Green
|
527
554
|
#
|
528
555
|
# A Ruby wrapper around RTree styles, used in PostScript plotting.
|
529
556
|
# in particular by {RTree#postscript}.
|
@@ -532,16 +559,14 @@ class RTree::Style < RTreeStyleBase
|
|
532
559
|
|
533
560
|
class << self
|
534
561
|
|
535
|
-
# Create a new Style instance from JSON stream
|
536
|
-
# @param
|
562
|
+
# Create a new Style instance from JSON path or stream
|
563
|
+
# @param io_arg [String|IO] a path or readable stream
|
537
564
|
# @return [RTree::Style] the newly instantiated Style
|
538
565
|
# @example Read from file
|
539
|
-
# style =
|
540
|
-
# RTree::Style.json_read(io)
|
541
|
-
# end
|
566
|
+
# style = RTree::Style.json_read('some.style')
|
542
567
|
#
|
543
|
-
def json_read(
|
544
|
-
super
|
568
|
+
def json_read(io_arg)
|
569
|
+
RTree::IOUtil.io_with_mode(io_arg, 'r') { |io| super(io) }
|
545
570
|
end
|
546
571
|
|
547
572
|
# Create a new Style instance from JSON string
|
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: 1.0.
|
4
|
+
version: 1.0.5
|
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:
|
11
|
+
date: 2024-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|