librtree 0.9.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +80 -0
- data/COPYING +21 -0
- data/README.md +87 -0
- data/ext/rtree/extconf.rb +37 -19
- data/ext/rtree/lib/README.md +9 -0
- data/ext/rtree/lib/bindex.c +157 -0
- data/ext/rtree/lib/bindex.h +31 -0
- data/ext/rtree/lib/bounds.h +21 -0
- data/ext/rtree/lib/branch.c +51 -0
- data/ext/rtree/lib/branches.c +17 -0
- data/ext/rtree/lib/bsrt.c +704 -0
- data/ext/rtree/lib/bsrt.h +16 -0
- data/ext/rtree/lib/constants.h +19 -0
- data/ext/rtree/lib/csv.c +81 -0
- data/ext/rtree/lib/csv.h +16 -0
- data/ext/rtree/lib/endianness.h +83 -0
- data/ext/rtree/lib/error.c +47 -0
- data/ext/rtree/lib/json.c +491 -0
- data/ext/rtree/lib/json.h +16 -0
- data/ext/rtree/lib/mk/Hdr.mk +3 -0
- data/ext/rtree/lib/mk/MakeDepend +25 -0
- data/ext/rtree/lib/mk/Obj.mk +3 -0
- data/ext/rtree/lib/node.c +736 -0
- data/ext/rtree/lib/package.c +11 -0
- data/ext/rtree/lib/page.c +47 -0
- data/ext/rtree/lib/page.h +13 -0
- data/ext/rtree/lib/postscript.c +543 -0
- data/ext/rtree/lib/rect.c +139 -0
- data/ext/rtree/lib/rectf.c +219 -0
- data/ext/rtree/lib/rtree/branch.h +105 -0
- data/ext/rtree/lib/rtree/branches.h +38 -0
- data/ext/rtree/lib/rtree/error.h +42 -0
- data/ext/rtree/lib/rtree/extent.h +20 -0
- data/ext/rtree/lib/rtree/node.h +96 -0
- data/ext/rtree/lib/rtree/package.h +14 -0
- data/ext/rtree/lib/rtree/postscript.h +66 -0
- data/ext/rtree/lib/rtree/rect.h +38 -0
- data/ext/rtree/lib/rtree/rectf.h +34 -0
- data/ext/rtree/lib/rtree/search.h +27 -0
- data/ext/rtree/lib/rtree/state.h +113 -0
- data/ext/rtree/lib/rtree/types.h +14 -0
- data/ext/rtree/lib/rtree-base.c +197 -0
- data/ext/rtree/lib/rtree.h +62 -0
- data/ext/rtree/lib/search.c +54 -0
- data/ext/rtree/lib/split.c +710 -0
- data/ext/rtree/lib/split.h +15 -0
- data/ext/rtree/lib/spvol.c +48 -0
- data/ext/rtree/lib/spvol.h +13 -0
- data/ext/rtree/lib/state.c +169 -0
- data/ext/rtree/rtree.c +11 -0
- data/lib/rtree.rb +4 -4
- metadata +65 -3
@@ -0,0 +1,48 @@
|
|
1
|
+
/* Autogenerated by spvol.py, do not edit */
|
2
|
+
|
3
|
+
#include "spvol.h"
|
4
|
+
|
5
|
+
int spvol(size_t dim, double *val)
|
6
|
+
{
|
7
|
+
static const double table[] = {
|
8
|
+
0x1.0000000000000p+1,
|
9
|
+
0x1.921fb54442d18p+1,
|
10
|
+
0x1.0c152382d7366p+2,
|
11
|
+
0x1.3bd3cc9be45dep+2,
|
12
|
+
0x1.50e1eb50f3976p+2,
|
13
|
+
0x1.4abbce625be53p+2,
|
14
|
+
0x1.2e6290cef4eedp+2,
|
15
|
+
0x1.03c1f081b5ac4p+2,
|
16
|
+
0x1.a6358a2b69ee8p+1,
|
17
|
+
0x1.466bc6775aae2p+1,
|
18
|
+
0x1.e254a1c03f10dp+0,
|
19
|
+
0x1.55d3c7e3cbffap+0,
|
20
|
+
0x1.d23deea12eccap-1,
|
21
|
+
0x1.32d2cce62bd86p-1,
|
22
|
+
0x1.86991141a8ff6p-2,
|
23
|
+
0x1.e1f506891babbp-3,
|
24
|
+
0x1.20bab3dc8101bp-3,
|
25
|
+
0x1.50783487ee782p-4,
|
26
|
+
0x1.7dec9576c3b57p-5,
|
27
|
+
0x1.a6d1f2a204a8cp-6,
|
28
|
+
0x1.c915f468284fep-7,
|
29
|
+
0x1.e3074fde8871fp-8,
|
30
|
+
0x1.f378691d9b076p-9,
|
31
|
+
0x1.f9d38a3763cc3p-10,
|
32
|
+
0x1.f61f536576352p-11,
|
33
|
+
0x1.e8f434d018d63p-12,
|
34
|
+
0x1.d3658f946c006p-13,
|
35
|
+
0x1.b6e24f44b128fp-14,
|
36
|
+
0x1.95114f4a6c2b5p-15,
|
37
|
+
0x1.6fadb9f155744p-16,
|
38
|
+
0x1.4866e45924c72p-17,
|
39
|
+
0x1.20c62c2f2d7f5p-18,
|
40
|
+
};
|
41
|
+
static const size_t table_size = sizeof(table) / sizeof(double);
|
42
|
+
if (dim < 1) return 1;
|
43
|
+
size_t n = dim - 1;
|
44
|
+
if (n >= table_size) return 1;
|
45
|
+
*val = table[n];
|
46
|
+
return 0;
|
47
|
+
}
|
48
|
+
|
@@ -0,0 +1,169 @@
|
|
1
|
+
#ifdef HAVE_CONFIG_H
|
2
|
+
#include "config.h"
|
3
|
+
#endif
|
4
|
+
|
5
|
+
#include "rtree/state.h"
|
6
|
+
#include "rtree/branch.h"
|
7
|
+
#include "rtree/node.h"
|
8
|
+
|
9
|
+
#include "page.h"
|
10
|
+
#include "constants.h"
|
11
|
+
#include "spvol.h"
|
12
|
+
|
13
|
+
#include <errno.h>
|
14
|
+
#include <string.h>
|
15
|
+
|
16
|
+
#ifdef HAVE_TGMATH_H
|
17
|
+
#include <tgmath.h>
|
18
|
+
#else
|
19
|
+
#include <math.h>
|
20
|
+
#endif
|
21
|
+
|
22
|
+
#ifdef HAVE_UNISTD_H
|
23
|
+
#include <unistd.h>
|
24
|
+
#endif
|
25
|
+
|
26
|
+
|
27
|
+
#define SPLIT_MASK ((1 << 2) - 1)
|
28
|
+
#define SPLIT_SHIFT 0
|
29
|
+
|
30
|
+
static state_flags_t flags_split(state_flags_t flags)
|
31
|
+
{
|
32
|
+
return (flags << SPLIT_SHIFT) & SPLIT_MASK;
|
33
|
+
}
|
34
|
+
|
35
|
+
state_flags_t state_split(const state_t *state)
|
36
|
+
{
|
37
|
+
return flags_split(state->flags);
|
38
|
+
}
|
39
|
+
|
40
|
+
#define NODE_PAGE_MASK ((1 << 8) - 1)
|
41
|
+
#define NODE_PAGE_SHIFT 2
|
42
|
+
|
43
|
+
static state_flags_t flags_node_page(state_flags_t flags)
|
44
|
+
{
|
45
|
+
return (flags >> NODE_PAGE_SHIFT) & NODE_PAGE_MASK;
|
46
|
+
}
|
47
|
+
|
48
|
+
state_flags_t state_node_page(const state_t *state)
|
49
|
+
{
|
50
|
+
return flags_node_page(state->flags);
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
For dim 2 with floats and 4K page-size we find that a node-page
|
55
|
+
of 8 gives reasonable performance; here we guess a formula which
|
56
|
+
scales the way you would expect and choose the parameter 64 so that
|
57
|
+
it gives 8 in the dim 2 float case. No doubt one could do better
|
58
|
+
with a case-by-case optimisation, but there are a lot of cases to
|
59
|
+
consider, look at that later ...
|
60
|
+
*/
|
61
|
+
|
62
|
+
static size_t node_page_default(size_t dims, size_t npg, size_t psz)
|
63
|
+
{
|
64
|
+
if (npg != 0) return npg;
|
65
|
+
size_t guess = psz / (dims * SIZEOF_RTREE_COORD_T * 64);
|
66
|
+
return guess ? guess : 1;
|
67
|
+
}
|
68
|
+
|
69
|
+
state_t* state_new(size_t dims, state_flags_t flags)
|
70
|
+
{
|
71
|
+
if (dims == 0)
|
72
|
+
{
|
73
|
+
errno = EDOM;
|
74
|
+
return NULL;
|
75
|
+
}
|
76
|
+
|
77
|
+
size_t psz;
|
78
|
+
|
79
|
+
if (page_size(&psz) != 0)
|
80
|
+
return NULL;
|
81
|
+
|
82
|
+
const size_t
|
83
|
+
npg = node_page_default(dims, flags_node_page(flags), psz),
|
84
|
+
nsz = psz / npg,
|
85
|
+
bsz = branch_sizeof(2 * dims),
|
86
|
+
factor = node_num_branch(nsz, bsz);
|
87
|
+
|
88
|
+
if (factor < 2)
|
89
|
+
{
|
90
|
+
errno = EINVAL;
|
91
|
+
return NULL;
|
92
|
+
}
|
93
|
+
|
94
|
+
double volume;
|
95
|
+
|
96
|
+
if (spvol(dims, &volume) != 0)
|
97
|
+
{
|
98
|
+
errno = EDOM;
|
99
|
+
return NULL;
|
100
|
+
}
|
101
|
+
|
102
|
+
state_t *state = malloc(sizeof(state_t));
|
103
|
+
|
104
|
+
if (state == NULL)
|
105
|
+
{
|
106
|
+
errno = ENOMEM;
|
107
|
+
return NULL;
|
108
|
+
}
|
109
|
+
|
110
|
+
state->dims = dims;
|
111
|
+
state->factor = factor;
|
112
|
+
state->size.page = psz;
|
113
|
+
state->size.branch = bsz;
|
114
|
+
state->size.node = nsz;
|
115
|
+
state->volume = volume;
|
116
|
+
state->flags = flags;
|
117
|
+
state->rectf.spherical_volume = rectf_spherical_volume(dims);
|
118
|
+
state->rectf.combine = rectf_combine(dims);
|
119
|
+
|
120
|
+
return state;
|
121
|
+
}
|
122
|
+
|
123
|
+
state_t* state_clone(const state_t *src)
|
124
|
+
{
|
125
|
+
state_t *dest;
|
126
|
+
|
127
|
+
if ((dest = malloc(sizeof(state_t))) != NULL)
|
128
|
+
{
|
129
|
+
memcpy(dest, src, sizeof(state_t));
|
130
|
+
return dest;
|
131
|
+
}
|
132
|
+
|
133
|
+
errno = ENOMEM;
|
134
|
+
return NULL;
|
135
|
+
}
|
136
|
+
|
137
|
+
void state_destroy(state_t *state)
|
138
|
+
{
|
139
|
+
free(state);
|
140
|
+
}
|
141
|
+
|
142
|
+
bool state_identical(const state_t *a, const state_t *b)
|
143
|
+
{
|
144
|
+
if (a && b)
|
145
|
+
{
|
146
|
+
return
|
147
|
+
(state_dims(a) == state_dims(b)) &&
|
148
|
+
(state_page_size(a) == state_page_size(b)) &&
|
149
|
+
(state_node_size(a) == state_node_size(b)) &&
|
150
|
+
(state_rect_size(a) == state_rect_size(b)) &&
|
151
|
+
(state_branching_factor(a) == state_branching_factor(b));
|
152
|
+
}
|
153
|
+
|
154
|
+
return ! (a || b);
|
155
|
+
}
|
156
|
+
|
157
|
+
extern size_t state_dims(const state_t*);
|
158
|
+
extern size_t state_page_size(const state_t*);
|
159
|
+
extern size_t state_node_size(const state_t*);
|
160
|
+
extern size_t state_rect_size(const state_t*);
|
161
|
+
extern size_t state_branch_size(const state_t*);
|
162
|
+
extern size_t state_branching_factor(const state_t*);
|
163
|
+
extern double state_unit_sphere_volume(const state_t*);
|
164
|
+
extern size_t state_bytes(const state_t*);
|
165
|
+
extern rtree_coord_t state_rsv(const state_t*, const rtree_coord_t*);
|
166
|
+
extern void state_rc(const state_t*,
|
167
|
+
const rtree_coord_t*,
|
168
|
+
const rtree_coord_t*,
|
169
|
+
rtree_coord_t*);
|
data/ext/rtree/rtree.c
CHANGED
@@ -55,6 +55,16 @@ static VALUE rt_release(VALUE self)
|
|
55
55
|
return self;
|
56
56
|
}
|
57
57
|
|
58
|
+
static VALUE rt_empty(VALUE self)
|
59
|
+
{
|
60
|
+
rtree_t *rtree;
|
61
|
+
TypedData_Get_Struct(self, rtree_t, &rtree_type, rtree);
|
62
|
+
if (rtree_empty(rtree))
|
63
|
+
return Qtrue;
|
64
|
+
else
|
65
|
+
return Qfalse;
|
66
|
+
}
|
67
|
+
|
58
68
|
static VALUE rt_height(VALUE self)
|
59
69
|
{
|
60
70
|
rtree_t *rtree;
|
@@ -505,6 +515,7 @@ void Init_rtree(void)
|
|
505
515
|
rb_define_method(cRTreeBase, "free", rt_release, 0);
|
506
516
|
rb_define_method(cRTreeBase, "clone", rt_clone, 0);
|
507
517
|
rb_define_method(cRTreeBase, "update!", rt_update, 0);
|
518
|
+
rb_define_method(cRTreeBase, "empty?", rt_empty, 0);
|
508
519
|
rb_define_method(cRTreeBase, "height", rt_height, 0);
|
509
520
|
rb_define_method(cRTreeBase, "add_rect", rt_add_rect, 2);
|
510
521
|
rb_define_method(cRTreeBase, "search", rt_search, 1);
|
data/lib/rtree.rb
CHANGED
@@ -14,9 +14,9 @@ require 'fcntl'
|
|
14
14
|
|
15
15
|
# @author RTree J. J. Green
|
16
16
|
#
|
17
|
-
# A Ruby
|
18
|
-
#
|
19
|
-
#
|
17
|
+
# A Ruby native extension implementing the R-tree spatial index of
|
18
|
+
# Guttman-Green. The code is an emebded version of
|
19
|
+
# {http://soliton.vm.bytemark.co.uk/pub/jjg/en/code/librtree librtree}.
|
20
20
|
#
|
21
21
|
# Use
|
22
22
|
#
|
@@ -355,7 +355,7 @@ class RTree < RTreeBase
|
|
355
355
|
# @return [Boolean] true if the RTree is empty
|
356
356
|
#
|
357
357
|
def empty?
|
358
|
-
|
358
|
+
super
|
359
359
|
end
|
360
360
|
|
361
361
|
# Serialise to JSON stream
|
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.
|
4
|
+
version: 1.0.1
|
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: 2023-
|
11
|
+
date: 2023-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.22'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.22'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: yard
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,7 +117,55 @@ extensions:
|
|
103
117
|
- ext/rtree/extconf.rb
|
104
118
|
extra_rdoc_files: []
|
105
119
|
files:
|
120
|
+
- CHANGELOG.md
|
121
|
+
- COPYING
|
122
|
+
- README.md
|
106
123
|
- ext/rtree/extconf.rb
|
124
|
+
- ext/rtree/lib/README.md
|
125
|
+
- ext/rtree/lib/bindex.c
|
126
|
+
- ext/rtree/lib/bindex.h
|
127
|
+
- ext/rtree/lib/bounds.h
|
128
|
+
- ext/rtree/lib/branch.c
|
129
|
+
- ext/rtree/lib/branches.c
|
130
|
+
- ext/rtree/lib/bsrt.c
|
131
|
+
- ext/rtree/lib/bsrt.h
|
132
|
+
- ext/rtree/lib/constants.h
|
133
|
+
- ext/rtree/lib/csv.c
|
134
|
+
- ext/rtree/lib/csv.h
|
135
|
+
- ext/rtree/lib/endianness.h
|
136
|
+
- ext/rtree/lib/error.c
|
137
|
+
- ext/rtree/lib/json.c
|
138
|
+
- ext/rtree/lib/json.h
|
139
|
+
- ext/rtree/lib/mk/Hdr.mk
|
140
|
+
- ext/rtree/lib/mk/MakeDepend
|
141
|
+
- ext/rtree/lib/mk/Obj.mk
|
142
|
+
- ext/rtree/lib/node.c
|
143
|
+
- ext/rtree/lib/package.c
|
144
|
+
- ext/rtree/lib/page.c
|
145
|
+
- ext/rtree/lib/page.h
|
146
|
+
- ext/rtree/lib/postscript.c
|
147
|
+
- ext/rtree/lib/rect.c
|
148
|
+
- ext/rtree/lib/rectf.c
|
149
|
+
- ext/rtree/lib/rtree-base.c
|
150
|
+
- ext/rtree/lib/rtree.h
|
151
|
+
- ext/rtree/lib/rtree/branch.h
|
152
|
+
- ext/rtree/lib/rtree/branches.h
|
153
|
+
- ext/rtree/lib/rtree/error.h
|
154
|
+
- ext/rtree/lib/rtree/extent.h
|
155
|
+
- ext/rtree/lib/rtree/node.h
|
156
|
+
- ext/rtree/lib/rtree/package.h
|
157
|
+
- ext/rtree/lib/rtree/postscript.h
|
158
|
+
- ext/rtree/lib/rtree/rect.h
|
159
|
+
- ext/rtree/lib/rtree/rectf.h
|
160
|
+
- ext/rtree/lib/rtree/search.h
|
161
|
+
- ext/rtree/lib/rtree/state.h
|
162
|
+
- ext/rtree/lib/rtree/types.h
|
163
|
+
- ext/rtree/lib/search.c
|
164
|
+
- ext/rtree/lib/split.c
|
165
|
+
- ext/rtree/lib/split.h
|
166
|
+
- ext/rtree/lib/spvol.c
|
167
|
+
- ext/rtree/lib/spvol.h
|
168
|
+
- ext/rtree/lib/state.c
|
107
169
|
- ext/rtree/rtree.c
|
108
170
|
- lib/rtree.rb
|
109
171
|
homepage: https://gitlab.com/jjg/librtree-ruby
|
@@ -126,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
188
|
- !ruby/object:Gem::Version
|
127
189
|
version: '0'
|
128
190
|
requirements:
|
129
|
-
- The
|
191
|
+
- The Jansson library
|
130
192
|
rubygems_version: 3.1.6
|
131
193
|
signing_key:
|
132
194
|
specification_version: 4
|