librtree 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -1
- data/README.md +5 -4
- data/ext/rtree/lib/branch.c +2 -1
- data/ext/rtree/lib/branch.h +97 -0
- data/ext/rtree/lib/branches.c +1 -1
- data/ext/rtree/lib/{rtree/branches.h → branches.h} +6 -6
- data/ext/rtree/lib/bsrt.c +6 -15
- data/ext/rtree/lib/bsrt.h +1 -1
- data/ext/rtree/lib/csv.c +1 -0
- data/ext/rtree/lib/csv.h +2 -2
- data/ext/rtree/lib/json.c +3 -1
- data/ext/rtree/lib/json.h +1 -1
- data/ext/rtree/lib/node.c +33 -32
- data/ext/rtree/lib/node.h +84 -0
- data/ext/rtree/lib/package.c +1 -1
- data/ext/rtree/lib/postscript.c +19 -14
- data/ext/rtree/lib/rect.c +3 -1
- data/ext/rtree/lib/{rtree/rect.h → rect.h} +5 -13
- data/ext/rtree/lib/rtree/branch.h +0 -86
- data/ext/rtree/lib/rtree/node.h +1 -75
- data/ext/rtree/lib/rtree/postscript.h +12 -11
- data/ext/rtree/lib/rtree/search.h +0 -6
- data/ext/rtree/lib/rtree/state.h +1 -79
- data/ext/rtree/lib/rtree-base.c +61 -1
- data/ext/rtree/lib/rtree.h +7 -5
- data/ext/rtree/lib/search.c +5 -3
- data/ext/rtree/lib/search.h +21 -0
- data/ext/rtree/lib/split.c +3 -1
- data/ext/rtree/lib/split.h +3 -3
- data/ext/rtree/lib/state.c +3 -3
- data/ext/rtree/lib/state.h +90 -0
- data/ext/rtree/rtree.c +18 -18
- data/lib/rtree.rb +23 -18
- metadata +37 -5
@@ -1,20 +1,16 @@
|
|
1
1
|
/*
|
2
|
-
|
2
|
+
rect.h
|
3
3
|
Copyright (c) J.J. Green 2019
|
4
4
|
*/
|
5
5
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
8
|
-
|
9
|
-
#ifdef __cplusplus
|
10
|
-
extern "C" {
|
11
|
-
#endif
|
6
|
+
#ifndef RECT_H
|
7
|
+
#define RECT_H
|
12
8
|
|
13
9
|
#include <stdlib.h>
|
14
10
|
#include <stdbool.h>
|
15
11
|
|
16
|
-
#include
|
17
|
-
#include
|
12
|
+
#include "rtree/state.h"
|
13
|
+
#include "rtree/types.h"
|
18
14
|
|
19
15
|
int rect_init(const state_t*, rtree_coord_t*);
|
20
16
|
|
@@ -31,8 +27,4 @@ bool rect_identical(const state_t*, const rtree_coord_t*, const rtree_coord_t*);
|
|
31
27
|
int rects_alloc(const state_t*, size_t, rtree_coord_t**);
|
32
28
|
void rects_free(size_t, rtree_coord_t**);
|
33
29
|
|
34
|
-
#ifdef __cplusplus
|
35
|
-
}
|
36
|
-
#endif
|
37
|
-
|
38
30
|
#endif
|
@@ -10,94 +10,8 @@
|
|
10
10
|
extern "C" {
|
11
11
|
#endif
|
12
12
|
|
13
|
-
#include <stdlib.h>
|
14
|
-
|
15
13
|
typedef struct branch_t branch_t;
|
16
14
|
|
17
|
-
#include <rtree/types.h>
|
18
|
-
#include <rtree/state.h>
|
19
|
-
#include <rtree/node.h>
|
20
|
-
#include <rtree/rect.h>
|
21
|
-
|
22
|
-
/*
|
23
|
-
The union is either a pointer to the child-node in the tree, or
|
24
|
-
if we are at level zero, the id payload. The latter may as well
|
25
|
-
be the size of a pointer.
|
26
|
-
|
27
|
-
The rect is big enough to hold 2 * dims floats, understood to be
|
28
|
-
[x0, y0, ..., x1, y1, ...] corresponding to the (hyper-)rectangle
|
29
|
-
x0 < x < x1, y0 < y < y1, ..., this must be at the end of the
|
30
|
-
struct (since variable).
|
31
|
-
|
32
|
-
For the sake of SSE, we would like the rect member to be 16-byte
|
33
|
-
aligned, and this could be done with
|
34
|
-
|
35
|
-
rtree_coord_t alignas(16) rect[];
|
36
|
-
|
37
|
-
but this would force the size of branch_t to be a multiple of 16,
|
38
|
-
so for the dimension 2 case with rtree_coord_t a float increases
|
39
|
-
branch size from 24 to 32 bytes, essentially increasing the size
|
40
|
-
of the tree by 20%. So we don't do that, and use non-aligned
|
41
|
-
variants for SSE load/save (apparently on recent CPUs the penalty
|
42
|
-
is pretty small).
|
43
|
-
*/
|
44
|
-
|
45
|
-
struct branch_t
|
46
|
-
{
|
47
|
-
union {
|
48
|
-
node_t *child;
|
49
|
-
rtree_id_t id;
|
50
|
-
};
|
51
|
-
rtree_coord_t rect[];
|
52
|
-
};
|
53
|
-
|
54
|
-
size_t branch_sizeof(size_t);
|
55
|
-
int branch_init(const state_t*, branch_t*);
|
56
|
-
branch_t* branch_copy(const state_t*, const branch_t*, branch_t*);
|
57
|
-
|
58
|
-
/* inline accessors */
|
59
|
-
|
60
|
-
inline void branch_set_child(branch_t *branch, node_t *child)
|
61
|
-
{
|
62
|
-
branch->child = child;
|
63
|
-
}
|
64
|
-
|
65
|
-
inline const node_t* branch_get_child(const branch_t *branch)
|
66
|
-
{
|
67
|
-
return branch->child;
|
68
|
-
}
|
69
|
-
|
70
|
-
inline node_t* branch_get_child_mutable(branch_t *branch)
|
71
|
-
{
|
72
|
-
return branch->child;
|
73
|
-
}
|
74
|
-
|
75
|
-
inline void branch_set_id(branch_t *branch, rtree_id_t id)
|
76
|
-
{
|
77
|
-
branch->id = id;
|
78
|
-
}
|
79
|
-
|
80
|
-
inline rtree_id_t branch_get_id(const branch_t *branch)
|
81
|
-
{
|
82
|
-
return branch->id;
|
83
|
-
}
|
84
|
-
|
85
|
-
inline void branch_set_rect(const state_t *state, branch_t *branch,
|
86
|
-
const rtree_coord_t *rect)
|
87
|
-
{
|
88
|
-
rect_copy(state, rect, branch->rect);
|
89
|
-
}
|
90
|
-
|
91
|
-
inline const rtree_coord_t* branch_get_rect(const branch_t *branch)
|
92
|
-
{
|
93
|
-
return branch->rect;
|
94
|
-
}
|
95
|
-
|
96
|
-
inline rtree_coord_t* branch_get_rect_mutable(branch_t *branch)
|
97
|
-
{
|
98
|
-
return branch->rect;
|
99
|
-
}
|
100
|
-
|
101
15
|
#ifdef __cplusplus
|
102
16
|
}
|
103
17
|
#endif
|
data/ext/rtree/lib/rtree/node.h
CHANGED
@@ -8,86 +8,12 @@
|
|
8
8
|
|
9
9
|
#ifdef __cplusplus
|
10
10
|
extern "C" {
|
11
|
-
#if 0
|
12
|
-
}
|
13
|
-
#endif
|
14
11
|
#endif
|
15
12
|
|
16
|
-
#include <stdint.h>
|
17
|
-
#include <stdbool.h>
|
18
|
-
#include <stddef.h>
|
19
|
-
|
20
|
-
typedef uint16_t node_level_t;
|
21
|
-
typedef uint16_t node_count_t;
|
22
|
-
typedef uint16_t node_height_t;
|
23
|
-
|
24
|
-
#define NODE_LEVEL_MAX UINT16_MAX
|
25
|
-
#define NODE_COUNT_MAX UINT16_MAX
|
26
|
-
|
27
|
-
typedef struct node_t node_t;
|
28
|
-
|
29
13
|
#include <rtree/types.h>
|
30
|
-
#include <rtree/state.h>
|
31
|
-
#include <rtree/branch.h>
|
32
|
-
|
33
|
-
struct node_t
|
34
|
-
{
|
35
|
-
node_level_t level;
|
36
|
-
node_count_t count;
|
37
|
-
char branches[];
|
38
|
-
};
|
39
14
|
|
15
|
+
typedef struct node_t node_t;
|
40
16
|
typedef int (rtree_update_t)(rtree_id_t, rtree_coord_t*, void*);
|
41
|
-
typedef int (nbe_cb_t)(const state_t*, const branch_t*, void*);
|
42
|
-
|
43
|
-
int node_init(const state_t*, node_t*);
|
44
|
-
node_t* node_new(const state_t*);
|
45
|
-
void node_destroy(const state_t*, node_t*);
|
46
|
-
node_t* node_clone(const state_t*, const node_t*);
|
47
|
-
int node_branch_each(const state_t*, const node_t*, nbe_cb_t*, void*);
|
48
|
-
int node_branch_each_level(const state_t*, const node_t*, node_level_t,
|
49
|
-
nbe_cb_t*, void*);
|
50
|
-
size_t node_num_branch(size_t, size_t);
|
51
|
-
int node_detach_branch(const state_t*, node_t*, size_t);
|
52
|
-
node_t* node_add_branch(const state_t*, node_t*, branch_t*);
|
53
|
-
int node_envelope(const state_t*, const node_t*, rtree_coord_t*);
|
54
|
-
node_t* node_add_rect(const state_t*, rtree_id_t, rtree_coord_t*,
|
55
|
-
node_t*, node_level_t);
|
56
|
-
int node_update(const state_t*, const node_t*, rtree_update_t*, void*);
|
57
|
-
bool node_identical(const state_t*, const node_t*, const node_t*);
|
58
|
-
node_height_t node_height(const state_t*, const node_t*);
|
59
|
-
size_t node_bytes(const state_t*, const node_t*);
|
60
|
-
bool node_nonempty(const state_t*, const node_t*);
|
61
|
-
|
62
|
-
inline node_count_t node_count(const node_t *node)
|
63
|
-
{
|
64
|
-
return node->count;
|
65
|
-
}
|
66
|
-
|
67
|
-
inline void node_count_increment(node_t *node)
|
68
|
-
{
|
69
|
-
node->count++;
|
70
|
-
}
|
71
|
-
|
72
|
-
inline void node_count_decrement(node_t *node)
|
73
|
-
{
|
74
|
-
node->count--;
|
75
|
-
}
|
76
|
-
|
77
|
-
inline node_level_t node_level(const node_t *node)
|
78
|
-
{
|
79
|
-
return node->level;
|
80
|
-
}
|
81
|
-
|
82
|
-
inline void node_set_level(node_t *node, node_level_t level)
|
83
|
-
{
|
84
|
-
node->level = level;
|
85
|
-
}
|
86
|
-
|
87
|
-
inline void* node_get_branches(node_t *node)
|
88
|
-
{
|
89
|
-
return node->branches;
|
90
|
-
}
|
91
17
|
|
92
18
|
#ifdef __cplusplus
|
93
19
|
}
|
@@ -14,42 +14,43 @@ typedef struct rtree_postscript_t rtree_postscript_t;
|
|
14
14
|
|
15
15
|
#include <stdio.h>
|
16
16
|
#include <rtree/node.h>
|
17
|
+
#include <rtree/state.h>
|
17
18
|
#include <rtree/extent.h>
|
18
19
|
|
19
20
|
typedef enum
|
20
21
|
{ model_none, model_grey, model_rgb, model_cmyk }
|
21
|
-
|
22
|
+
postscript_colour_model_t;
|
22
23
|
|
23
24
|
typedef struct {
|
24
|
-
|
25
|
+
postscript_colour_model_t model;
|
25
26
|
union {
|
26
27
|
float grey[1];
|
27
28
|
float rgb[3];
|
28
29
|
float cmyk[4];
|
29
30
|
};
|
30
|
-
}
|
31
|
+
} postscript_colour_t;
|
31
32
|
|
32
33
|
typedef struct {
|
33
34
|
struct {
|
34
|
-
|
35
|
+
postscript_colour_t colour;
|
35
36
|
} fill;
|
36
37
|
struct {
|
37
|
-
|
38
|
+
postscript_colour_t colour;
|
38
39
|
float width;
|
39
40
|
} stroke;
|
40
|
-
}
|
41
|
+
} postscript_style_level_t;
|
41
42
|
|
42
43
|
typedef struct {
|
43
44
|
size_t n;
|
44
|
-
|
45
|
-
}
|
45
|
+
postscript_style_level_t *array;
|
46
|
+
} postscript_style_t;
|
46
47
|
|
47
|
-
|
48
|
-
void postscript_style_destroy(
|
48
|
+
postscript_style_t* postscript_style_read(FILE*);
|
49
|
+
void postscript_style_destroy(postscript_style_t*);
|
49
50
|
|
50
51
|
struct rtree_postscript_t
|
51
52
|
{
|
52
|
-
const
|
53
|
+
const postscript_style_t *style;
|
53
54
|
extent_axis_t axis;
|
54
55
|
float extent;
|
55
56
|
float margin;
|
@@ -10,16 +10,10 @@
|
|
10
10
|
extern "C" {
|
11
11
|
#endif
|
12
12
|
|
13
|
-
#include <rtree/node.h>
|
14
13
|
#include <rtree/types.h>
|
15
|
-
#include <rtree/state.h>
|
16
14
|
|
17
15
|
typedef int (rtree_search_t)(rtree_id_t, void*);
|
18
16
|
|
19
|
-
int search(const state_t*,
|
20
|
-
const rtree_coord_t*, const node_t*,
|
21
|
-
rtree_search_t*, void*);
|
22
|
-
|
23
17
|
#ifdef __cplusplus
|
24
18
|
}
|
25
19
|
#endif
|
data/ext/rtree/lib/rtree/state.h
CHANGED
@@ -15,28 +15,10 @@
|
|
15
15
|
extern "C" {
|
16
16
|
#endif
|
17
17
|
|
18
|
-
#include <stdlib.h>
|
19
18
|
#include <stdint.h>
|
20
|
-
#include <stdbool.h>
|
21
|
-
|
22
|
-
#include <rtree/types.h>
|
23
|
-
#include <rtree/rectf.h>
|
24
19
|
|
25
20
|
typedef uint32_t state_flags_t;
|
26
|
-
|
27
|
-
typedef struct
|
28
|
-
{
|
29
|
-
size_t dims, factor;
|
30
|
-
rtree_coord_t volume;
|
31
|
-
struct {
|
32
|
-
size_t page, branch, node;
|
33
|
-
} size;
|
34
|
-
struct {
|
35
|
-
rectf_rsv_t *spherical_volume;
|
36
|
-
rectf_rc_t *combine;
|
37
|
-
} rectf;
|
38
|
-
state_flags_t flags;
|
39
|
-
} state_t;
|
21
|
+
typedef struct state_t state_t;
|
40
22
|
|
41
23
|
#define RTREE_DEFAULT 0
|
42
24
|
|
@@ -46,66 +28,6 @@ typedef struct
|
|
46
28
|
|
47
29
|
#define RTREE_NODE_PAGE(n) ((n) << 2)
|
48
30
|
|
49
|
-
state_t* state_new(size_t, state_flags_t);
|
50
|
-
state_t* state_clone(const state_t*);
|
51
|
-
void state_destroy(state_t*);
|
52
|
-
state_flags_t state_split(const state_t*);
|
53
|
-
state_flags_t state_node_page(const state_t*);
|
54
|
-
bool state_identical(const state_t*, const state_t*);
|
55
|
-
|
56
|
-
inline rtree_coord_t state_rsv(const state_t *state, const rtree_coord_t *rect)
|
57
|
-
{
|
58
|
-
return state->rectf.spherical_volume(state->dims, rect) * state->volume;
|
59
|
-
}
|
60
|
-
|
61
|
-
inline void state_rc(const state_t *state,
|
62
|
-
const rtree_coord_t *rect0,
|
63
|
-
const rtree_coord_t *rect1,
|
64
|
-
rtree_coord_t *rect2)
|
65
|
-
{
|
66
|
-
state->rectf.combine(state->dims, rect0, rect1, rect2);
|
67
|
-
}
|
68
|
-
|
69
|
-
inline size_t state_dims(const state_t *state)
|
70
|
-
{
|
71
|
-
return state->dims;
|
72
|
-
}
|
73
|
-
|
74
|
-
inline size_t state_branch_size(const state_t *state)
|
75
|
-
{
|
76
|
-
return state->size.branch;
|
77
|
-
}
|
78
|
-
|
79
|
-
inline size_t state_page_size(const state_t *state)
|
80
|
-
{
|
81
|
-
return state->size.page;
|
82
|
-
}
|
83
|
-
|
84
|
-
inline size_t state_node_size(const state_t *state)
|
85
|
-
{
|
86
|
-
return state->size.node;
|
87
|
-
}
|
88
|
-
|
89
|
-
inline size_t state_rect_size(const state_t *state)
|
90
|
-
{
|
91
|
-
return state_dims(state) * 2 * sizeof(rtree_coord_t);
|
92
|
-
}
|
93
|
-
|
94
|
-
inline size_t state_branching_factor(const state_t *state)
|
95
|
-
{
|
96
|
-
return state->factor;
|
97
|
-
}
|
98
|
-
|
99
|
-
inline double state_unit_sphere_volume(const state_t *state)
|
100
|
-
{
|
101
|
-
return state->volume;
|
102
|
-
}
|
103
|
-
|
104
|
-
inline size_t state_bytes(const state_t *state)
|
105
|
-
{
|
106
|
-
return (state ? sizeof(state_t) : 0);
|
107
|
-
}
|
108
|
-
|
109
31
|
#ifdef __cplusplus
|
110
32
|
}
|
111
33
|
#endif
|
data/ext/rtree/lib/rtree-base.c
CHANGED
@@ -3,11 +3,15 @@
|
|
3
3
|
#endif
|
4
4
|
|
5
5
|
#include "rtree.h"
|
6
|
-
#include "rtree/error.h"
|
7
6
|
|
8
7
|
#include "csv.h"
|
9
8
|
#include "json.h"
|
10
9
|
#include "bsrt.h"
|
10
|
+
#include "node.h"
|
11
|
+
#include "search.h"
|
12
|
+
#include "state.h"
|
13
|
+
|
14
|
+
#include "rtree/error.h"
|
11
15
|
|
12
16
|
#include <errno.h>
|
13
17
|
#include <stdlib.h>
|
@@ -189,6 +193,62 @@ size_t rtree_bytes(const rtree_t *rtree)
|
|
189
193
|
node_bytes(rtree->state, rtree->root);
|
190
194
|
}
|
191
195
|
|
196
|
+
size_t rtree_dims(const rtree_t *rtree)
|
197
|
+
{
|
198
|
+
if (rtree == NULL)
|
199
|
+
return 0;
|
200
|
+
else
|
201
|
+
return state_dims(rtree->state);
|
202
|
+
}
|
203
|
+
|
204
|
+
size_t rtree_page_size(const rtree_t *rtree)
|
205
|
+
{
|
206
|
+
if (rtree == NULL)
|
207
|
+
return 0;
|
208
|
+
else
|
209
|
+
return state_page_size(rtree->state);
|
210
|
+
}
|
211
|
+
|
212
|
+
size_t rtree_node_size(const rtree_t *rtree)
|
213
|
+
{
|
214
|
+
if (rtree == NULL)
|
215
|
+
return 0;
|
216
|
+
else
|
217
|
+
return state_node_size(rtree->state);
|
218
|
+
}
|
219
|
+
|
220
|
+
size_t rtree_rect_size(const rtree_t *rtree)
|
221
|
+
{
|
222
|
+
if (rtree == NULL)
|
223
|
+
return 0;
|
224
|
+
else
|
225
|
+
return state_rect_size(rtree->state);
|
226
|
+
}
|
227
|
+
|
228
|
+
size_t rtree_branch_size(const rtree_t *rtree)
|
229
|
+
{
|
230
|
+
if (rtree == NULL)
|
231
|
+
return 0;
|
232
|
+
else
|
233
|
+
return state_branch_size(rtree->state);
|
234
|
+
}
|
235
|
+
|
236
|
+
size_t rtree_branching_factor(const rtree_t *rtree)
|
237
|
+
{
|
238
|
+
if (rtree == NULL)
|
239
|
+
return 0;
|
240
|
+
else
|
241
|
+
return state_branching_factor(rtree->state);
|
242
|
+
}
|
243
|
+
|
244
|
+
double rtree_unit_sphere_volume(const rtree_t *rtree)
|
245
|
+
{
|
246
|
+
if (rtree == NULL)
|
247
|
+
return 0;
|
248
|
+
else
|
249
|
+
return state_unit_sphere_volume(rtree->state);
|
250
|
+
}
|
251
|
+
|
192
252
|
bool rtree_empty(const rtree_t *rtree)
|
193
253
|
{
|
194
254
|
return
|
data/ext/rtree/lib/rtree.h
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
/*
|
2
2
|
rtree.h
|
3
|
-
|
4
|
-
This is the bottom-level "public" header, it does not
|
5
|
-
include all of the rtree headers, just enough to define
|
6
|
-
the members of the (atypically) open structure rtree_t.
|
7
|
-
|
8
3
|
Copyright (c) J.J. Green 2020
|
9
4
|
*/
|
10
5
|
|
@@ -53,6 +48,13 @@ rtree_t* rtree_bsrt_read(FILE*);
|
|
53
48
|
int rtree_postscript(const rtree_t*, const rtree_postscript_t*, FILE*);
|
54
49
|
const char* rtree_strerror(int);
|
55
50
|
size_t rtree_bytes(const rtree_t*);
|
51
|
+
size_t rtree_dims(const rtree_t*);
|
52
|
+
size_t rtree_page_size(const rtree_t*);
|
53
|
+
size_t rtree_node_size(const rtree_t*);
|
54
|
+
size_t rtree_rect_size(const rtree_t*);
|
55
|
+
size_t rtree_branch_size(const rtree_t*);
|
56
|
+
size_t rtree_branching_factor(const rtree_t*);
|
57
|
+
double rtree_unit_sphere_volume(const rtree_t*);
|
56
58
|
bool rtree_empty(const rtree_t*);
|
57
59
|
|
58
60
|
#ifdef __cplusplus
|
data/ext/rtree/lib/search.c
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
#include "config.h"
|
3
3
|
#endif
|
4
4
|
|
5
|
-
#include "
|
5
|
+
#include "search.h"
|
6
|
+
#include "node.h"
|
7
|
+
#include "branch.h"
|
8
|
+
#include "rect.h"
|
6
9
|
|
7
|
-
#include "rtree/branch.h"
|
8
10
|
#include "rtree/error.h"
|
9
|
-
|
11
|
+
|
10
12
|
|
11
13
|
typedef struct
|
12
14
|
{
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/*
|
2
|
+
search.h
|
3
|
+
Copyright (c) J.J. Green 2023
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef SEARCH_H
|
7
|
+
#define SEARCH_H
|
8
|
+
|
9
|
+
#include "rtree/search.h"
|
10
|
+
|
11
|
+
#include "rtree/node.h"
|
12
|
+
#include "rtree/types.h"
|
13
|
+
#include "rtree/state.h"
|
14
|
+
|
15
|
+
int search(const state_t*,
|
16
|
+
const rtree_coord_t*,
|
17
|
+
const node_t*,
|
18
|
+
rtree_search_t*,
|
19
|
+
void*);
|
20
|
+
|
21
|
+
#endif
|
data/ext/rtree/lib/split.c
CHANGED
data/ext/rtree/lib/split.h
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
#ifndef SPLIT_H
|
7
7
|
#define SPLIT_H
|
8
8
|
|
9
|
-
#include
|
10
|
-
#include
|
11
|
-
#include
|
9
|
+
#include "rtree/state.h"
|
10
|
+
#include "rtree/branch.h"
|
11
|
+
#include "rtree/node.h"
|
12
12
|
|
13
13
|
node_t* split_node(const state_t*, node_t*, branch_t*);
|
14
14
|
|
data/ext/rtree/lib/state.c
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
#include "config.h"
|
3
3
|
#endif
|
4
4
|
|
5
|
-
#include "
|
6
|
-
#include "rtree/branch.h"
|
7
|
-
#include "rtree/node.h"
|
5
|
+
#include "state.h"
|
8
6
|
|
7
|
+
#include "branch.h"
|
9
8
|
#include "page.h"
|
10
9
|
#include "constants.h"
|
11
10
|
#include "spvol.h"
|
11
|
+
#include "node.h"
|
12
12
|
|
13
13
|
#include <errno.h>
|
14
14
|
#include <string.h>
|
@@ -0,0 +1,90 @@
|
|
1
|
+
/*
|
2
|
+
state.h
|
3
|
+
Copyright (c) J.J. Green 2023
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef STATE_H
|
7
|
+
#define STATE_H
|
8
|
+
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <stdbool.h>
|
11
|
+
|
12
|
+
#include "rtree/state.h"
|
13
|
+
#include "rtree/types.h"
|
14
|
+
#include "rtree/rectf.h"
|
15
|
+
|
16
|
+
struct state_t
|
17
|
+
{
|
18
|
+
size_t dims, factor;
|
19
|
+
rtree_coord_t volume;
|
20
|
+
struct {
|
21
|
+
size_t page, branch, node;
|
22
|
+
} size;
|
23
|
+
struct {
|
24
|
+
rectf_rsv_t *spherical_volume;
|
25
|
+
rectf_rc_t *combine;
|
26
|
+
} rectf;
|
27
|
+
state_flags_t flags;
|
28
|
+
};
|
29
|
+
|
30
|
+
state_t* state_new(size_t, state_flags_t);
|
31
|
+
state_t* state_clone(const state_t*);
|
32
|
+
void state_destroy(state_t*);
|
33
|
+
state_flags_t state_split(const state_t*);
|
34
|
+
state_flags_t state_node_page(const state_t*);
|
35
|
+
bool state_identical(const state_t*, const state_t*);
|
36
|
+
|
37
|
+
inline rtree_coord_t state_rsv(const state_t *state, const rtree_coord_t *rect)
|
38
|
+
{
|
39
|
+
return state->rectf.spherical_volume(state->dims, rect) * state->volume;
|
40
|
+
}
|
41
|
+
|
42
|
+
inline void state_rc(const state_t *state,
|
43
|
+
const rtree_coord_t *rect0,
|
44
|
+
const rtree_coord_t *rect1,
|
45
|
+
rtree_coord_t *rect2)
|
46
|
+
{
|
47
|
+
state->rectf.combine(state->dims, rect0, rect1, rect2);
|
48
|
+
}
|
49
|
+
|
50
|
+
inline size_t state_dims(const state_t *state)
|
51
|
+
{
|
52
|
+
return state->dims;
|
53
|
+
}
|
54
|
+
|
55
|
+
inline size_t state_branch_size(const state_t *state)
|
56
|
+
{
|
57
|
+
return state->size.branch;
|
58
|
+
}
|
59
|
+
|
60
|
+
inline size_t state_page_size(const state_t *state)
|
61
|
+
{
|
62
|
+
return state->size.page;
|
63
|
+
}
|
64
|
+
|
65
|
+
inline size_t state_node_size(const state_t *state)
|
66
|
+
{
|
67
|
+
return state->size.node;
|
68
|
+
}
|
69
|
+
|
70
|
+
inline size_t state_rect_size(const state_t *state)
|
71
|
+
{
|
72
|
+
return state_dims(state) * 2 * sizeof(rtree_coord_t);
|
73
|
+
}
|
74
|
+
|
75
|
+
inline size_t state_branching_factor(const state_t *state)
|
76
|
+
{
|
77
|
+
return state->factor;
|
78
|
+
}
|
79
|
+
|
80
|
+
inline double state_unit_sphere_volume(const state_t *state)
|
81
|
+
{
|
82
|
+
return state->volume;
|
83
|
+
}
|
84
|
+
|
85
|
+
inline size_t state_bytes(const state_t *state)
|
86
|
+
{
|
87
|
+
return (state ? sizeof(state_t) : 0);
|
88
|
+
}
|
89
|
+
|
90
|
+
#endif
|