rgeo 3.0.0.pre.rc.1 → 3.0.0.pre.rc.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -12
  3. data/ext/geos_c_impl/analysis.c +26 -23
  4. data/ext/geos_c_impl/analysis.h +8 -5
  5. data/ext/geos_c_impl/coordinates.c +27 -21
  6. data/ext/geos_c_impl/coordinates.h +5 -2
  7. data/ext/geos_c_impl/errors.c +15 -8
  8. data/ext/geos_c_impl/errors.h +4 -1
  9. data/ext/geos_c_impl/extconf.rb +40 -30
  10. data/ext/geos_c_impl/factory.c +391 -410
  11. data/ext/geos_c_impl/factory.h +66 -48
  12. data/ext/geos_c_impl/geometry.c +417 -299
  13. data/ext/geos_c_impl/geometry.h +5 -5
  14. data/ext/geos_c_impl/geometry_collection.c +289 -213
  15. data/ext/geos_c_impl/geometry_collection.h +6 -7
  16. data/ext/geos_c_impl/globals.c +99 -21
  17. data/ext/geos_c_impl/globals.h +3 -2
  18. data/ext/geos_c_impl/line_string.c +231 -200
  19. data/ext/geos_c_impl/line_string.h +5 -6
  20. data/ext/geos_c_impl/main.c +8 -9
  21. data/ext/geos_c_impl/point.c +62 -63
  22. data/ext/geos_c_impl/point.h +4 -5
  23. data/ext/geos_c_impl/polygon.c +133 -94
  24. data/ext/geos_c_impl/polygon.h +10 -8
  25. data/ext/geos_c_impl/preface.h +8 -13
  26. data/ext/geos_c_impl/ruby_more.c +60 -0
  27. data/ext/geos_c_impl/ruby_more.h +17 -0
  28. data/lib/rgeo/cartesian/bounding_box.rb +1 -1
  29. data/lib/rgeo/cartesian/factory.rb +14 -50
  30. data/lib/rgeo/cartesian/feature_classes.rb +2 -0
  31. data/lib/rgeo/cartesian/feature_methods.rb +16 -5
  32. data/lib/rgeo/cartesian/interface.rb +6 -35
  33. data/lib/rgeo/coord_sys/cs/entities.rb +214 -0
  34. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +15 -8
  35. data/lib/rgeo/coord_sys.rb +1 -20
  36. data/lib/rgeo/feature/curve.rb +0 -10
  37. data/lib/rgeo/feature/factory.rb +1 -9
  38. data/lib/rgeo/feature/factory_generator.rb +3 -10
  39. data/lib/rgeo/feature/geometry.rb +77 -8
  40. data/lib/rgeo/feature/multi_curve.rb +0 -5
  41. data/lib/rgeo/feature/types.rb +5 -5
  42. data/lib/rgeo/geographic/factory.rb +15 -42
  43. data/lib/rgeo/geographic/interface.rb +28 -127
  44. data/lib/rgeo/geographic/projected_feature_methods.rb +16 -10
  45. data/lib/rgeo/geographic/projected_window.rb +1 -1
  46. data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -3
  47. data/lib/rgeo/geographic/simple_mercator_projector.rb +1 -10
  48. data/lib/rgeo/geographic/spherical_feature_methods.rb +17 -6
  49. data/lib/rgeo/geographic.rb +1 -1
  50. data/lib/rgeo/geos/capi_factory.rb +37 -98
  51. data/lib/rgeo/geos/capi_feature_classes.rb +15 -25
  52. data/lib/rgeo/geos/ffi_factory.rb +58 -99
  53. data/lib/rgeo/geos/ffi_feature_methods.rb +15 -29
  54. data/lib/rgeo/geos/interface.rb +5 -37
  55. data/lib/rgeo/geos/zm_factory.rb +5 -43
  56. data/lib/rgeo/geos/zm_feature_methods.rb +15 -24
  57. data/lib/rgeo/geos.rb +8 -8
  58. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +1 -14
  59. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +1 -19
  60. data/lib/rgeo/impl_helper/basic_point_methods.rb +0 -10
  61. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +1 -9
  62. data/lib/rgeo/impl_helper/utils.rb +27 -0
  63. data/lib/rgeo/impl_helper/validity_check.rb +6 -5
  64. data/lib/rgeo/version.rb +1 -1
  65. data/lib/rgeo/wkrep/wkb_generator.rb +68 -53
  66. data/lib/rgeo/wkrep/wkb_parser.rb +19 -16
  67. data/lib/rgeo/wkrep/wkt_generator.rb +34 -34
  68. data/lib/rgeo/wkrep/wkt_parser.rb +26 -23
  69. data/lib/rgeo.rb +1 -3
  70. metadata +23 -9
  71. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  72. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  73. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -2,144 +2,91 @@
2
2
  Factory and utility functions for GEOS wrapper
3
3
  */
4
4
 
5
-
6
5
  #include "preface.h"
7
6
 
8
7
  #ifdef RGEO_GEOS_SUPPORTED
9
8
 
10
- #include <ruby.h>
11
9
  #include <geos_c.h>
12
- #include <ctype.h>
13
- #include <stdarg.h>
14
- #include <stdio.h>
15
-
16
- #include "globals.h"
10
+ #include <ruby.h>
17
11
 
12
+ #include "errors.h"
18
13
  #include "factory.h"
19
14
  #include "geometry.h"
20
- #include "point.h"
15
+ #include "geometry_collection.h"
16
+ #include "globals.h"
21
17
  #include "line_string.h"
18
+ #include "point.h"
22
19
  #include "polygon.h"
23
- #include "geometry_collection.h"
24
- #include "errors.h"
20
+ #include "ruby_more.h"
25
21
 
26
22
  RGEO_BEGIN_C
27
23
 
28
-
29
24
  /**** RUBY AND GEOS CALLBACKS ****/
30
25
 
31
-
32
- // The notice handler is very rarely used by GEOS, only in
33
- // GEOSIsValid_r (check for NOTICE_MESSAGE in GEOS codebase).
34
- // We still set it to make sure we do not miss any implementation
35
- // change. Use `DEBUG=1 rake` to show notice.
36
- #ifdef RGEO_GEOS_DEBUG
37
- static void notice_handler(const char* fmt, ...)
38
- {
39
- va_list args;
40
- va_start(args, fmt);
41
- fprintf(stderr, "GEOS Notice -- ");
42
- vfprintf(stderr, fmt, args);
43
- fprintf(stderr, "\n");
44
- va_end(args);
45
- }
46
- #endif
47
-
48
- static void error_handler(const char* fmt, ...)
49
- {
50
- // See https://en.cppreference.com/w/c/io/vfprintf
51
- va_list args1;
52
- va_start(args1, fmt);
53
- va_list args2;
54
- va_copy(args2, args1);
55
- int size = 1+vsnprintf(NULL, 0, fmt, args1);
56
- va_end(args1);
57
- char geos_full_error[size];
58
- vsnprintf(geos_full_error, sizeof geos_full_error, fmt, args2);
59
- va_end(args2);
60
-
61
- // NOTE: strtok is destructive, geos_full_error is not to be used afterwards.
62
- char *geos_error = strtok(geos_full_error, ":");
63
- char *geos_message = strtok(NULL, ":");
64
- while(isspace(*geos_message)) geos_message++;
65
-
66
- if (streq(geos_error, "UnsupportedOperationException")) {
67
- rb_raise(rb_eRGeoUnsupportedOperation, "%s", geos_message);
68
- } else if (streq(geos_error, "IllegalArgumentException")) {
69
- rb_raise(rb_eRGeoInvalidGeometry, "%s", geos_message);
70
- } else if (geos_message) {
71
- rb_raise(rb_eGeosError, "%s: %s", geos_error, geos_message);
72
- } else {
73
- rb_raise(rb_eGeosError, "%s", geos_error);
74
- }
75
- }
76
-
77
26
  // Destroy function for factory data. We destroy any serialization
78
- // objects that have been created for the factory, and then destroy
79
- // the GEOS context, before freeing the factory data itself.
27
+ // objects that have been created for the factory before freeing
28
+ // the factory data itself.
80
29
 
