librtree 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +72 -0
- data/COPYING +21 -0
- data/README.md +86 -0
- data/ext/rtree/extconf.rb +43 -27
- 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 +708 -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 +92 -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 +190 -0
- data/ext/rtree/lib/rtree.h +61 -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 +2 -1
- data/lib/rtree.rb +1 -3
- metadata +51 -4
@@ -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
@@ -24,7 +24,7 @@ static size_t rt_dsize(const void *p)
|
|
24
24
|
|
25
25
|
static VALUE rt_alloc(VALUE cls)
|
26
26
|
{
|
27
|
-
rtree_t *rtree
|
27
|
+
rtree_t *rtree;
|
28
28
|
if ((rtree = rtree_alloc()) == NULL)
|
29
29
|
rb_raise(rb_eNoMemError, "failed to alloc rtree");
|
30
30
|
return TypedData_Wrap_Struct(cls, &rtree_type, rtree);
|
@@ -534,6 +534,7 @@ void Init_rtree(void)
|
|
534
534
|
|
535
535
|
VALUE cRTreeStyleBase = rb_const_get(rb_cObject, rb_intern("RTreeStyleBase"));
|
536
536
|
|
537
|
+
rb_undef_alloc_func(cRTreeStyleBase);
|
537
538
|
rb_define_method(cRTreeStyleBase, "free", st_release, 0);
|
538
539
|
rb_define_singleton_method(cRTreeStyleBase, "json_read", st_json_read, 1);
|
539
540
|
}
|
data/lib/rtree.rb
CHANGED
@@ -271,7 +271,7 @@ class RTree < RTreeBase
|
|
271
271
|
# @param node_page [Integer] the nodes-per-page value. This value can
|
272
272
|
# affect performance quite dramatically, particularly build time. A
|
273
273
|
# value which is too large would result in an infeasible branching
|
274
|
-
# factor for the R-tree and will
|
274
|
+
# factor for the R-tree and will cause the function to error with errno
|
275
275
|
# set to EINVAL. A value of zero is permitted and the default; in
|
276
276
|
# this case the function will choose a good value based on heuristics.
|
277
277
|
# You may get better performance for your use-case by manual
|
@@ -482,8 +482,6 @@ class RTree < RTreeBase
|
|
482
482
|
# @param margin [Float] extra space around the plot in units of
|
483
483
|
# PostScript point (1/72 inch), default zero
|
484
484
|
#
|
485
|
-
# rdoc-image:img/cb-bupu3.png
|
486
|
-
#
|
487
485
|
def postscript(io, style, height: nil, width: nil, margin: 0)
|
488
486
|
if height && width then
|
489
487
|
raise ArgumentError, 'cannot specify both height and width'
|
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.0
|
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: 2023-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,7 +103,54 @@ extensions:
|
|
103
103
|
- ext/rtree/extconf.rb
|
104
104
|
extra_rdoc_files: []
|
105
105
|
files:
|
106
|
+
- CHANGELOG.md
|
107
|
+
- COPYING
|
108
|
+
- README.md
|
106
109
|
- ext/rtree/extconf.rb
|
110
|
+
- ext/rtree/lib/bindex.c
|
111
|
+
- ext/rtree/lib/bindex.h
|
112
|
+
- ext/rtree/lib/bounds.h
|
113
|
+
- ext/rtree/lib/branch.c
|
114
|
+
- ext/rtree/lib/branches.c
|
115
|
+
- ext/rtree/lib/bsrt.c
|
116
|
+
- ext/rtree/lib/bsrt.h
|
117
|
+
- ext/rtree/lib/constants.h
|
118
|
+
- ext/rtree/lib/csv.c
|
119
|
+
- ext/rtree/lib/csv.h
|
120
|
+
- ext/rtree/lib/endianness.h
|
121
|
+
- ext/rtree/lib/error.c
|
122
|
+
- ext/rtree/lib/json.c
|
123
|
+
- ext/rtree/lib/json.h
|
124
|
+
- ext/rtree/lib/mk/Hdr.mk
|
125
|
+
- ext/rtree/lib/mk/MakeDepend
|
126
|
+
- ext/rtree/lib/mk/Obj.mk
|
127
|
+
- ext/rtree/lib/node.c
|
128
|
+
- ext/rtree/lib/package.c
|
129
|
+
- ext/rtree/lib/page.c
|
130
|
+
- ext/rtree/lib/page.h
|
131
|
+
- ext/rtree/lib/postscript.c
|
132
|
+
- ext/rtree/lib/rect.c
|
133
|
+
- ext/rtree/lib/rectf.c
|
134
|
+
- ext/rtree/lib/rtree-base.c
|
135
|
+
- ext/rtree/lib/rtree.h
|
136
|
+
- ext/rtree/lib/rtree/branch.h
|
137
|
+
- ext/rtree/lib/rtree/branches.h
|
138
|
+
- ext/rtree/lib/rtree/error.h
|
139
|
+
- ext/rtree/lib/rtree/extent.h
|
140
|
+
- ext/rtree/lib/rtree/node.h
|
141
|
+
- ext/rtree/lib/rtree/package.h
|
142
|
+
- ext/rtree/lib/rtree/postscript.h
|
143
|
+
- ext/rtree/lib/rtree/rect.h
|
144
|
+
- ext/rtree/lib/rtree/rectf.h
|
145
|
+
- ext/rtree/lib/rtree/search.h
|
146
|
+
- ext/rtree/lib/rtree/state.h
|
147
|
+
- ext/rtree/lib/rtree/types.h
|
148
|
+
- ext/rtree/lib/search.c
|
149
|
+
- ext/rtree/lib/split.c
|
150
|
+
- ext/rtree/lib/split.h
|
151
|
+
- ext/rtree/lib/spvol.c
|
152
|
+
- ext/rtree/lib/spvol.h
|
153
|
+
- ext/rtree/lib/state.c
|
107
154
|
- ext/rtree/rtree.c
|
108
155
|
- lib/rtree.rb
|
109
156
|
homepage: https://gitlab.com/jjg/librtree-ruby
|
@@ -126,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
173
|
- !ruby/object:Gem::Version
|
127
174
|
version: '0'
|
128
175
|
requirements:
|
129
|
-
- The
|
130
|
-
rubygems_version: 3.1.
|
176
|
+
- The Jannson library
|
177
|
+
rubygems_version: 3.1.6
|
131
178
|
signing_key:
|
132
179
|
specification_version: 4
|
133
180
|
summary: R-tree spatial index
|