librtree 1.0.1 → 1.0.3
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 +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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97e18073b1466bdc07ddba6d4b06cfa850c3531240920ab4bd391a1896def24f
|
4
|
+
data.tar.gz: 0a57abcf15c8dd21e3ec7ee26fdb2f5d98ae8ec06838297eb00b05f5ebaae70d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e633393e0fc75958fae7ee302a0a1e51e42ce41f86ec887da9c41bf74c2bb1657b4c06d4e690939c83945092ba4531901050f537bef6c48c73ddeea28a272a69
|
7
|
+
data.tar.gz: 25b6456ab526e41afd095157c96715118cdadbb9a15c2c863197fda329a61f5d6f8adda1e78aeb8733f8e74d54faf4bba193103e81aff3db7bfebcc8e54c2052
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
Changelog
|
2
2
|
---------
|
3
3
|
|
4
|
+
### 1.0.3, 16-10-2023
|
5
|
+
|
6
|
+
- Update to librtree 1.3.0
|
7
|
+
- Remove workaround for "optional argument to #exit!" issue
|
8
|
+
|
9
|
+
### 1.0.2, 06-04-2023
|
10
|
+
|
11
|
+
- The `#serialise` method raises if the read from pipe returns
|
12
|
+
nil (which it might), so the method (and other methods which
|
13
|
+
call it to serialise) now return `String` or raise
|
14
|
+
- Added RBS static type signatures and infrastructure for static
|
15
|
+
type checking with **steep**
|
16
|
+
|
4
17
|
### 1.0.1, 16-03-2023
|
5
18
|
|
6
19
|
- Update to 1.1.4 of embedded `librtree`
|
@@ -18,7 +31,7 @@ Changelog
|
|
18
31
|
|
19
32
|
- Tidying
|
20
33
|
- Fix warning "undefining the allocator of T_DATA class" on
|
21
|
-
Ruby 3
|
34
|
+
Ruby 3.2
|
22
35
|
- No functional changes
|
23
36
|
|
24
37
|
### 0.9.0, 07-11-2021
|
data/README.md
CHANGED
@@ -54,12 +54,12 @@ this.
|
|
54
54
|
If using [rbenv][4], then first set a local version of Ruby to use,
|
55
55
|
then install the gems into your local cache
|
56
56
|
|
57
|
-
rbenv local 2.
|
57
|
+
rbenv local 3.2.0
|
58
58
|
bundle install
|
59
59
|
|
60
|
-
The repository's `.gitignore` ignores **rbenv**'s `.ruby-version`
|
61
|
-
|
62
|
-
|
60
|
+
The repository's `.gitignore` ignores **rbenv**'s `.ruby-version` file,
|
61
|
+
since we don't want to mandate a particular Ruby version for the package
|
62
|
+
(although 3.0 is the minimal version for development at present).
|
63
63
|
|
64
64
|
If not using **rbenv** then just
|
65
65
|
|
@@ -79,6 +79,7 @@ run the tests:
|
|
79
79
|
|
80
80
|
bundle exec rake compile
|
81
81
|
bundle exec rake spec
|
82
|
+
bundle exec steep check
|
82
83
|
|
83
84
|
|
84
85
|
[1]: http://www.digip.org/jansson/
|
data/ext/rtree/lib/branch.c
CHANGED
@@ -0,0 +1,97 @@
|
|
1
|
+
/*
|
2
|
+
branch.h
|
3
|
+
Copyright (c) J.J. Green 2023
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef BRANCH_H
|
7
|
+
#define BRANCH_H
|
8
|
+
|
9
|
+
#include <stdlib.h>
|
10
|
+
|
11
|
+
#include "rtree/branch.h"
|
12
|
+
|
13
|
+
#include "rect.h"
|
14
|
+
#include "rtree/types.h"
|
15
|
+
#include "rtree/state.h"
|
16
|
+
#include "rtree/node.h"
|
17
|
+
|
18
|
+
/*
|
19
|
+
The union is either a pointer to the child-node in the tree, or
|
20
|
+
if we are at level zero, the id payload. The latter may as well
|
21
|
+
be the size of a pointer.
|
22
|
+
|
23
|
+
The rect is big enough to hold 2 * dims floats, understood to be
|
24
|
+
[x0, y0, ..., x1, y1, ...] corresponding to the (hyper-)rectangle
|
25
|
+
x0 < x < x1, y0 < y < y1, ..., this must be at the end of the
|
26
|
+
struct (since variable).
|
27
|
+
|
28
|
+
For the sake of SSE, we would like the rect member to be 16-byte
|
29
|
+
aligned, and this could be done with
|
30
|
+
|
31
|
+
rtree_coord_t alignas(16) rect[];
|
32
|
+
|
33
|
+
but this would force the size of branch_t to be a multiple of 16,
|
34
|
+
so for the dimension 2 case with rtree_coord_t a float increases
|
35
|
+
branch size from 24 to 32 bytes, essentially increasing the size
|
36
|
+
of the tree by 20%. So we don't do that, and use non-aligned
|
37
|
+
variants for SSE load/save (apparently on recent CPUs the penalty
|
38
|
+
is pretty small).
|
39
|
+
*/
|
40
|
+
|
41
|
+
struct branch_t
|
42
|
+
{
|
43
|
+
union {
|
44
|
+
node_t *child;
|
45
|
+
rtree_id_t id;
|
46
|
+
};
|
47
|
+
rtree_coord_t rect[];
|
48
|
+
};
|
49
|
+
|
50
|
+
size_t branch_sizeof(size_t);
|
51
|
+
int branch_init(const state_t*, branch_t*);
|
52
|
+
branch_t* branch_copy(const state_t*, const branch_t*, branch_t*);
|
53
|
+
|
54
|
+
/* inline accessors */
|
55
|
+
|
56
|
+
inline void branch_set_child(branch_t *branch, node_t *child)
|
57
|
+
{
|
58
|
+
branch->child = child;
|
59
|
+
}
|
60
|
+
|
61
|
+
inline const node_t* branch_get_child(const branch_t *branch)
|
62
|
+
{
|
63
|
+
return branch->child;
|
64
|
+
}
|
65
|
+
|
66
|
+
inline node_t* branch_get_child_mutable(branch_t *branch)
|
67
|
+
{
|
68
|
+
return branch->child;
|
69
|
+
}
|
70
|
+
|
71
|
+
inline void branch_set_id(branch_t *branch, rtree_id_t id)
|
72
|
+
{
|
73
|
+
branch->id = id;
|
74
|
+
}
|
75
|
+
|
76
|
+
inline rtree_id_t branch_get_id(const branch_t *branch)
|
77
|
+
{
|
78
|
+
return branch->id;
|
79
|
+
}
|
80
|
+
|
81
|
+
inline void branch_set_rect(const state_t *state, branch_t *branch,
|
82
|
+
const rtree_coord_t *rect)
|
83
|
+
{
|
84
|
+
rect_copy(state, rect, branch->rect);
|
85
|
+
}
|
86
|
+
|
87
|
+
inline const rtree_coord_t* branch_get_rect(const branch_t *branch)
|
88
|
+
{
|
89
|
+
return branch->rect;
|
90
|
+
}
|
91
|
+
|
92
|
+
inline rtree_coord_t* branch_get_rect_mutable(branch_t *branch)
|
93
|
+
{
|
94
|
+
return branch->rect;
|
95
|
+
}
|
96
|
+
|
97
|
+
#endif
|
data/ext/rtree/lib/branches.c
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/*
|
2
|
-
|
2
|
+
branches.h
|
3
3
|
Copyright (c) J.J. Green 2020
|
4
4
|
*/
|
5
5
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
6
|
+
#ifndef BRANCHES_H
|
7
|
+
#define BRANCHES_H
|
8
8
|
|
9
9
|
#ifdef __cplusplus
|
10
10
|
extern "C" {
|
@@ -14,9 +14,9 @@ extern "C" {
|
|
14
14
|
#include <errno.h>
|
15
15
|
#include <string.h>
|
16
16
|
|
17
|
-
#include
|
18
|
-
#include
|
19
|
-
#include
|
17
|
+
#include "state.h"
|
18
|
+
#include "rtree/branch.h"
|
19
|
+
#include "rtree/error.h"
|
20
20
|
|
21
21
|
inline branch_t* branches_get(const state_t *state, void *buffer, size_t i)
|
22
22
|
{
|
data/ext/rtree/lib/bsrt.c
CHANGED
@@ -4,8 +4,11 @@
|
|
4
4
|
|
5
5
|
#include "bsrt.h"
|
6
6
|
|
7
|
+
#include "node.h"
|
8
|
+
#include "branch.h"
|
9
|
+
#include "branches.h"
|
10
|
+
|
7
11
|
#include "rtree/error.h"
|
8
|
-
#include "rtree/branches.h"
|
9
12
|
|
10
13
|
#include <errno.h>
|
11
14
|
#include <string.h>
|
@@ -129,28 +132,18 @@ static int write_rect(const state_t *state,
|
|
129
132
|
|
130
133
|
for (size_t i = 0 ; i < n ; i++)
|
131
134
|
{
|
132
|
-
/*
|
133
|
-
The type-punning to/from char* here is legal (the standard
|
134
|
-
makes an explicit exception), but cppcheck warns anyway, so
|
135
|
-
we suppress those warnings
|
136
|
-
*/
|
137
|
-
|
138
135
|
char p[k];
|
139
136
|
|
140
|
-
/* cppcheck-suppress invalidPointerCast */
|
141
137
|
*(rtree_coord_t*)p = rect[i];
|
142
138
|
|
143
139
|
#if SIZEOF_RTREE_COORD_T == 4
|
144
|
-
/* cppcheck-suppress invalidPointerCast */
|
145
140
|
*(uint32_t*)p = htole32(*(uint32_t*)p);
|
146
141
|
#elif SIZEOF_RTREE_COORD_T == 8
|
147
|
-
/* cppcheck-suppress invalidPointerCast */
|
148
142
|
*(uint64_t*)p = htole64(*(uint64_t*)p);
|
149
143
|
#else
|
150
144
|
#error rtree_coord_t size not handled
|
151
145
|
#endif
|
152
146
|
|
153
|
-
/* cppcheck-suppress invalidPointerCast */
|
154
147
|
buffer[i] = *(rtree_coord_t*)p;
|
155
148
|
}
|
156
149
|
|
@@ -321,7 +314,7 @@ static int read_v1_header(FILE *stream, uint16_t v[5])
|
|
321
314
|
return 0;
|
322
315
|
}
|
323
316
|
|
324
|
-
static bool read_v1_state_consistent(uint16_t v[5], const state_t *state)
|
317
|
+
static bool read_v1_state_consistent(const uint16_t v[5], const state_t *state)
|
325
318
|
{
|
326
319
|
return
|
327
320
|
(v[0] == state_dims(state)) &&
|
@@ -360,8 +353,6 @@ static int read_v1_rect(FILE *stream,
|
|
360
353
|
#error rtree_coord_t size not handled
|
361
354
|
#endif
|
362
355
|
|
363
|
-
/* cppcheck-suppress invalidPointerCast */
|
364
|
-
|
365
356
|
rect[i] = *(rtree_coord_t*)p;
|
366
357
|
}
|
367
358
|
|
@@ -592,7 +583,7 @@ static int read_v2_header(FILE *stream, uint16_t v[6])
|
|
592
583
|
return 0;
|
593
584
|
}
|
594
585
|
|
595
|
-
static bool read_v2_state_consistent(uint16_t v[6], const state_t *state)
|
586
|
+
static bool read_v2_state_consistent(const uint16_t v[6], const state_t *state)
|
596
587
|
{
|
597
588
|
return
|
598
589
|
(v[0] == state_dims(state)) &&
|
data/ext/rtree/lib/bsrt.h
CHANGED
data/ext/rtree/lib/csv.c
CHANGED
data/ext/rtree/lib/csv.h
CHANGED
data/ext/rtree/lib/json.c
CHANGED
data/ext/rtree/lib/json.h
CHANGED
data/ext/rtree/lib/node.c
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
#include "config.h"
|
3
3
|
#endif
|
4
4
|
|
5
|
-
#include "
|
6
|
-
|
7
|
-
#include "rtree/rect.h"
|
5
|
+
#include "node.h"
|
6
|
+
|
8
7
|
#include "rtree/error.h"
|
9
8
|
|
9
|
+
#include "branch.h"
|
10
|
+
#include "branches.h"
|
11
|
+
#include "rect.h"
|
10
12
|
#include "split.h"
|
11
13
|
|
12
14
|
#include <stdbool.h>
|
@@ -307,23 +309,27 @@ node_t* node_add_branch(const state_t *state, node_t *node, branch_t *branch)
|
|
307
309
|
Pick a branch. Pick the one that will need the smallest increase
|
308
310
|
in volume to accomodate the new (hyper-)rectangle. This will result
|
309
311
|
in the least total volume for the covering rectangles in the current
|
310
|
-
node.
|
311
|
-
|
312
|
+
node.
|
313
|
+
|
314
|
+
This is expensive but does not show up directly in the profile since
|
315
|
+
it is only called once so obviously inlined.
|
312
316
|
*/
|
313
317
|
|
314
318
|
static int node_pick_branch(const state_t *state,
|
315
|
-
node_t *node,
|
319
|
+
node_t *node,
|
320
|
+
const rtree_coord_t *rect,
|
316
321
|
size_t *index)
|
317
322
|
{
|
318
|
-
const size_t
|
319
|
-
dims = state_dims(state);
|
320
|
-
size_t
|
321
|
-
index_min = SIZE_MAX;
|
322
|
-
rtree_coord_t
|
323
|
-
dvol_min = INFINITY,
|
324
|
-
vol_min = INFINITY;
|
325
323
|
|
326
|
-
|
324
|
+
const size_t dims = state_dims(state);
|
325
|
+
assert(dims > 0);
|
326
|
+
rtree_coord_t rect2[2 * dims];
|
327
|
+
|
328
|
+
const size_t n = node_count(node);
|
329
|
+
assert(n > 0);
|
330
|
+
rtree_coord_t dvol[n];
|
331
|
+
|
332
|
+
for (size_t i = 0 ; i < n ; i++)
|
327
333
|
{
|
328
334
|
branch_t *branch;
|
329
335
|
|
@@ -331,34 +337,29 @@ static int node_pick_branch(const state_t *state,
|
|
331
337
|
return RTREE_ERR_GETBRANCH;
|
332
338
|
|
333
339
|
const rtree_coord_t *rect1 = branch_get_rect(branch);
|
334
|
-
rtree_coord_t rect2[2 * dims];
|
335
340
|
rect_combine(state, rect, rect1, rect2);
|
336
341
|
|
337
342
|
rtree_coord_t
|
338
343
|
vol1 = rect_spherical_volume(state, rect1),
|
339
|
-
vol2 = rect_spherical_volume(state, rect2)
|
340
|
-
dvol = vol2 - vol1;
|
344
|
+
vol2 = rect_spherical_volume(state, rect2);
|
341
345
|
|
342
|
-
|
346
|
+
dvol[i] = vol2 - vol1;
|
347
|
+
}
|
348
|
+
|
349
|
+
rtree_coord_t dvol_min = dvol[0];
|
350
|
+
size_t index_min = 0;
|
351
|
+
|
352
|
+
for (size_t i = 1 ; i < n ; i++)
|
353
|
+
{
|
354
|
+
rtree_coord_t dvol_i = dvol[i];
|
355
|
+
|
356
|
+
if (dvol_i < dvol_min)
|
343
357
|
{
|
358
|
+
dvol_min = dvol_i;
|
344
359
|
index_min = i;
|
345
|
-
vol_min = vol1;
|
346
|
-
dvol_min = dvol;
|
347
360
|
}
|
348
361
|
}
|
349
362
|
|
350
|
-
/*
|
351
|
-
This can only happen if no branches are assigned in the above
|
352
|
-
block, on the first call of it, dvol_min == DBL_MAX, so either
|
353
|
-
the first case is called, or dvol == DBL_MAX, but dvol is equal
|
354
|
-
to vol2 - vol1, and vol1, vol2 are non-negative, so vol2 must
|
355
|
-
be DBL_MAX and vol1 zero, in particular vol1 < vol_min (DBL_MAX),
|
356
|
-
so the second condition is met.
|
357
|
-
*/
|
358
|
-
|
359
|
-
if (index_min == SIZE_MAX)
|
360
|
-
return RTREE_ERR_PICKBRANCH;
|
361
|
-
|
362
363
|
*index = index_min;
|
363
364
|
|
364
365
|
return RTREE_OK;
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/*
|
2
|
+
node.h
|
3
|
+
Copyright (c) J.J. Green 2023
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef NODE_H
|
7
|
+
#define NODE_H
|
8
|
+
|
9
|
+
#include <stdint.h>
|
10
|
+
#include <stdbool.h>
|
11
|
+
#include <stddef.h>
|
12
|
+
|
13
|
+
typedef uint16_t node_level_t;
|
14
|
+
typedef uint16_t node_count_t;
|
15
|
+
typedef uint16_t node_height_t;
|
16
|
+
|
17
|
+
#define NODE_LEVEL_MAX UINT16_MAX
|
18
|
+
#define NODE_COUNT_MAX UINT16_MAX
|
19
|
+
|
20
|
+
#include "rtree/node.h"
|
21
|
+
|
22
|
+
#include "rtree/types.h"
|
23
|
+
#include "rtree/state.h"
|
24
|
+
#include "rtree/branch.h"
|
25
|
+
|
26
|
+
struct node_t
|
27
|
+
{
|
28
|
+
node_level_t level;
|
29
|
+
node_count_t count;
|
30
|
+
char branches[];
|
31
|
+
};
|
32
|
+
|
33
|
+
typedef int (nbe_cb_t)(const state_t*, const branch_t*, void*);
|
34
|
+
|
35
|
+
int node_init(const state_t*, node_t*);
|
36
|
+
node_t* node_new(const state_t*);
|
37
|
+
void node_destroy(const state_t*, node_t*);
|
38
|
+
node_t* node_clone(const state_t*, const node_t*);
|
39
|
+
int node_branch_each(const state_t*, const node_t*, nbe_cb_t*, void*);
|
40
|
+
int node_branch_each_level(const state_t*, const node_t*, node_level_t,
|
41
|
+
nbe_cb_t*, void*);
|
42
|
+
size_t node_num_branch(size_t, size_t);
|
43
|
+
int node_detach_branch(const state_t*, node_t*, size_t);
|
44
|
+
node_t* node_add_branch(const state_t*, node_t*, branch_t*);
|
45
|
+
int node_envelope(const state_t*, const node_t*, rtree_coord_t*);
|
46
|
+
node_t* node_add_rect(const state_t*, rtree_id_t, rtree_coord_t*,
|
47
|
+
node_t*, node_level_t);
|
48
|
+
int node_update(const state_t*, const node_t*, rtree_update_t*, void*);
|
49
|
+
bool node_identical(const state_t*, const node_t*, const node_t*);
|
50
|
+
node_height_t node_height(const state_t*, const node_t*);
|
51
|
+
size_t node_bytes(const state_t*, const node_t*);
|
52
|
+
bool node_nonempty(const state_t*, const node_t*);
|
53
|
+
|
54
|
+
inline node_count_t node_count(const node_t *node)
|
55
|
+
{
|
56
|
+
return node->count;
|
57
|
+
}
|
58
|
+
|
59
|
+
inline void node_count_increment(node_t *node)
|
60
|
+
{
|
61
|
+
node->count++;
|
62
|
+
}
|
63
|
+
|
64
|
+
inline void node_count_decrement(node_t *node)
|
65
|
+
{
|
66
|
+
node->count--;
|
67
|
+
}
|
68
|
+
|
69
|
+
inline node_level_t node_level(const node_t *node)
|
70
|
+
{
|
71
|
+
return node->level;
|
72
|
+
}
|
73
|
+
|
74
|
+
inline void node_set_level(node_t *node, node_level_t level)
|
75
|
+
{
|
76
|
+
node->level = level;
|
77
|
+
}
|
78
|
+
|
79
|
+
inline void* node_get_branches(node_t *node)
|
80
|
+
{
|
81
|
+
return node->branches;
|
82
|
+
}
|
83
|
+
|
84
|
+
#endif
|
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.
|
8
|
+
const char rtree_package_version[] = "1.2.0";
|
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
@@ -3,6 +3,11 @@
|
|
3
3
|
#endif
|
4
4
|
|
5
5
|
#include "rtree/postscript.h"
|
6
|
+
|
7
|
+
#include "node.h"
|
8
|
+
#include "branch.h"
|
9
|
+
#include "state.h"
|
10
|
+
|
6
11
|
#include "rtree/package.h"
|
7
12
|
#include "rtree/error.h"
|
8
13
|
|
@@ -32,7 +37,7 @@ typedef struct {
|
|
32
37
|
typedef struct {
|
33
38
|
const state_t *state;
|
34
39
|
const node_t *root;
|
35
|
-
const
|
40
|
+
const postscript_style_t *style;
|
36
41
|
page_t page;
|
37
42
|
} ps_t;
|
38
43
|
|
@@ -45,7 +50,7 @@ static bool clamped(float value)
|
|
45
50
|
return (value >= 0.0) && (value <= 1.0);
|
46
51
|
}
|
47
52
|
|
48
|
-
static int psr_colour(json_t *json,
|
53
|
+
static int psr_colour(json_t *json, postscript_colour_t *colour)
|
49
54
|
{
|
50
55
|
json_t *json_colour;
|
51
56
|
|
@@ -127,7 +132,7 @@ static int psr_colour(json_t *json, colour_t *colour)
|
|
127
132
|
return 1;
|
128
133
|
}
|
129
134
|
|
130
|
-
static int psr_style_level(json_t *json,
|
135
|
+
static int psr_style_level(json_t *json, postscript_style_level_t *style_level)
|
131
136
|
{
|
132
137
|
if (! json_is_object(json))
|
133
138
|
return 1;
|
@@ -169,7 +174,7 @@ static int psr_style_level(json_t *json, style_level_t *style_level)
|
|
169
174
|
return 0;
|
170
175
|
}
|
171
176
|
|
172
|
-
static
|
177
|
+
static postscript_style_t* psr_style(json_t *json)
|
173
178
|
{
|
174
179
|
if (! json_is_array(json))
|
175
180
|
return NULL;
|
@@ -179,16 +184,16 @@ static style_t* psr_style(json_t *json)
|
|
179
184
|
if (n == 0)
|
180
185
|
return NULL;
|
181
186
|
|
182
|
-
|
187
|
+
postscript_style_level_t *array;
|
183
188
|
|
184
|
-
if ((array = calloc(n, sizeof(
|
189
|
+
if ((array = calloc(n, sizeof(postscript_style_level_t))) != NULL)
|
185
190
|
{
|
186
191
|
size_t i;
|
187
192
|
json_t *json_style;
|
188
193
|
|
189
194
|
json_array_foreach(json, i, json_style)
|
190
195
|
{
|
191
|
-
|
196
|
+
postscript_style_level_t *style_level = array + i;
|
192
197
|
|
193
198
|
if (psr_style_level(json_style, style_level) != 0)
|
194
199
|
{
|
@@ -197,9 +202,9 @@ static style_t* psr_style(json_t *json)
|
|
197
202
|
}
|
198
203
|
}
|
199
204
|
|
200
|
-
|
205
|
+
postscript_style_t *style;
|
201
206
|
|
202
|
-
if ((style = malloc(sizeof(
|
207
|
+
if ((style = malloc(sizeof(postscript_style_t))) != NULL)
|
203
208
|
{
|
204
209
|
style->n = n;
|
205
210
|
style->array = array;
|
@@ -212,14 +217,14 @@ static style_t* psr_style(json_t *json)
|
|
212
217
|
return NULL;
|
213
218
|
}
|
214
219
|
|
215
|
-
|
220
|
+
postscript_style_t* postscript_style_read(FILE *stream)
|
216
221
|
{
|
217
222
|
const size_t flags = JSON_REJECT_DUPLICATES;
|
218
223
|
json_t *json;
|
219
224
|
|
220
225
|
if ((json = json_loadf(stream, flags, NULL)) != NULL)
|
221
226
|
{
|
222
|
-
|
227
|
+
postscript_style_t *style = psr_style(json);
|
223
228
|
json_decref(json);
|
224
229
|
return style;
|
225
230
|
}
|
@@ -231,7 +236,7 @@ style_t* postscript_style_read(FILE *stream)
|
|
231
236
|
|
232
237
|
#pragma GCC diagnostic push
|
233
238
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
234
|
-
|
239
|
+
postscript_style_t* postscript_style_read(FILE *stream)
|
235
240
|
{
|
236
241
|
errno = ENOSYS;
|
237
242
|
return NULL;
|
@@ -240,7 +245,7 @@ style_t* postscript_style_read(FILE *stream)
|
|
240
245
|
|
241
246
|
#endif
|
242
247
|
|
243
|
-
void postscript_style_destroy(
|
248
|
+
void postscript_style_destroy(postscript_style_t *style)
|
244
249
|
{
|
245
250
|
if (style != NULL)
|
246
251
|
free(style->array);
|
@@ -473,7 +478,7 @@ int postscript_write(const state_t *state,
|
|
473
478
|
if (i >= ps.style->n)
|
474
479
|
break;
|
475
480
|
|
476
|
-
|
481
|
+
postscript_style_level_t style_level = ps.style->array[i];
|
477
482
|
node_level_t level = max_level - i;
|
478
483
|
|
479
484
|
switch (style_level.fill.colour.model)
|