81
- static void destroy_factory_func(void* data)
30
+ static void
31
+ destroy_factory_func(void* data)
82
32
  {
83
33
  RGeo_FactoryData* factory_data;
84
- GEOSContextHandle_t context;
85
34
 
86
35
  factory_data = (RGeo_FactoryData*)data;
87
- context = factory_data->geos_context;
88
36
  if (factory_data->wkt_reader) {
89
- GEOSWKTReader_destroy_r(context, factory_data->wkt_reader);
37
+ GEOSWKTReader_destroy(factory_data->wkt_reader);
90
38
  }
91
39
  if (factory_data->wkb_reader) {
92
- GEOSWKBReader_destroy_r(context, factory_data->wkb_reader);
40
+ GEOSWKBReader_destroy(factory_data->wkb_reader);
93
41
  }
94
42
  if (factory_data->wkt_writer) {
95
- GEOSWKTWriter_destroy_r(context, factory_data->wkt_writer);
43
+ GEOSWKTWriter_destroy(factory_data->wkt_writer);
96
44
  }
97
45
  if (factory_data->wkb_writer) {
98
- GEOSWKBWriter_destroy_r(context, factory_data->wkb_writer);
46
+ GEOSWKBWriter_destroy(factory_data->wkb_writer);
99
47
  }
100
48
  if (factory_data->psych_wkt_reader) {
101
- GEOSWKTReader_destroy_r(context, factory_data->psych_wkt_reader);
49
+ GEOSWKTReader_destroy(factory_data->psych_wkt_reader);
102
50
  }
103
51
  if (factory_data->marshal_wkb_reader) {
104
- GEOSWKBReader_destroy_r(context, factory_data->marshal_wkb_reader);
52
+ GEOSWKBReader_destroy(factory_data->marshal_wkb_reader);
105
53
  }
106
54
  if (factory_data->psych_wkt_writer) {
107
- GEOSWKTWriter_destroy_r(context, factory_data->psych_wkt_writer);
55
+ GEOSWKTWriter_destroy(factory_data->psych_wkt_writer);
108
56
  }
109
57
  if (factory_data->marshal_wkb_writer) {
110
- GEOSWKBWriter_destroy_r(context, factory_data->marshal_wkb_writer);
58
+ GEOSWKBWriter_destroy(factory_data->marshal_wkb_writer);
111
59
  }
112
- finishGEOS_r(context);
113
- free(factory_data);
60
+ FREE(factory_data);
114
61
  }
115
62
 
116
-
117
63
  // Destroy function for geometry data. We destroy the internal
118
64
  // GEOS geometry (if present) before freeing the data itself.
119
65
 
120
- static void destroy_geometry_func(void* data)
66
+ static void
67
+ destroy_geometry_func(void* data)
121
68
  {
122
69
  RGeo_GeometryData* geometry_data;
123
70
  const GEOSPreparedGeometry* prep;
124
71
 
125
72
  geometry_data = (RGeo_GeometryData*)data;
126
73
  if (geometry_data->geom) {
127
- GEOSGeom_destroy_r(geometry_data->geos_context, geometry_data->geom);
74
+ GEOSGeom_destroy(geometry_data->geom);
128
75
  }
129
76
  prep = geometry_data->prep;
130
- if (prep && prep != (const GEOSPreparedGeometry*)1 && prep != (const GEOSPreparedGeometry*)2 &&
131
- prep != (const GEOSPreparedGeometry*)3)
132
- {
133
- GEOSPreparedGeom_destroy_r(geometry_data->geos_context, prep);
77
+ if (prep && prep != (const GEOSPreparedGeometry*)1 &&
78
+ prep != (const GEOSPreparedGeometry*)2 &&
79
+ prep != (const GEOSPreparedGeometry*)3) {
80
+ GEOSPreparedGeom_destroy(prep);
134
81
  }
135
- free(geometry_data);
82
+ FREE(geometry_data);
136
83
  }
137
84
 
138
-
139
85
  // Mark function for factory data. This marks the wkt and wkb generator
140
86
  // handles so they don't get collected.
141
87
 
142
- static void mark_factory_func(void* data)
88
+ static void
89
+ mark_factory_func(void* data)
143
90
  {
144
91
  RGeo_FactoryData* factory_data;
145
92
 
@@ -156,19 +103,16 @@ static void mark_factory_func(void* data)
156
103
  if (!NIL_P(factory_data->wkrep_wkb_parser)) {
157
104
  mark(factory_data->wkrep_wkb_parser);
158
105
  }
159
- if (!NIL_P(factory_data->proj4_obj)) {
160
- mark(factory_data->proj4_obj);
161
- }
162
106
  if (!NIL_P(factory_data->coord_sys_obj)) {
163
107
  mark(factory_data->coord_sys_obj);
164
108
  }
165
109
  }
166
110
 
167
-
168
111
  // Mark function for geometry data. This marks the factory and klasses
169
112
  // held by the geometry so those don't get collected.
170
113
 
171
- static void mark_geometry_func(void* data)
114
+ static void
115
+ mark_geometry_func(void* data)
172
116
  {
173
117
  RGeo_GeometryData* geometry_data;
174
118
 
@@ -181,35 +125,36 @@ static void mark_geometry_func(void* data)
181
125
  }
182
126
  }
183
127
 
184
-
185
128
  #ifdef HAVE_RB_GC_MARK_MOVABLE
186
- static void compact_factory_func(void* data)
129
+ static void
130
+ compact_factory_func(void* data)
187
131
  {
188
132
  RGeo_FactoryData* factory_data;
189
133
 
190
134
  factory_data = (RGeo_FactoryData*)data;
191
135
  if (!NIL_P(factory_data->wkrep_wkt_generator)) {
192
- factory_data->wkrep_wkt_generator = rb_gc_location(factory_data->wkrep_wkt_generator);
136
+ factory_data->wkrep_wkt_generator =
137
+ rb_gc_location(factory_data->wkrep_wkt_generator);
193
138
  }
194
139
  if (!NIL_P(factory_data->wkrep_wkb_generator)) {
195
- factory_data->wkrep_wkb_generator = rb_gc_location(factory_data->wkrep_wkb_generator);
140
+ factory_data->wkrep_wkb_generator =
141
+ rb_gc_location(factory_data->wkrep_wkb_generator);
196
142
  }
197
143
  if (!NIL_P(factory_data->wkrep_wkt_parser)) {
198
- factory_data->wkrep_wkt_parser = rb_gc_location(factory_data->wkrep_wkt_parser);
144
+ factory_data->wkrep_wkt_parser =
145
+ rb_gc_location(factory_data->wkrep_wkt_parser);
199
146
  }
200
147
  if (!NIL_P(factory_data->wkrep_wkb_parser)) {
201
- factory_data->wkrep_wkb_parser = rb_gc_location(factory_data->wkrep_wkb_parser);
202
- }
203
- if (!NIL_P(factory_data->proj4_obj)) {
204
- factory_data->proj4_obj = rb_gc_location(factory_data->proj4_obj);
148
+ factory_data->wkrep_wkb_parser =
149
+ rb_gc_location(factory_data->wkrep_wkb_parser);
205
150
  }
206
151
  if (!NIL_P(factory_data->coord_sys_obj)) {
207
152
  factory_data->coord_sys_obj = rb_gc_location(factory_data->coord_sys_obj);
208
153
  }
209
154
  }
210
155
 
211
-
212
- static void compact_geometry_func(void* data)
156
+ static void
157
+ compact_geometry_func(void* data)
213
158
  {
214
159
  RGeo_GeometryData* geometry_data;
215
160
 
@@ -223,89 +168,95 @@ static void compact_geometry_func(void* data)
223
168
  }
224
169
  #endif
225
170
 
226
-
227
- const rb_data_type_t rgeo_factory_type = {
228
- .wrap_struct_name = "RGeo/Factory",
229
- .function = {
230
- .dmark = mark_factory_func,
231
- .dfree = destroy_factory_func,
171
+ const rb_data_type_t rgeo_factory_type = { .wrap_struct_name = "RGeo/Factory",
172
+ .function = {
173
+ .dmark = mark_factory_func,
174
+ .dfree = destroy_factory_func,
232
175
  #ifdef HAVE_RB_GC_MARK_MOVABLE
233
- .dcompact = compact_factory_func,
176
+ .dcompact = compact_factory_func,
234
177
  #endif
235
- }
236
- };
178
+ } };
237
179
 
238
- const rb_data_type_t rgeo_geometry_type = {
239
- .wrap_struct_name = "RGeo/Geometry",
240
- .function = {
241
- .dmark = mark_geometry_func,
242
- .dfree = destroy_geometry_func,
180
+ const rb_data_type_t rgeo_geometry_type = { .wrap_struct_name = "RGeo/Geometry",
181
+ .function = {
182
+ .dmark = mark_geometry_func,
183
+ .dfree = destroy_geometry_func,
243
184
  #ifdef HAVE_RB_GC_MARK_MOVABLE
244
- .dcompact = compact_geometry_func,
185
+ .dcompact = compact_geometry_func,
245
186
  #endif
246
- }
247
- };
248
-
187
+ } };
249
188
 
250
189
  /**** RUBY METHOD DEFINITIONS ****/
251
190
 
252
-
253
- static VALUE method_factory_srid(VALUE self)
191
+ static VALUE
192
+ method_factory_srid(VALUE self)
254
193
  {
255
194
  return INT2NUM(RGEO_FACTORY_DATA_PTR(self)->srid);
256
195
  }
257
196
 
258
-
259
- static VALUE method_factory_buffer_resolution(VALUE self)
197
+ static VALUE
198
+ method_factory_buffer_resolution(VALUE self)
260
199
  {
261
200
  return INT2NUM(RGEO_FACTORY_DATA_PTR(self)->buffer_resolution);
262
201
  }
263
202
 
264
-
265
- static VALUE method_factory_flags(VALUE self)
203
+ static VALUE
204
+ method_factory_flags(VALUE self)
266
205
  {
267
206
  return INT2NUM(RGEO_FACTORY_DATA_PTR(self)->flags);
268
207
  }
269
208
 
270
- VALUE method_factory_supports_z_p(VALUE self)
209
+ VALUE
210
+ method_factory_supports_z_p(VALUE self)
271
211
  {
272
- return RGEO_FACTORY_DATA_PTR(self)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z ? Qtrue : Qfalse;
212
+ return RGEO_FACTORY_DATA_PTR(self)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z
213
+ ? Qtrue
214
+ : Qfalse;
273
215
  }
274
216
 
275
- VALUE method_factory_supports_m_p(VALUE self)
217
+ VALUE
218
+ method_factory_supports_m_p(VALUE self)
276
219
  {
277
- return RGEO_FACTORY_DATA_PTR(self)->flags & RGEO_FACTORYFLAGS_SUPPORTS_M ? Qtrue : Qfalse;
220
+ return RGEO_FACTORY_DATA_PTR(self)->flags & RGEO_FACTORYFLAGS_SUPPORTS_M
221
+ ? Qtrue
222
+ : Qfalse;
278
223
  }
279
224
 
280
- VALUE method_factory_supports_z_or_m_p(VALUE self)
225
+ VALUE
226
+ method_factory_supports_z_or_m_p(VALUE self)
281
227
  {
282
- return RGEO_FACTORY_DATA_PTR(self)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M ? Qtrue : Qfalse;
228
+ return RGEO_FACTORY_DATA_PTR(self)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M
229
+ ? Qtrue
230
+ : Qfalse;
283
231
  }
284
232
 
285
- VALUE method_factory_prepare_heuristic_p(VALUE self)
233
+ VALUE
234
+ method_factory_prepare_heuristic_p(VALUE self)
286
235
  {
287
- return RGEO_FACTORY_DATA_PTR(self)->flags & RGEO_FACTORYFLAGS_PREPARE_HEURISTIC ? Qtrue : Qfalse;
236
+ return RGEO_FACTORY_DATA_PTR(self)->flags &
237
+ RGEO_FACTORYFLAGS_PREPARE_HEURISTIC
238
+ ? Qtrue
239
+ : Qfalse;
288
240
  }
289
241
 
290
- static VALUE method_factory_parse_wkt(VALUE self, VALUE str)
242
+ static VALUE
243
+ method_factory_parse_wkt(VALUE self, VALUE str)
291
244
  {
292
245
  RGeo_FactoryData* self_data;
293
- GEOSContextHandle_t self_context;
294
246
  GEOSWKTReader* wkt_reader;
295
247
  VALUE result;
296
248
  GEOSGeometry* geom;
297
249
 
298
250
  Check_Type(str, T_STRING);
299
251
  self_data = RGEO_FACTORY_DATA_PTR(self);
300
- self_context = self_data->geos_context;
301
252
  wkt_reader = self_data->wkt_reader;
302
253
  if (!wkt_reader) {
303
- wkt_reader = GEOSWKTReader_create_r(self_context);
254
+ wkt_reader = GEOSWKTReader_create();
304
255
  self_data->wkt_reader = wkt_reader;
305
256
  }
306
257
  result = Qnil;
307
258
  if (wkt_reader) {
308
- geom = GEOSWKTReader_read_r(self_context, wkt_reader, RSTRING_PTR(str));
259
+ geom = GEOSWKTReader_read(wkt_reader, RSTRING_PTR(str));
309
260
  if (geom) {
310
261
  result = rgeo_wrap_geos_geometry(self, geom, Qnil);
311
262
  }
@@ -313,26 +264,31 @@ static VALUE method_factory_parse_wkt(VALUE self, VALUE str)
313
264
  return result;
314
265
  }
315
266
 
316
-
317
- static VALUE method_factory_parse_wkb(VALUE self, VALUE str)
267
+ static VALUE
268
+ method_factory_parse_wkb(VALUE self, VALUE str)
318
269
  {
319
270
  RGeo_FactoryData* self_data;
320
- GEOSContextHandle_t self_context;
321
271
  GEOSWKBReader* wkb_reader;
322
272
  VALUE result;
323
273
  GEOSGeometry* geom;
274
+ char* c_str;
324
275
 
325
276
  Check_Type(str, T_STRING);
326
277
  self_data = RGEO_FACTORY_DATA_PTR(self);
327
- self_context = self_data->geos_context;
328
278
  wkb_reader = self_data->wkb_reader;
329
279
  if (!wkb_reader) {
330
- wkb_reader = GEOSWKBReader_create_r(self_context);
280
+ wkb_reader = GEOSWKBReader_create();
331
281
  self_data->wkb_reader = wkb_reader;
332
282
  }
333
283
  result = Qnil;
334
284
  if (wkb_reader) {
335
- geom = GEOSWKBReader_read_r(self_context, wkb_reader, (unsigned char*)RSTRING_PTR(str), (size_t)RSTRING_LEN(str));
285
+ c_str = RSTRING_PTR(str);
286
+ if (c_str[0] == '\x00' || c_str[0] == '\x01')
287
+ geom = GEOSWKBReader_read(
288
+ wkb_reader, (unsigned char*)c_str, (size_t)RSTRING_LEN(str));
289
+ else
290
+ geom = GEOSWKBReader_readHEX(
291
+ wkb_reader, (unsigned char*)c_str, (size_t)RSTRING_LEN(str));
336
292
  if (geom) {
337
293
  result = rgeo_wrap_geos_geometry(self, geom, Qnil);
338
294
  }
@@ -340,26 +296,25 @@ static VALUE method_factory_parse_wkb(VALUE self, VALUE str)
340
296
  return result;
341
297
  }
342
298
 
343
-
344
- static VALUE method_factory_read_for_marshal(VALUE self, VALUE str)
299
+ static VALUE
300
+ method_factory_read_for_marshal(VALUE self, VALUE str)
345
301
  {
346
302
  RGeo_FactoryData* self_data;
347
- GEOSContextHandle_t self_context;
348
303
  GEOSWKBReader* wkb_reader;
349
304
  VALUE result;
350
305
  GEOSGeometry* geom;
351
306
 
352
307
  Check_Type(str, T_STRING);
353
308
  self_data = RGEO_FACTORY_DATA_PTR(self);
354
- self_context = self_data->geos_context;
355
309
  wkb_reader = self_data->marshal_wkb_reader;
356
310
  if (!wkb_reader) {
357
- wkb_reader = GEOSWKBReader_create_r(self_context);
311
+ wkb_reader = GEOSWKBReader_create();
358
312
  self_data->marshal_wkb_reader = wkb_reader;
359
313
  }
360
314
  result = Qnil;
361
315
  if (wkb_reader) {
362
- geom = GEOSWKBReader_read_r(self_context, wkb_reader, (unsigned char*)RSTRING_PTR(str), (size_t)RSTRING_LEN(str));
316
+ geom = GEOSWKBReader_read(
317
+ wkb_reader, (unsigned char*)RSTRING_PTR(str), (size_t)RSTRING_LEN(str));
363
318
  if (geom) {
364
319
  result = rgeo_wrap_geos_geometry(self, geom, Qnil);
365
320
  }
@@ -367,25 +322,24 @@ static VALUE method_factory_read_for_marshal(VALUE self, VALUE str)
367
322
  return result;
368
323
  }
369
324
 
370
- static VALUE method_factory_read_for_psych(VALUE self, VALUE str)
325
+ static VALUE
326
+ method_factory_read_for_psych(VALUE self, VALUE str)
371
327
  {
372
328
  RGeo_FactoryData* self_data;
373
- GEOSContextHandle_t self_context;
374
329
  GEOSWKTReader* wkt_reader;
375
330
  VALUE result;
376
331
  GEOSGeometry* geom;
377
332
 
378
333
  Check_Type(str, T_STRING);
379
334
  self_data = RGEO_FACTORY_DATA_PTR(self);
380
- self_context = self_data->geos_context;
381
335
  wkt_reader = self_data->psych_wkt_reader;
382
336
  if (!wkt_reader) {
383
- wkt_reader = GEOSWKTReader_create_r(self_context);
337
+ wkt_reader = GEOSWKTReader_create();
384
338
  self_data->psych_wkt_reader = wkt_reader;
385
339
  }
386
340
  result = Qnil;
387
341
  if (wkt_reader) {
388
- geom = GEOSWKTReader_read_r(self_context, wkt_reader, RSTRING_PTR(str));
342
+ geom = GEOSWKTReader_read(wkt_reader, RSTRING_PTR(str));
389
343
  if (geom) {
390
344
  result = rgeo_wrap_geos_geometry(self, geom, Qnil);
391
345
  }
@@ -397,10 +351,10 @@ static VALUE method_factory_read_for_psych(VALUE self, VALUE str)
397
351
  static VALUE marshal_wkb_generator;
398
352
  #endif
399
353
 
400
- static VALUE method_factory_write_for_marshal(VALUE self, VALUE obj)
354
+ static VALUE
355
+ method_factory_write_for_marshal(VALUE self, VALUE obj)
401
356
  {
402
357
  RGeo_FactoryData* self_data;
403
- GEOSContextHandle_t self_context;
404
358
  GEOSWKBWriter* wkb_writer;
405
359
  const GEOSGeometry* geom;
406
360
  VALUE result;
@@ -409,23 +363,23 @@ static VALUE method_factory_write_for_marshal(VALUE self, VALUE obj)
409
363
  char has_3d;
410
364
 
411
365
  self_data = RGEO_FACTORY_DATA_PTR(self);
412
- self_context = self_data->geos_context;
413
366
  has_3d = self_data->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
414
367
  #ifndef RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
415
368
  if (has_3d) {
416
369
  if (NIL_P(marshal_wkb_generator)) {
417
- marshal_wkb_generator = rb_funcall(
418
- rb_const_get_at(rgeo_geos_module, rb_intern("Utils")),
419
- rb_intern("marshal_wkb_generator"), 0);
370
+ marshal_wkb_generator =
371
+ rb_funcall(rb_const_get_at(rgeo_geos_module, rb_intern("Utils")),
372
+ rb_intern("marshal_wkb_generator"),
373
+ 0);
420
374
  }
421
375
  return rb_funcall(marshal_wkb_generator, rb_intern("generate"), 1, obj);
422
376
  }
423
377
  #endif
424
378
  wkb_writer = self_data->marshal_wkb_writer;
425
379
  if (!wkb_writer) {
426
- wkb_writer = GEOSWKBWriter_create_r(self_context);
380
+ wkb_writer = GEOSWKBWriter_create();
427
381
  if (has_3d) {
428
- GEOSWKBWriter_setOutputDimension_r(self_context, wkb_writer, 3);
382
+ GEOSWKBWriter_setOutputDimension(wkb_writer, 3);
429
383
  }
430
384
  self_data->marshal_wkb_writer = wkb_writer;
431
385
  }
@@ -433,10 +387,10 @@ static VALUE method_factory_write_for_marshal(VALUE self, VALUE obj)
433
387
  if (wkb_writer) {
434
388
  geom = rgeo_get_geos_geometry_safe(obj);
435
389
  if (geom) {
436
- str = (char*)GEOSWKBWriter_write_r(self_context, wkb_writer, geom, &size);
390
+ str = (char*)GEOSWKBWriter_write(wkb_writer, geom, &size);
437
391
  if (str) {
438
392
  result = rb_str_new(str, size);
439
- GEOSFree_r(self_context, str);
393
+ GEOSFree(str);
440
394
  }
441
395
  }
442
396
  }
@@ -447,10 +401,10 @@ static VALUE method_factory_write_for_marshal(VALUE self, VALUE obj)
447
401
  static VALUE psych_wkt_generator;
448
402
  #endif
449
403
 
450
- static VALUE method_factory_write_for_psych(VALUE self, VALUE obj)
404
+ static VALUE
405
+ method_factory_write_for_psych(VALUE self, VALUE obj)
451
406
  {
452
407
  RGeo_FactoryData* self_data;
453
- GEOSContextHandle_t self_context;
454
408
  GEOSWKTWriter* wkt_writer;
455
409
  const GEOSGeometry* geom;
456
410
  VALUE result;
@@ -458,23 +412,24 @@ static VALUE method_factory_write_for_psych(VALUE self, VALUE obj)
458
412
  char has_3d;
459
413
 
460
414
  self_data = RGEO_FACTORY_DATA_PTR(self);
461
- self_context = self_data->geos_context;
462
415
  has_3d = self_data->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
463
416
  #ifndef RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
464
417
  if (has_3d) {
465
418
  if (NIL_P(psych_wkt_generator)) {
466
- psych_wkt_generator = rb_funcall(
467
- rb_const_get_at(rgeo_geos_module, rb_intern("Utils")),
468
- rb_intern("psych_wkt_generator"), 0);
419
+ psych_wkt_generator =
420
+ rb_funcall(rb_const_get_at(rgeo_geos_module, rb_intern("Utils")),
421
+ rb_intern("psych_wkt_generator"),
422
+ 0);
469
423
  }
470
424
  return rb_funcall(psych_wkt_generator, rb_intern("generate"), 1, obj);
471
425
  }
472
426
  #endif
473
427
  wkt_writer = self_data->psych_wkt_writer;
474
428
  if (!wkt_writer) {
475
- wkt_writer = GEOSWKTWriter_create_r(self_context);
429
+ wkt_writer = GEOSWKTWriter_create();
430
+ GEOSWKTWriter_setTrim(wkt_writer, 1);
476
431
  if (has_3d) {
477
- GEOSWKTWriter_setOutputDimension_r(self_context, wkt_writer, 3);
432
+ GEOSWKTWriter_setOutputDimension(wkt_writer, 3);
478
433
  }
479
434
  self_data->psych_wkt_writer = wkt_writer;
480
435
  }
@@ -482,24 +437,24 @@ static VALUE method_factory_write_for_psych(VALUE self, VALUE obj)
482
437
  if (wkt_writer) {
483
438
  geom = rgeo_get_geos_geometry_safe(obj);
484
439
  if (geom) {
485
- str = GEOSWKTWriter_write_r(self_context, wkt_writer, geom);
440
+ str = GEOSWKTWriter_write(wkt_writer, geom);
486
441
  if (str) {
487
442
  result = rb_str_new2(str);
488
- GEOSFree_r(self_context, str);
443
+ GEOSFree(str);
489
444
  }
490
445
  }
491
446
  }
492
447
  return result;
493
448
  }
494
449
 
495
-
496
- static VALUE cmethod_factory_geos_version(VALUE klass)
450
+ static VALUE
451
+ cmethod_factory_geos_version(VALUE klass)
497
452
  {
498
453
  return rb_str_new2(GEOS_VERSION);
499
454
  }
500
455
 
501
-
502
- static VALUE cmethod_factory_supports_unary_union(VALUE klass)
456
+ static VALUE
457
+ cmethod_factory_supports_unary_union(VALUE klass)
503
458
  {
504
459
  #ifdef RGEO_GEOS_SUPPORTS_UNARYUNION
505
460
  return Qtrue;
@@ -508,103 +463,93 @@ static VALUE cmethod_factory_supports_unary_union(VALUE klass)
508
463
  #endif
509
464
  }
510
465
 
511
- static VALUE cmethod_factory_create(VALUE klass, VALUE flags, VALUE srid, VALUE buffer_resolution,
512
- VALUE wkt_generator, VALUE wkb_generator, VALUE proj4_obj, VALUE coord_sys_obj)
466
+ static VALUE
467
+ cmethod_factory_create(VALUE klass,
468
+ VALUE flags,
469
+ VALUE srid,
470
+ VALUE buffer_resolution,
471
+ VALUE wkt_generator,
472
+ VALUE wkb_generator,
473
+ VALUE coord_sys_obj)
513
474
  {
514
475
  VALUE result;
515
476
  RGeo_FactoryData* data;
516
- GEOSContextHandle_t context;
517
477
 
518
478
  result = Qnil;
519
479
  data = ALLOC(RGeo_FactoryData);
520
480
  if (data) {
521
- context = GEOS_init_r();
522
- #ifdef RGEO_GEOS_DEBUG
523
- GEOSContext_setNoticeHandler_r(context, notice_handler);
524
- #endif
525
- GEOSContext_setErrorHandler_r(context, error_handler);
526
-
527
- if (context) {
528
- data->geos_context = context;
529
- data->flags = NUM2INT(flags);
530
- data->srid = NUM2INT(srid);
531
- data->buffer_resolution = NUM2INT(buffer_resolution);
532
- data->wkt_reader = NULL;
533
- data->wkb_reader = NULL;
534
- data->wkt_writer = NULL;
535
- data->wkb_writer = NULL;
536
- data->psych_wkt_reader = NULL;
537
- data->marshal_wkb_reader = NULL;
538
- data->psych_wkt_writer = NULL;
539
- data->marshal_wkb_writer = NULL;
540
- data->wkrep_wkt_generator = wkt_generator;
541
- data->wkrep_wkb_generator = wkb_generator;
542
- data->wkrep_wkt_parser = Qnil;
543
- data->wkrep_wkb_parser = Qnil;
544
- data->proj4_obj = proj4_obj;
545
- data->coord_sys_obj = coord_sys_obj;
546
- result = TypedData_Wrap_Struct(klass, &rgeo_factory_type, data);
547
- }
548
- else {
549
- free(data);
550
- }
481
+ data->flags = RB_NUM2INT(flags);
482
+ data->srid = RB_NUM2INT(srid);
483
+ data->buffer_resolution = RB_NUM2INT(buffer_resolution);
484
+ data->wkt_reader = NULL;
485
+ data->wkb_reader = NULL;
486
+ data->wkt_writer = NULL;
487
+ data->wkb_writer = NULL;
488
+ data->psych_wkt_reader = NULL;
489
+ data->marshal_wkb_reader = NULL;
490
+ data->psych_wkt_writer = NULL;
491
+ data->marshal_wkb_writer = NULL;
492
+ data->wkrep_wkt_generator = wkt_generator;
493
+ data->wkrep_wkb_generator = wkb_generator;
494
+ data->wkrep_wkt_parser = Qnil;
495
+ data->wkrep_wkb_parser = Qnil;
496
+ data->coord_sys_obj = coord_sys_obj;
497
+ result = TypedData_Wrap_Struct(klass, &rgeo_factory_type, data);
551
498
  }
552
499
  return result;
553
500
  }
554
501
 
555
-
556
- static VALUE alloc_factory(VALUE klass)
502
+ static VALUE
503
+ alloc_factory(VALUE klass)
557
504
  {
558
- return cmethod_factory_create(klass, INT2NUM(0), INT2NUM(0), INT2NUM(0), Qnil, Qnil, Qnil, Qnil);
505
+ return cmethod_factory_create(
506
+ klass, INT2NUM(0), INT2NUM(0), INT2NUM(0), Qnil, Qnil, Qnil);
559
507
  }
560
508
 
561
-
562
- static VALUE method_factory_initialize_copy(VALUE self, VALUE orig)
509
+ static VALUE
510
+ method_factory_initialize_copy(VALUE self, VALUE orig)
563
511
  {
564
512
  RGeo_FactoryData* self_data;
565
513
  RGeo_FactoryData* orig_data;
566
- GEOSContextHandle_t context;
567
514
 
568
515
  // Clear out existing data
569
516
  self_data = RGEO_FACTORY_DATA_PTR(self);
570
- context = self_data->geos_context;
571
517
  if (self_data->wkt_reader) {
572
- GEOSWKTReader_destroy_r(context, self_data->wkt_reader);
518
+ GEOSWKTReader_destroy(self_data->wkt_reader);
573
519
  self_data->wkt_reader = NULL;
574
520
  }
575
521
  if (self_data->wkb_reader) {
576
- GEOSWKBReader_destroy_r(context, self_data->wkb_reader);
522
+ GEOSWKBReader_destroy(self_data->wkb_reader);
577
523
  self_data->wkb_reader = NULL;
578
524
  }
579
525
  if (self_data->wkt_writer) {
580
- GEOSWKTWriter_destroy_r(context, self_data->wkt_writer);
526
+ GEOSWKTWriter_destroy(self_data->wkt_writer);
581
527
  self_data->wkt_writer = NULL;
582
528
  }
583
529
  if (self_data->wkb_writer) {
584
- GEOSWKBWriter_destroy_r(context, self_data->wkb_writer);
530
+ GEOSWKBWriter_destroy(self_data->wkb_writer);
585
531
  self_data->wkb_writer = NULL;
586
532
  }
587
533
  if (self_data->psych_wkt_reader) {
588
- GEOSWKTReader_destroy_r(context, self_data->psych_wkt_reader);
534
+ GEOSWKTReader_destroy(self_data->psych_wkt_reader);
589
535
  self_data->psych_wkt_reader = NULL;
590
536
  }
591
537
  if (self_data->marshal_wkb_reader) {
592
- GEOSWKBReader_destroy_r(context, self_data->marshal_wkb_reader);
538
+ GEOSWKBReader_destroy(self_data->marshal_wkb_reader);
593
539
  self_data->marshal_wkb_reader = NULL;
594
540
  }
595
541
  if (self_data->psych_wkt_writer) {
596
- GEOSWKTWriter_destroy_r(context, self_data->psych_wkt_writer);
542
+ GEOSWKTWriter_destroy(self_data->psych_wkt_writer);
597
543
  self_data->psych_wkt_writer = NULL;
598
544
  }
599
545
  if (self_data->marshal_wkb_writer) {
600
- GEOSWKBWriter_destroy_r(context, self_data->marshal_wkb_writer);
546
+ GEOSWKBWriter_destroy(self_data->marshal_wkb_writer);
601
547
  self_data->marshal_wkb_writer = NULL;
602
548
  }
603
549
  self_data->wkrep_wkt_generator = Qnil;
604
550
  self_data->wkrep_wkb_generator = Qnil;
605
551
  self_data->wkrep_wkt_parser = Qnil;
606
552
  self_data->wkrep_wkb_parser = Qnil;
607
- self_data->proj4_obj = Qnil;
608
553
  self_data->coord_sys_obj = Qnil;
609
554
 
610
555
  // Copy new data from original object
@@ -617,14 +562,13 @@ static VALUE method_factory_initialize_copy(VALUE self, VALUE orig)
617
562
  self_data->wkrep_wkb_generator = orig_data->wkrep_wkb_generator;
618
563
  self_data->wkrep_wkt_parser = orig_data->wkrep_wkt_parser;
619
564
  self_data->wkrep_wkb_parser = orig_data->wkrep_wkb_parser;
620
- self_data->proj4_obj = orig_data->proj4_obj;
621
565
  self_data->coord_sys_obj = orig_data->coord_sys_obj;
622
566
  }
623
567
  return self;
624
568
  }
625
569
 
626
-
627
- static VALUE method_set_wkrep_parsers(VALUE self, VALUE wkt_parser, VALUE wkb_parser)
570
+ static VALUE
571
+ method_set_wkrep_parsers(VALUE self, VALUE wkt_parser, VALUE wkb_parser)
628
572
  {
629
573
  RGeo_FactoryData* self_data;
630
574
 
@@ -635,96 +579,126 @@ static VALUE method_set_wkrep_parsers(VALUE self, VALUE wkt_parser, VALUE wkb_pa
635
579
  return self;
636
580
  }
637
581
 
638
-
639
- static VALUE method_get_proj4(VALUE self)
640
- {
641
- return RGEO_FACTORY_DATA_PTR(self)->proj4_obj;
642
- }
643
-
644
-
645
- static VALUE method_get_coord_sys(VALUE self)
582
+ static VALUE
583
+ method_get_coord_sys(VALUE self)
646
584
  {
647
585
  return RGEO_FACTORY_DATA_PTR(self)->coord_sys_obj;
648
586
  }
649
587
 
650
-
651
- static VALUE method_get_wkt_generator(VALUE self)
588
+ static VALUE
589
+ method_get_wkt_generator(VALUE self)
652
590
  {
653
591
  return RGEO_FACTORY_DATA_PTR(self)->wkrep_wkt_generator;
654
592
  }
655
593
 
656
-
657
- static VALUE method_get_wkb_generator(VALUE self)
594
+ static VALUE
595
+ method_get_wkb_generator(VALUE self)
658
596
  {
659
597
  return RGEO_FACTORY_DATA_PTR(self)->wkrep_wkb_generator;
660
598
  }
661
599
 
662
-
663
- static VALUE method_get_wkt_parser(VALUE self)
600
+ static VALUE
601
+ method_get_wkt_parser(VALUE self)
664
602
  {
665
603
  return RGEO_FACTORY_DATA_PTR(self)->wkrep_wkt_parser;
666
604
  }
667
605
 
668
-
669
- static VALUE method_get_wkb_parser(VALUE self)
606
+ static VALUE
607
+ method_get_wkb_parser(VALUE self)
670
608
  {
671
609
  return RGEO_FACTORY_DATA_PTR(self)->wkrep_wkb_parser;
672
610
  }
673
611
 
674
-
675
- static VALUE alloc_geometry(VALUE klass)
612
+ static VALUE
613
+ alloc_geometry(VALUE klass)
676
614
  {
677
615
  return rgeo_wrap_geos_geometry(Qnil, NULL, klass);
678
616
  }
679
617
 
680
-
681
618
  /**** INITIALIZATION FUNCTION ****/
682
619
 
683
-
684
- void rgeo_init_geos_factory()
620
+ void
621
+ rgeo_init_geos_factory()
685
622
  {
686
623
  VALUE geos_factory_class;
687
624
 
688
625
  #ifndef RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
689
- /* We favor rb_gc_register_address over rb_gc_register_mark_object because the value changes at runtime */
626
+ /* We favor rb_gc_register_address over rb_gc_register_mark_object because
627
+ * the value changes at runtime */
690
628
  psych_wkt_generator = Qnil;
691
629
  rb_gc_register_address(&psych_wkt_generator);
692
630
  marshal_wkb_generator = Qnil;
693
631
  rb_gc_register_address(&marshal_wkb_generator);
694
632
  #endif
695
633
 
696
- geos_factory_class = rb_define_class_under(rgeo_geos_module, "CAPIFactory", rb_cObject);
634
+ geos_factory_class =
635
+ rb_define_class_under(rgeo_geos_module, "CAPIFactory", rb_cObject);
697
636
  rb_define_alloc_func(geos_factory_class, alloc_factory);
698
637
  // Add C constants to the factory.
699
- rb_define_const(geos_factory_class, "FLAG_SUPPORTS_Z", INT2FIX(RGEO_FACTORYFLAGS_SUPPORTS_Z));
700
- rb_define_const(geos_factory_class, "FLAG_SUPPORTS_M", INT2FIX(RGEO_FACTORYFLAGS_SUPPORTS_M));
701
- rb_define_const(geos_factory_class, "FLAG_SUPPORTS_Z_OR_M", INT2FIX(RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M));
702
- rb_define_const(geos_factory_class, "FLAG_PREPARE_HEURISTIC", INT2FIX(RGEO_FACTORYFLAGS_PREPARE_HEURISTIC));
638
+ rb_define_const(geos_factory_class,
639
+ "FLAG_SUPPORTS_Z",
640
+ INT2FIX(RGEO_FACTORYFLAGS_SUPPORTS_Z));
641
+ rb_define_const(geos_factory_class,
642
+ "FLAG_SUPPORTS_M",
643
+ INT2FIX(RGEO_FACTORYFLAGS_SUPPORTS_M));
644
+ rb_define_const(geos_factory_class,
645
+ "FLAG_SUPPORTS_Z_OR_M",
646
+ INT2FIX(RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M));
647
+ rb_define_const(geos_factory_class,
648
+ "FLAG_PREPARE_HEURISTIC",
649
+ INT2FIX(RGEO_FACTORYFLAGS_PREPARE_HEURISTIC));
703
650
  // Add C methods to the factory.
704
- rb_define_method(geos_factory_class, "initialize_copy", method_factory_initialize_copy, 1);
705
- rb_define_method(geos_factory_class, "_parse_wkt_impl", method_factory_parse_wkt, 1);
706
- rb_define_method(geos_factory_class, "_parse_wkb_impl", method_factory_parse_wkb, 1);
651
+ rb_define_method(
652
+ geos_factory_class, "initialize_copy", method_factory_initialize_copy, 1);
653
+ rb_define_method(
654
+ geos_factory_class, "_parse_wkt_impl", method_factory_parse_wkt, 1);
655
+ rb_define_method(
656
+ geos_factory_class, "_parse_wkb_impl", method_factory_parse_wkb, 1);
707
657
  rb_define_method(geos_factory_class, "_srid", method_factory_srid, 0);
708
- rb_define_method(geos_factory_class, "_buffer_resolution", method_factory_buffer_resolution, 0);
658
+ rb_define_method(geos_factory_class,
659
+ "_buffer_resolution",
660
+ method_factory_buffer_resolution,
661
+ 0);
709
662
  rb_define_method(geos_factory_class, "_flags", method_factory_flags, 0);
710
- rb_define_method(geos_factory_class, "supports_z?", method_factory_supports_z_p, 0);
711
- rb_define_method(geos_factory_class, "supports_m?", method_factory_supports_m_p, 0);
712
- rb_define_method(geos_factory_class, "supports_z_or_m?", method_factory_supports_z_or_m_p, 0);
713
- rb_define_method(geos_factory_class, "prepare_heuristic?", method_factory_prepare_heuristic_p, 0);
714
- rb_define_method(geos_factory_class, "_set_wkrep_parsers", method_set_wkrep_parsers, 2);
715
- rb_define_method(geos_factory_class, "_proj4", method_get_proj4, 0);
663
+ rb_define_method(
664
+ geos_factory_class, "supports_z?", method_factory_supports_z_p, 0);
665
+ rb_define_method(
666
+ geos_factory_class, "supports_m?", method_factory_supports_m_p, 0);
667
+ rb_define_method(geos_factory_class,
668
+ "supports_z_or_m?",
669
+ method_factory_supports_z_or_m_p,
670
+ 0);
671
+ rb_define_method(geos_factory_class,
672
+ "prepare_heuristic?",
673
+ method_factory_prepare_heuristic_p,
674
+ 0);
675
+ rb_define_method(
676
+ geos_factory_class, "_set_wkrep_parsers", method_set_wkrep_parsers, 2);
716
677
  rb_define_method(geos_factory_class, "_coord_sys", method_get_coord_sys, 0);
717
- rb_define_method(geos_factory_class, "_wkt_generator", method_get_wkt_generator, 0);
718
- rb_define_method(geos_factory_class, "_wkb_generator", method_get_wkb_generator, 0);
678
+ rb_define_method(
679
+ geos_factory_class, "_wkt_generator", method_get_wkt_generator, 0);
680
+ rb_define_method(
681
+ geos_factory_class, "_wkb_generator", method_get_wkb_generator, 0);
719
682
  rb_define_method(geos_factory_class, "_wkt_parser", method_get_wkt_parser, 0);
720
683
  rb_define_method(geos_factory_class, "_wkb_parser", method_get_wkb_parser, 0);
721
- rb_define_method(geos_factory_class, "read_for_marshal", method_factory_read_for_marshal, 1);
722
- rb_define_method(geos_factory_class, "write_for_marshal", method_factory_write_for_marshal, 1);
723
- rb_define_method(geos_factory_class, "read_for_psych", method_factory_read_for_psych, 1);
724
- rb_define_method(geos_factory_class, "write_for_psych", method_factory_write_for_psych, 1);
725
- rb_define_module_function(geos_factory_class, "_create", cmethod_factory_create, 7);
726
- rb_define_module_function(geos_factory_class, "_geos_version", cmethod_factory_geos_version, 0);
727
- rb_define_module_function(geos_factory_class, "_supports_unary_union?", cmethod_factory_supports_unary_union, 0);
684
+ rb_define_method(
685
+ geos_factory_class, "read_for_marshal", method_factory_read_for_marshal, 1);
686
+ rb_define_method(geos_factory_class,
687
+ "write_for_marshal",
688
+ method_factory_write_for_marshal,
689
+ 1);
690
+ rb_define_method(
691
+ geos_factory_class, "read_for_psych", method_factory_read_for_psych, 1);
692
+ rb_define_method(
693
+ geos_factory_class, "write_for_psych", method_factory_write_for_psych, 1);
694
+ rb_define_module_function(
695
+ geos_factory_class, "_create", cmethod_factory_create, 6);
696
+ rb_define_module_function(
697
+ geos_factory_class, "_geos_version", cmethod_factory_geos_version, 0);
698
+ rb_define_module_function(geos_factory_class,
699
+ "_supports_unary_union?",
700
+ cmethod_factory_supports_unary_union,
701
+ 0);
728
702
 
729
703
  // Define allocation methods for global class types
730
704
  rb_define_alloc_func(rgeo_geos_geometry_class, alloc_geometry);
@@ -739,15 +713,13 @@ void rgeo_init_geos_factory()
739
713
  rb_define_alloc_func(rgeo_geos_multi_polygon_class, alloc_geometry);
740
714
  }
741
715
 
742
-
743
716
  /**** OTHER PUBLIC FUNCTIONS ****/
744
717
 
745
-
746
- VALUE rgeo_wrap_geos_geometry(VALUE factory, GEOSGeometry* geom, VALUE klass)
718
+ VALUE
719
+ rgeo_wrap_geos_geometry(VALUE factory, GEOSGeometry* geom, VALUE klass)
747
720
  {
748
721
  VALUE result;
749
722
  RGeo_FactoryData* factory_data;
750
- GEOSContextHandle_t factory_context;
751
723
  VALUE klasses;
752
724
  VALUE inferred_klass;
753
725
  char is_collection;
@@ -756,14 +728,14 @@ VALUE rgeo_wrap_geos_geometry(VALUE factory, GEOSGeometry* geom, VALUE klass)
756
728
  result = Qnil;
757
729
  if (geom || !NIL_P(klass)) {
758
730
  factory_data = NIL_P(factory) ? NULL : RGEO_FACTORY_DATA_PTR(factory);
759
- factory_context = factory_data ? factory_data->geos_context : NULL;
760
731
 
761
732
  // We don't allow "empty" points, so replace such objects with
762
733
  // an empty collection.
763
734
  if (geom && factory) {
764
- if (GEOSGeomTypeId_r(factory_context, geom) == GEOS_POINT && GEOSGetNumCoordinates_r(factory_context, geom) == 0) {
765
- GEOSGeom_destroy_r(factory_context, geom);
766
- geom = GEOSGeom_createCollection_r(factory_context, GEOS_GEOMETRYCOLLECTION, NULL, 0);
735
+ if (GEOSGeomTypeId(geom) == GEOS_POINT &&
736
+ GEOSGetNumCoordinates(geom) == 0) {
737
+ GEOSGeom_destroy(geom);
738
+ geom = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, NULL, 0);
767
739
  klass = rgeo_geos_geometry_collection_class;
768
740
  }
769
741
  }
@@ -772,38 +744,38 @@ VALUE rgeo_wrap_geos_geometry(VALUE factory, GEOSGeometry* geom, VALUE klass)
772
744
  if (TYPE(klass) != T_CLASS) {
773
745
  inferred_klass = Qnil;
774
746
  is_collection = 0;
775
- switch (GEOSGeomTypeId_r(factory_context, geom)) {
776
- case GEOS_POINT:
777
- inferred_klass = rgeo_geos_point_class;
778
- break;
779
- case GEOS_LINESTRING:
780
- inferred_klass = rgeo_geos_line_string_class;
781
- break;
782
- case GEOS_LINEARRING:
783
- inferred_klass = rgeo_geos_linear_ring_class;
784
- break;
785
- case GEOS_POLYGON:
786
- inferred_klass = rgeo_geos_polygon_class;
787
- break;
788
- case GEOS_MULTIPOINT:
789
- inferred_klass = rgeo_geos_multi_point_class;
790
- is_collection = 1;
791
- break;
792
- case GEOS_MULTILINESTRING:
793
- inferred_klass = rgeo_geos_multi_line_string_class;
794
- is_collection = 1;
795
- break;
796
- case GEOS_MULTIPOLYGON:
797
- inferred_klass = rgeo_geos_multi_polygon_class;
798
- is_collection = 1;
799
- break;
800
- case GEOS_GEOMETRYCOLLECTION:
801
- inferred_klass = rgeo_geos_geometry_collection_class;
802
- is_collection = 1;
803
- break;
804
- default:
805
- inferred_klass = rgeo_geos_geometry_class;
806
- break;
747
+ switch (GEOSGeomTypeId(geom)) {
748
+ case GEOS_POINT:
749
+ inferred_klass = rgeo_geos_point_class;
750
+ break;
751
+ case GEOS_LINESTRING:
752
+ inferred_klass = rgeo_geos_line_string_class;
753
+ break;
754
+ case GEOS_LINEARRING:
755
+ inferred_klass = rgeo_geos_linear_ring_class;
756
+ break;
757
+ case GEOS_POLYGON:
758
+ inferred_klass = rgeo_geos_polygon_class;
759
+ break;
760
+ case GEOS_MULTIPOINT:
761
+ inferred_klass = rgeo_geos_multi_point_class;
762
+ is_collection = 1;
763
+ break;
764
+ case GEOS_MULTILINESTRING:
765
+ inferred_klass = rgeo_geos_multi_line_string_class;
766
+ is_collection = 1;
767
+ break;
768
+ case GEOS_MULTIPOLYGON:
769
+ inferred_klass = rgeo_geos_multi_polygon_class;
770
+ is_collection = 1;
771
+ break;
772
+ case GEOS_GEOMETRYCOLLECTION:
773
+ inferred_klass = rgeo_geos_geometry_collection_class;
774
+ is_collection = 1;
775
+ break;
776
+ default:
777
+ inferred_klass = rgeo_geos_geometry_class;
778
+ break;
807
779
  }
808
780
  if (TYPE(klass) == T_ARRAY && is_collection) {
809
781
  klasses = klass;
@@ -813,12 +785,14 @@ VALUE rgeo_wrap_geos_geometry(VALUE factory, GEOSGeometry* geom, VALUE klass)
813
785
  data = ALLOC(RGeo_GeometryData);
814
786
  if (data) {
815
787
  if (geom) {
816
- GEOSSetSRID_r(factory_context, geom, factory_data->srid);
788
+ GEOSSetSRID(geom, factory_data->srid);
817
789
  }
818
- data->geos_context = factory_context;
819
790
  data->geom = geom;
820
- data->prep = factory_data && ((factory_data->flags & RGEO_FACTORYFLAGS_PREPARE_HEURISTIC) != 0) ?
821
- (GEOSPreparedGeometry*)1 : NULL;
791
+ data->prep =
792
+ factory_data &&
793
+ ((factory_data->flags & RGEO_FACTORYFLAGS_PREPARE_HEURISTIC) != 0)
794
+ ? (GEOSPreparedGeometry*)1
795
+ : NULL;
822
796
  data->factory = factory;
823
797
  data->klasses = klasses;
824
798
  result = TypedData_Wrap_Struct(klass, &rgeo_geometry_type, data);
@@ -827,14 +801,17 @@ VALUE rgeo_wrap_geos_geometry(VALUE factory, GEOSGeometry* geom, VALUE klass)
827
801
  return result;
828
802
  }
829
803
 
830
- VALUE rgeo_wrap_geos_geometry_clone(VALUE factory, const GEOSGeometry* geom, VALUE klass)
804
+ VALUE
805
+ rgeo_wrap_geos_geometry_clone(VALUE factory,
806
+ const GEOSGeometry* geom,
807
+ VALUE klass)
831
808
  {
832
809
  VALUE result;
833
810
  GEOSGeometry* clone_geom;
834
811
 
835
812
  result = Qnil;
836
813
  if (geom) {
837
- clone_geom = GEOSGeom_clone_r(RGEO_FACTORY_DATA_PTR(factory)->geos_context, geom);
814
+ clone_geom = GEOSGeom_clone(geom);
838
815
  if (clone_geom) {
839
816
  result = rgeo_wrap_geos_geometry(factory, clone_geom, klass);
840
817
  }
@@ -842,16 +819,17 @@ VALUE rgeo_wrap_geos_geometry_clone(VALUE factory, const GEOSGeometry* geom, VAL
842
819
  return result;
843
820
  }
844
821
 
845
-
846
- const GEOSGeometry* rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALUE type)
822
+ const GEOSGeometry*
823
+ rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALUE type)
847
824
  {
848
825
  VALUE object;
849
826
 
850
- if (NIL_P(type) && RGEO_GEOMETRY_TYPEDDATA_P(obj) && RGEO_GEOMETRY_DATA_PTR(obj)->factory == factory) {
827
+ if (NIL_P(type) && RGEO_GEOMETRY_TYPEDDATA_P(obj) &&
828
+ RGEO_GEOMETRY_DATA_PTR(obj)->factory == factory) {
851
829
  object = obj;
852
- }
853
- else {
854
- object = rb_funcall(rgeo_feature_module, rb_intern("cast"), 3, obj, factory, type);
830
+ } else {
831
+ object =
832
+ rb_funcall(rgeo_feature_module, rb_intern("cast"), 3, obj, factory, type);
855
833
  }
856
834
  if (NIL_P(object))
857
835
  return NULL;
@@ -860,62 +838,81 @@ const GEOSGeometry* rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALU
860
838
  return RGEO_GEOMETRY_DATA_PTR(object)->geom;
861
839
  }
862
840
 
863
-
864
- GEOSGeometry* rgeo_convert_to_detached_geos_geometry(VALUE obj, VALUE factory, VALUE type, VALUE* klasses)
841
+ GEOSGeometry*
842
+ rgeo_convert_to_detached_geos_geometry(VALUE obj,
843
+ VALUE factory,
844
+ VALUE type,
845
+ VALUE* klasses,
846
+ int* state)
865
847
  {
866
848
  VALUE object;
867
849
  GEOSGeometry* geom;
868
850
  RGeo_GeometryData* object_data;
869
851
  const GEOSPreparedGeometry* prep;
870
-
871
852
  if (klasses) {
872
853
  *klasses = Qnil;
873
854
  }
874
- object = rb_funcall(rgeo_feature_module, rb_intern("cast"), 5, obj, factory, type, ID2SYM(rb_intern("force_new")), ID2SYM(rb_intern("keep_subtype")));
875
- geom = NULL;
876
- if (!NIL_P(object)) {
877
- object_data = RGEO_GEOMETRY_DATA_PTR(object);
878
- geom = object_data->geom;
879
- if (klasses) {
880
- *klasses = object_data->klasses;
881
- if (NIL_P(*klasses)) {
882
- *klasses = CLASS_OF(object);
883
- }
884
- }
885
- prep = object_data->prep;
886
- if (prep && prep != (GEOSPreparedGeometry*)1 && prep != (GEOSPreparedGeometry*)2) {
887
- GEOSPreparedGeom_destroy_r(object_data->geos_context, prep);
855
+
856
+ object = rb_protect_funcall(rgeo_feature_module,
857
+ rb_intern("cast"),
858
+ state,
859
+ 5,
860
+ obj,
861
+ factory,
862
+ type,
863
+ ID2SYM(rb_intern("force_new")),
864
+ ID2SYM(rb_intern("keep_subtype")));
865
+ if (*state || NIL_P(object)) {
866
+ return NULL;
867
+ }
868
+
869
+ object_data = RGEO_GEOMETRY_DATA_PTR(object);
870
+ geom = object_data->geom;
871
+ if (klasses) {
872
+ *klasses = object_data->klasses;
873
+ if (NIL_P(*klasses)) {
874
+ *klasses = CLASS_OF(object);
888
875
  }
889
- object_data->geos_context = NULL;
890
- object_data->geom = NULL;
891
- object_data->prep = NULL;
892
- object_data->factory = Qnil;
893
- object_data->klasses = Qnil;
894
876
  }
877
+ prep = object_data->prep;
878
+ if (prep && prep != (GEOSPreparedGeometry*)1 &&
879
+ prep != (GEOSPreparedGeometry*)2) {
880
+ GEOSPreparedGeom_destroy(prep);
881
+ }
882
+ object_data->geom = NULL;
883
+ object_data->prep = NULL;
884
+ object_data->factory = Qnil;
885
+ object_data->klasses = Qnil;
886
+
895
887
  return geom;
896
888
  }
897
889
 
898
-
899
- char rgeo_is_geos_object(VALUE obj)
890
+ char
891
+ rgeo_is_geos_object(VALUE obj)
900
892
  {
901
893
  return RGEO_GEOMETRY_TYPEDDATA_P(obj) ? 1 : 0;
902
894
  }
903
895
 
904
- void rgeo_check_geos_object(VALUE obj)
896
+ void
897
+ rgeo_check_geos_object(VALUE obj)
905
898
  {
906
899
  if (!rgeo_is_geos_object(obj)) {
907
900
  rb_raise(rb_eRGeoError, "Not a GEOS Geometry object.");
908
901
  }
909
902
  }
910
903
 
911
-
912
- const GEOSGeometry* rgeo_get_geos_geometry_safe(VALUE obj)
904
+ const GEOSGeometry*
905
+ rgeo_get_geos_geometry_safe(VALUE obj)
913
906
  {
914
- return RGEO_GEOMETRY_TYPEDDATA_P(obj) ? (const GEOSGeometry*)(RGEO_GEOMETRY_DATA_PTR(obj)->geom) : NULL;
907
+ return RGEO_GEOMETRY_TYPEDDATA_P(obj)
908
+ ? (const GEOSGeometry*)(RGEO_GEOMETRY_DATA_PTR(obj)->geom)
909
+ : NULL;
915
910
  }
916
911
 
917
-
918
- VALUE rgeo_geos_coordseqs_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z)
912
+ VALUE
913
+ rgeo_geos_coordseqs_eql(const GEOSGeometry* geom1,
914
+ const GEOSGeometry* geom2,
915
+ char check_z)
919
916
  {
920
917
  VALUE result;
921
918
  const GEOSCoordSequence* cs1;
@@ -927,27 +924,30 @@ VALUE rgeo_geos_coordseqs_eql(GEOSContextHandle_t context, const GEOSGeometry* g
927
924
 
928
925
  result = Qnil;
929
926
  if (geom1 && geom2) {
930
- cs1 = GEOSGeom_getCoordSeq_r(context, geom1);
931
- cs2 = GEOSGeom_getCoordSeq_r(context, geom2);
927
+ cs1 = GEOSGeom_getCoordSeq(geom1);
928
+ cs2 = GEOSGeom_getCoordSeq(geom2);
932
929
  if (cs1 && cs2) {
933
930
  len1 = 0;
934
931
  len2 = 0;
935
- if (GEOSCoordSeq_getSize_r(context, cs1, &len1) && GEOSCoordSeq_getSize_r(context, cs2, &len2)) {
932
+ if (GEOSCoordSeq_getSize(cs1, &len1) &&
933
+ GEOSCoordSeq_getSize(cs2, &len2)) {
936
934
  if (len1 == len2) {
937
935
  result = Qtrue;
938
- for (i=0; i<len1; ++i) {
939
- if (GEOSCoordSeq_getX_r(context, cs1, i, &val1) && GEOSCoordSeq_getX_r(context, cs2, i, &val2)) {
936
+ for (i = 0; i < len1; ++i) {
937
+ if (GEOSCoordSeq_getX(cs1, i, &val1) &&
938
+ GEOSCoordSeq_getX(cs2, i, &val2)) {
940
939
  if (val1 == val2) {
941
- if (GEOSCoordSeq_getY_r(context, cs1, i, &val1) && GEOSCoordSeq_getY_r(context, cs2, i, &val2)) {
940
+ if (GEOSCoordSeq_getY(cs1, i, &val1) &&
941
+ GEOSCoordSeq_getY(cs2, i, &val2)) {
942
942
  if (val1 == val2) {
943
943
  if (check_z) {
944
944
  val1 = 0;
945
- if (!GEOSCoordSeq_getZ_r(context, cs1, i, &val1)) {
945
+ if (!GEOSCoordSeq_getZ(cs1, i, &val1)) {
946
946
  result = Qnil;
947
947
  break;
948
948
  }
949
949
  val2 = 0;
950
- if (!GEOSCoordSeq_getZ_r(context, cs2, i, &val2)) {
950
+ if (!GEOSCoordSeq_getZ(cs2, i, &val2)) {
951
951
  result = Qnil;
952
952
  break;
953
953
  }
@@ -956,29 +956,24 @@ VALUE rgeo_geos_coordseqs_eql(GEOSContextHandle_t context, const GEOSGeometry* g
956
956
  break;
957
957
  }
958
958
  }
959
- }
960
- else { // Y coords are different
959
+ } else { // Y coords are different
961
960
  result = Qfalse;
962
961
  break;
963
962
  }
964
- }
965
- else { // Failed to get Y coords
963
+ } else { // Failed to get Y coords
966
964
  result = Qnil;
967
965
  break;
968
966
  }
969
- }
970
- else { // X coords are different
967
+ } else { // X coords are different
971
968
  result = Qfalse;
972
969
  break;
973
970
  }
974
- }
975
- else { // Failed to get X coords
971
+ } else { // Failed to get X coords
976
972
  result = Qnil;
977
973
  break;
978
974
  }
979
- } // Iteration over coords
980
- }
981
- else { // Lengths are different
975
+ } // Iteration over coords
976
+ } else { // Lengths are different
982
977
  result = Qfalse;
983
978
  }
984
979
  }
@@ -987,8 +982,8 @@ VALUE rgeo_geos_coordseqs_eql(GEOSContextHandle_t context, const GEOSGeometry* g
987
982
  return result;
988
983
  }
989
984
 
990
-
991
- VALUE rgeo_geos_klasses_and_factories_eql(VALUE obj1, VALUE obj2)
985
+ VALUE
986
+ rgeo_geos_klasses_and_factories_eql(VALUE obj1, VALUE obj2)
992
987
  {
993
988
  VALUE result;
994
989
  VALUE factory;
@@ -996,24 +991,25 @@ VALUE rgeo_geos_klasses_and_factories_eql(VALUE obj1, VALUE obj2)
996
991
  result = Qnil;
997
992
  if (rb_obj_class(obj1) != rb_obj_class(obj2)) {
998
993
  result = Qfalse;
999
- }
1000
- else {
994
+ } else {
1001
995
  factory = RGEO_GEOMETRY_DATA_PTR(obj1)->factory;
1002
996
  /* No need to cache the internal here (https://ips.fastruby.io/4x) */
1003
- result = rb_funcall(factory, rb_intern("eql?"), 1, RGEO_GEOMETRY_DATA_PTR(obj2)->factory);
997
+ result = rb_funcall(
998
+ factory, rb_intern("eql?"), 1, RGEO_GEOMETRY_DATA_PTR(obj2)->factory);
1004
999
  }
1005
1000
  return result;
1006
1001
  }
1007
1002
 
1008
-
1009
- typedef struct {
1003
+ typedef struct
1004
+ {
1010
1005
  st_index_t seed_hash;
1011
1006
  double x;
1012
1007
  double y;
1013
1008
  double z;
1014
1009
  } RGeo_Coordseq_Hash_Struct;
1015
1010
 
1016
- st_index_t rgeo_geos_coordseq_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash)
1011
+ st_index_t
1012
+ rgeo_geos_coordseq_hash(const GEOSGeometry* geom, st_index_t hash)
1017
1013
  {
1018
1014
  const GEOSCoordSequence* cs;
1019
1015
  unsigned int len;
@@ -1021,17 +1017,18 @@ st_index_t rgeo_geos_coordseq_hash(GEOSContextHandle_t context, const GEOSGeomet
1021
1017
  RGeo_Coordseq_Hash_Struct hash_struct;
1022
1018
 
1023
1019
  if (geom) {
1024
- cs = GEOSGeom_getCoordSeq_r(context, geom);
1020
+ cs = GEOSGeom_getCoordSeq(geom);
1025
1021
  if (cs) {
1026
- if (GEOSCoordSeq_getSize_r(context, cs, &len)) {
1027
- for (i=0; i<len; ++i) {
1028
- if (GEOSCoordSeq_getX_r(context, cs, i, &hash_struct.x)) {
1029
- if (GEOSCoordSeq_getY_r(context, cs, i, &hash_struct.y)) {
1030
- if (!GEOSCoordSeq_getY_r(context, cs, i, &hash_struct.z)) {
1022
+ if (GEOSCoordSeq_getSize(cs, &len)) {
1023
+ for (i = 0; i < len; ++i) {
1024
+ if (GEOSCoordSeq_getX(cs, i, &hash_struct.x)) {
1025
+ if (GEOSCoordSeq_getY(cs, i, &hash_struct.y)) {
1026
+ if (!GEOSCoordSeq_getY(cs, i, &hash_struct.z)) {
1031
1027
  hash_struct.z = 0;
1032
1028
  }
1033
1029
  hash_struct.seed_hash = hash;
1034
- hash = rb_memhash(&hash_struct, sizeof(RGeo_Coordseq_Hash_Struct));
1030
+ hash =
1031
+ rb_memhash(&hash_struct, sizeof(RGeo_Coordseq_Hash_Struct));
1035
1032
  }
1036
1033
  }
1037
1034
  }
@@ -1041,14 +1038,15 @@ st_index_t rgeo_geos_coordseq_hash(GEOSContextHandle_t context, const GEOSGeomet
1041
1038
  return hash;
1042
1039
  }
1043
1040
 
1044
-
1045
- typedef struct {
1041
+ typedef struct
1042
+ {
1046
1043
  st_index_t seed_hash;
1047
1044
  st_index_t h1;
1048
1045
  st_index_t h2;
1049
1046
  } RGeo_Objbase_Hash_Struct;
1050
1047
 
1051
- st_index_t rgeo_geos_objbase_hash(VALUE factory, VALUE type_module, st_index_t hash)
1048
+ st_index_t
1049
+ rgeo_geos_objbase_hash(VALUE factory, VALUE type_module, st_index_t hash)
1052
1050
  {
1053
1051
  ID hash_method;
1054
1052
  RGeo_Objbase_Hash_Struct hash_struct;
@@ -1060,23 +1058,6 @@ st_index_t rgeo_geos_objbase_hash(VALUE factory, VALUE type_module, st_index_t h
1060
1058
  return rb_memhash(&hash_struct, sizeof(RGeo_Objbase_Hash_Struct));
1061
1059
  }
1062
1060
 
1063
-
1064
- st_index_t rgeo_internal_memhash(const void* ptr, long len)
1065
- {
1066
- const char* bytes;
1067
- st_index_t hval;
1068
- long i;
1069
-
1070
- bytes = (const char*)ptr;
1071
- hval = 0x811c9dc5;
1072
- for (i=0; i<len; ++i) {
1073
- hval ^= (unsigned int)(*bytes++);
1074
- hval *= 0x01000193;
1075
- }
1076
- return hval;
1077
- }
1078
-
1079
-
1080
1061
  RGEO_END_C
1081
1062
 
1082
1063
  #endif