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,27 +2,24 @@
2
2
  Polygon methods 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>
10
+ #include <ruby.h>
12
11
 
13
- #include "globals.h"
14
-
12
+ #include "coordinates.h"
15
13
  #include "factory.h"
16
14
  #include "geometry.h"
15
+ #include "globals.h"
17
16
  #include "line_string.h"
18
17
  #include "polygon.h"
19
18
 
20
- #include "coordinates.h"
21
-
22
19
  RGEO_BEGIN_C
23
20
 
24
-
25
- static VALUE method_polygon_eql(VALUE self, VALUE rhs)
21
+ static VALUE
22
+ method_polygon_eql(VALUE self, VALUE rhs)
26
23
  {
27
24
  VALUE result;
28
25
  RGeo_GeometryData* self_data;
@@ -30,13 +27,14 @@ static VALUE method_polygon_eql(VALUE self, VALUE rhs)
30
27
  result = rgeo_geos_klasses_and_factories_eql(self, rhs);
31
28
  if (RTEST(result)) {
32
29
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
33
- result = rgeo_geos_geometries_strict_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
30
+ result = rgeo_geos_geometries_strict_eql(self_data->geom,
31
+ RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
34
32
  }
35
33
  return result;
36
34
  }
37
35
 
38
-
39
- static VALUE method_polygon_hash(VALUE self)
36
+ static VALUE
37
+ method_polygon_hash(VALUE self)
40
38
  {
41
39
  st_index_t hash;
42
40
  RGeo_GeometryData* self_data;
@@ -46,12 +44,12 @@ static VALUE method_polygon_hash(VALUE self)
46
44
  factory = self_data->factory;
47
45
  hash = rb_hash_start(0);
48
46
  hash = rgeo_geos_objbase_hash(factory, rgeo_feature_polygon_module, hash);
49
- hash = rgeo_geos_polygon_hash(self_data->geos_context, self_data->geom, hash);
47
+ hash = rgeo_geos_polygon_hash(self_data->geom, hash);
50
48
  return LONG2FIX(rb_hash_end(hash));
51
49
  }
52
50
 
53
-
54
- static VALUE method_polygon_geometry_type(VALUE self)
51
+ static VALUE
52
+ method_polygon_geometry_type(VALUE self)
55
53
  {
56
54
  VALUE result;
57
55
  RGeo_GeometryData* self_data;
@@ -64,8 +62,8 @@ static VALUE method_polygon_geometry_type(VALUE self)
64
62
  return result;
65
63
  }
66
64
 
67
-
68
- static VALUE method_polygon_area(VALUE self)
65
+ static VALUE
66
+ method_polygon_area(VALUE self)
69
67
  {
70
68
  VALUE result;
71
69
  RGeo_GeometryData* self_data;
@@ -76,15 +74,15 @@ static VALUE method_polygon_area(VALUE self)
76
74
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
77
75
  self_geom = self_data->geom;
78
76
  if (self_geom) {
79
- if (GEOSArea_r(self_data->geos_context, self_geom, &area)) {
77
+ if (GEOSArea(self_geom, &area)) {
80
78
  result = rb_float_new(area);
81
79
  }
82
80
  }
83
81
  return result;
84
82
  }
85
83
 
86
-
87
- static VALUE method_polygon_centroid(VALUE self)
84
+ static VALUE
85
+ method_polygon_centroid(VALUE self)
88
86
  {
89
87
  VALUE result;
90
88
  RGeo_GeometryData* self_data;
@@ -94,13 +92,14 @@ static VALUE method_polygon_centroid(VALUE self)
94
92
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
95
93
  self_geom = self_data->geom;
96
94
  if (self_geom) {
97
- result = rgeo_wrap_geos_geometry(self_data->factory, GEOSGetCentroid_r(self_data->geos_context, self_geom), rgeo_geos_point_class);
95
+ result = rgeo_wrap_geos_geometry(
96
+ self_data->factory, GEOSGetCentroid(self_geom), rgeo_geos_point_class);
98
97
  }
99
98
  return result;
100
99
  }
101
100
 
102
-
103
- static VALUE method_polygon_point_on_surface(VALUE self)
101
+ static VALUE
102
+ method_polygon_point_on_surface(VALUE self)
104
103
  {
105
104
  VALUE result;
106
105
  RGeo_GeometryData* self_data;
@@ -110,18 +109,18 @@ static VALUE method_polygon_point_on_surface(VALUE self)
110
109
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
111
110
  self_geom = self_data->geom;
112
111
  if (self_geom) {
113
- result = rgeo_wrap_geos_geometry(self_data->factory, GEOSPointOnSurface_r(self_data->geos_context, self_geom), rgeo_geos_point_class);
112
+ result = rgeo_wrap_geos_geometry(
113
+ self_data->factory, GEOSPointOnSurface(self_geom), rgeo_geos_point_class);
114
114
  }
115
115
  return result;
116
116
  }
117
117
 
118
-
119
- static VALUE method_polygon_coordinates(VALUE self)
118
+ static VALUE
119
+ method_polygon_coordinates(VALUE self)
120
120
  {
121
121
  VALUE result = Qnil;
122
122
  RGeo_GeometryData* self_data;
123
123
  const GEOSGeometry* self_geom;
124
- GEOSContextHandle_t self_context;
125
124
 
126
125
  int zCoordinate;
127
126
 
@@ -129,14 +128,15 @@ static VALUE method_polygon_coordinates(VALUE self)
129
128
  self_geom = self_data->geom;
130
129
 
131
130
  if (self_geom) {
132
- zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
133
- self_context = self_data->geos_context;
134
- result = extract_points_from_polygon(self_context, self_geom, zCoordinate);
131
+ zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
132
+ RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
133
+ result = extract_points_from_polygon(self_geom, zCoordinate);
135
134
  }
136
135
  return result;
137
136
  }
138
137
 
139
- static VALUE method_polygon_exterior_ring(VALUE self)
138
+ static VALUE
139
+ method_polygon_exterior_ring(VALUE self)
140
140
  {
141
141
  VALUE result;
142
142
  RGeo_GeometryData* self_data;
@@ -146,13 +146,15 @@ static VALUE method_polygon_exterior_ring(VALUE self)
146
146
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
147
147
  self_geom = self_data->geom;
148
148
  if (self_geom) {
149
- result = rgeo_wrap_geos_geometry_clone(self_data->factory, GEOSGetExteriorRing_r(self_data->geos_context, self_geom), rgeo_geos_linear_ring_class);
149
+ result = rgeo_wrap_geos_geometry_clone(self_data->factory,
150
+ GEOSGetExteriorRing(self_geom),
151
+ rgeo_geos_linear_ring_class);
150
152
  }
151
153
  return result;
152
154
  }
153
155
 
154
-
155
- static VALUE method_polygon_num_interior_rings(VALUE self)
156
+ static VALUE
157
+ method_polygon_num_interior_rings(VALUE self)
156
158
  {
157
159
  VALUE result;
158
160
  RGeo_GeometryData* self_data;
@@ -163,7 +165,7 @@ static VALUE method_polygon_num_interior_rings(VALUE self)
163
165
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
164
166
  self_geom = self_data->geom;
165
167
  if (self_geom) {
166
- num = GEOSGetNumInteriorRings_r(self_data->geos_context, self_geom);
168
+ num = GEOSGetNumInteriorRings(self_geom);
167
169
  if (num >= 0) {
168
170
  result = INT2NUM(num);
169
171
  }
@@ -171,150 +173,187 @@ static VALUE method_polygon_num_interior_rings(VALUE self)
171
173
  return result;
172
174
  }
173
175
 
174
-
175
- static VALUE method_polygon_interior_ring_n(VALUE self, VALUE n)
176
+ static VALUE
177
+ method_polygon_interior_ring_n(VALUE self, VALUE n)
176
178
  {
177
179
  VALUE result;
178
180
  RGeo_GeometryData* self_data;
179
181
  const GEOSGeometry* self_geom;
180
182
  int i;
181
- GEOSContextHandle_t self_context;
182
183
  int num;
183
184
 
184
185
  result = Qnil;
185
186
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
186
187
  self_geom = self_data->geom;
187
188
  if (self_geom) {
188
- i = NUM2INT(n);
189
+ i = RB_NUM2INT(n);
189
190
  if (i >= 0) {
190
- self_context = self_data->geos_context;
191
- num = GEOSGetNumInteriorRings_r(self_context, self_geom);
191
+ num = GEOSGetNumInteriorRings(self_geom);
192
192
  if (i < num) {
193
- result = rgeo_wrap_geos_geometry_clone(self_data->factory,
194
- GEOSGetInteriorRingN_r(self_context, self_geom, i),
195
- rgeo_geos_linear_ring_class);
193
+ result =
194
+ rgeo_wrap_geos_geometry_clone(self_data->factory,
195
+ GEOSGetInteriorRingN(self_geom, i),
196
+ rgeo_geos_linear_ring_class);
196
197
  }
197
198
  }
198
199
  }
199
200
  return result;
200
201
  }
201
202
 
202
-
203
- static VALUE method_polygon_interior_rings(VALUE self)
203
+ static VALUE
204
+ method_polygon_interior_rings(VALUE self)
204
205
  {
205
206
  VALUE result;
206
207
  RGeo_GeometryData* self_data;
207
208
  const GEOSGeometry* self_geom;
208
- GEOSContextHandle_t self_context;
209
209
  int count;
210
210
  VALUE factory;
211
- VALUE linear_ring_class;
212
211
  int i;
213
212
 
214
213
  result = Qnil;
215
214
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
216
215
  self_geom = self_data->geom;
217
216
  if (self_geom) {
218
- self_context = self_data->geos_context;
219
- count = GEOSGetNumInteriorRings_r(self_context, self_geom);
217
+ count = GEOSGetNumInteriorRings(self_geom);
220
218
  if (count >= 0) {
221
219
  result = rb_ary_new2(count);
222
220
  factory = self_data->factory;
223
- for (i=0; i<count; ++i) {
224
- rb_ary_store(result, i, rgeo_wrap_geos_geometry_clone(factory, GEOSGetInteriorRingN_r(self_context, self_geom, i), rgeo_geos_linear_ring_class));
221
+ for (i = 0; i < count; ++i) {
222
+ rb_ary_store(
223
+ result,
224
+ i,
225
+ rgeo_wrap_geos_geometry_clone(factory,
226
+ GEOSGetInteriorRingN(self_geom, i),
227
+ rgeo_geos_linear_ring_class));
225
228
  }
226
229
  }
227
230
  }
228
231
  return result;
229
232
  }
230
233
 
231
-
232
- static VALUE cmethod_create(VALUE module, VALUE factory, VALUE exterior, VALUE interior_array)
234
+ static VALUE
235
+ cmethod_create(VALUE module,
236
+ VALUE factory,
237
+ VALUE exterior,
238
+ VALUE interior_array)
233
239
  {
234
240
  RGeo_FactoryData* factory_data;
235
241
  VALUE linear_ring_type;
236
242
  GEOSGeometry* exterior_geom;
237
- GEOSContextHandle_t context;
238
243
  unsigned int len;
239
244
  GEOSGeometry** interior_geoms;
240
245
  unsigned int actual_len;
241
246
  unsigned int i;
242
247
  GEOSGeometry* interior_geom;
243
248
  GEOSGeometry* polygon;
249
+ int state = 0;
244
250
 
245
251
  Check_Type(interior_array, T_ARRAY);
246
252
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
247
253
  linear_ring_type = rgeo_feature_linear_ring_module;
248
- exterior_geom = rgeo_convert_to_detached_geos_geometry(exterior, factory, linear_ring_type, NULL);
249
- if (exterior_geom) {
250
- context = factory_data->geos_context;
251
- len = (unsigned int)RARRAY_LEN(interior_array);
252
- interior_geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
253
- if (interior_geoms) {
254
- actual_len = 0;
255
- for (i=0; i<len; ++i) {
256
- interior_geom = rgeo_convert_to_detached_geos_geometry(rb_ary_entry(interior_array, i), factory, linear_ring_type, NULL);
257
- if (interior_geom) {
258
- interior_geoms[actual_len++] = interior_geom;
259
- }
254
+ exterior_geom = rgeo_convert_to_detached_geos_geometry(
255
+ exterior, factory, linear_ring_type, NULL, &state);
256
+ if (state) {
257
+ rb_exc_raise(rb_errinfo());
258
+ }
259
+ if (!exterior_geom) {
260
+ return Qnil;
261
+ }
262
+
263
+ len = (unsigned int)RARRAY_LEN(interior_array);
264
+ interior_geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
265
+ if (interior_geoms) {
266
+ actual_len = 0;
267
+ for (i = 0; i < len; ++i) {
268
+ interior_geom =
269
+ rgeo_convert_to_detached_geos_geometry(rb_ary_entry(interior_array, i),
270
+ factory,
271
+ linear_ring_type,
272
+ NULL,
273
+ &state);
274
+ if (interior_geom) {
275
+ interior_geoms[actual_len++] = interior_geom;
260
276
  }
261
- if (len == actual_len) {
262
- polygon = GEOSGeom_createPolygon_r(context, exterior_geom, interior_geoms, actual_len);
263
- if (polygon) {
264
- free(interior_geoms);
265
- return rgeo_wrap_geos_geometry(factory, polygon, rgeo_geos_polygon_class);
266
- }
277
+ if (state) {
278
+ break;
267
279
  }
268
- for (i=0; i<actual_len; ++i) {
269
- GEOSGeom_destroy_r(context, interior_geoms[i]);
280
+ }
281
+ if (len == actual_len) {
282
+ polygon =
283
+ GEOSGeom_createPolygon(exterior_geom, interior_geoms, actual_len);
284
+ if (polygon) {
285
+ FREE(interior_geoms);
286
+ // NOTE: we can return safely here, state cannot be other than 0.
287
+ return rgeo_wrap_geos_geometry(
288
+ factory, polygon, rgeo_geos_polygon_class);
270
289
  }
271
- free(interior_geoms);
272
290
  }
273
- GEOSGeom_destroy_r(context, exterior_geom);
291
+ for (i = 0; i < actual_len; ++i) {
292
+ GEOSGeom_destroy(interior_geoms[i]);
293
+ }
294
+ FREE(interior_geoms);
295
+ }
296
+ GEOSGeom_destroy(exterior_geom);
297
+ if (state) {
298
+ rb_exc_raise(rb_errinfo());
274
299
  }
275
300
  return Qnil;
276
301
  }
277
302
 
278
-
279
- void rgeo_init_geos_polygon()
303
+ void
304
+ rgeo_init_geos_polygon()
280
305
  {
281
306
  VALUE geos_polygon_methods;
282
307
 
283
308
  // Class methods for CAPIPolygonImpl
284
- rb_define_module_function(rgeo_geos_polygon_class, "create", cmethod_create, 3);
309
+ rb_define_module_function(
310
+ rgeo_geos_polygon_class, "create", cmethod_create, 3);
285
311
 
286
312
  // CAPIPolygonMethods module
287
- geos_polygon_methods = rb_define_module_under(rgeo_geos_module, "CAPIPolygonMethods");
313
+ geos_polygon_methods =
314
+ rb_define_module_under(rgeo_geos_module, "CAPIPolygonMethods");
288
315
  rb_define_method(geos_polygon_methods, "rep_equals?", method_polygon_eql, 1);
289
316
  rb_define_method(geos_polygon_methods, "eql?", method_polygon_eql, 1);
290
317
  rb_define_method(geos_polygon_methods, "hash", method_polygon_hash, 0);
291
- rb_define_method(geos_polygon_methods, "geometry_type", method_polygon_geometry_type, 0);
318
+ rb_define_method(
319
+ geos_polygon_methods, "geometry_type", method_polygon_geometry_type, 0);
292
320
  rb_define_method(geos_polygon_methods, "area", method_polygon_area, 0);
293
- rb_define_method(geos_polygon_methods, "centroid", method_polygon_centroid, 0);
294
- rb_define_method(geos_polygon_methods, "point_on_surface", method_polygon_point_on_surface, 0);
295
- rb_define_method(geos_polygon_methods, "exterior_ring", method_polygon_exterior_ring, 0);
296
- rb_define_method(geos_polygon_methods, "num_interior_rings", method_polygon_num_interior_rings, 0);
297
- rb_define_method(geos_polygon_methods, "interior_ring_n", method_polygon_interior_ring_n, 1);
298
- rb_define_method(geos_polygon_methods, "interior_rings", method_polygon_interior_rings, 0);
299
- rb_define_method(geos_polygon_methods, "coordinates", method_polygon_coordinates, 0);
321
+ rb_define_method(
322
+ geos_polygon_methods, "centroid", method_polygon_centroid, 0);
323
+ rb_define_method(geos_polygon_methods,
324
+ "point_on_surface",
325
+ method_polygon_point_on_surface,
326
+ 0);
327
+ rb_define_method(
328
+ geos_polygon_methods, "exterior_ring", method_polygon_exterior_ring, 0);
329
+ rb_define_method(geos_polygon_methods,
330
+ "num_interior_rings",
331
+ method_polygon_num_interior_rings,
332
+ 0);
333
+ rb_define_method(
334
+ geos_polygon_methods, "interior_ring_n", method_polygon_interior_ring_n, 1);
335
+ rb_define_method(
336
+ geos_polygon_methods, "interior_rings", method_polygon_interior_rings, 0);
337
+ rb_define_method(
338
+ geos_polygon_methods, "coordinates", method_polygon_coordinates, 0);
300
339
  }
301
340
 
302
- st_index_t rgeo_geos_polygon_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash)
341
+ st_index_t
342
+ rgeo_geos_polygon_hash(const GEOSGeometry* geom, st_index_t hash)
303
343
  {
304
344
  unsigned int len;
305
345
  unsigned int i;
306
346
 
307
347
  if (geom) {
308
- hash = rgeo_geos_coordseq_hash(context, GEOSGetExteriorRing_r(context, geom), hash);
309
- len = GEOSGetNumInteriorRings_r(context, geom);
310
- for (i=0; i<len; ++i) {
311
- hash = rgeo_geos_coordseq_hash(context, GEOSGetInteriorRingN_r(context, geom, i), hash);
348
+ hash = rgeo_geos_coordseq_hash(GEOSGetExteriorRing(geom), hash);
349
+ len = GEOSGetNumInteriorRings(geom);
350
+ for (i = 0; i < len; ++i) {
351
+ hash = rgeo_geos_coordseq_hash(GEOSGetInteriorRingN(geom, i), hash);
312
352
  }
313
353
  }
314
354
  return hash;
315
355
  }
316
356
 
317
-
318
357
  RGEO_END_C
319
358
 
320
359
  #endif
@@ -2,21 +2,20 @@
2
2
  Polygon methods for GEOS wrapper
3
3
  */
4
4
 
5
-
6
5
  #ifndef RGEO_GEOS_POLYGON_INCLUDED
7
6
  #define RGEO_GEOS_POLYGON_INCLUDED
8
7
 
9
- #include <ruby.h>
10
8
  #include <geos_c.h>
9
+ #include <ruby.h>
11
10
 
12
11
  RGEO_BEGIN_C
13
12
 
14
-
15
13
  /*
16
14
  Initializes the polygon module. This should be called after
17
15
  the geometry module is initialized.
18
16
  */
19
- void rgeo_init_geos_polygon();
17
+ void
18
+ rgeo_init_geos_polygon();
20
19
 
21
20
  /*
22
21
  Comopares the values of two GEOS polygons. The two given geometries MUST
@@ -24,17 +23,20 @@ void rgeo_init_geos_polygon();
24
23
  Returns Qtrue if the polygons are equal, Qfalse if they are inequal, or
25
24
  Qnil if an error occurs.
26
25
  */
27
- VALUE rgeo_geos_polygons_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z);
26
+ VALUE
27
+ rgeo_geos_polygons_eql(const GEOSGeometry* geom1,
28
+ const GEOSGeometry* geom2,
29
+ char check_z);
28
30
 
29
31
  /*
30
32
  A tool for building up hash values.
31
- You must pass in the context, a geos geometry, and a seed hash.
33
+ You must pass in a geos geometry, and a seed hash.
32
34
  Returns an updated hash.
33
35
  This call is useful in sequence, and should be bracketed by calls to
34
36
  rb_hash_start and rb_hash_end.
35
37
  */
36
- st_index_t rgeo_geos_polygon_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash);
37
-
38
+ st_index_t
39
+ rgeo_geos_polygon_hash(const GEOSGeometry* geom, st_index_t hash);
38
40
 
39
41
  RGEO_END_C
40
42
 
@@ -2,7 +2,6 @@
2
2
  Preface header for GEOS wrapper
3
3
  */
4
4
 
5
-
6
5
  #ifdef HAVE_GEOS_C_H
7
6
  #ifdef HAVE_GEOSSETSRID_R
8
7
  #define RGEO_GEOS_SUPPORTED
@@ -24,24 +23,16 @@
24
23
  #ifdef HAVE_GEOSCOORDSEQ_ISCCW_R
25
24
  #define RGEO_GEOS_SUPPORTS_ISCCW
26
25
  #endif
27
- #ifdef HAVE_RB_MEMHASH
28
- #define RGEO_SUPPORTS_NEW_HASHING
29
- #endif
30
26
  #ifdef HAVE_RB_GC_MARK_MOVABLE
31
27
  #define mark rb_gc_mark_movable
32
28
  #else
33
29
  #define mark rb_gc_mark
34
30
  #endif
35
31
 
36
- #ifndef RGEO_SUPPORTS_NEW_HASHING
37
- #define st_index_t int
38
- #define rb_memhash(x,y) rgeo_internal_memhash(x,y)
39
- #define rb_hash_start(x) ((st_index_t)(x ^ 0xdeadbeef))
40
- #define rb_hash_end(x) ((st_index_t)(x ^ 0xbeefdead))
41
- #endif
42
-
43
32
  #ifdef __cplusplus
44
- #define RGEO_BEGIN_C extern "C" {
33
+ #define RGEO_BEGIN_C \
34
+ extern "C" \
35
+ {
45
36
  #define RGEO_END_C }
46
37
  #else
47
38
  #define RGEO_BEGIN_C
@@ -49,4 +40,8 @@
49
40
  #endif
50
41
 
51
42
  // https://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html
52
- #define streq(a, b) (!strcmp((a),(b)))
43
+ #define streq(a, b) (!strcmp((a), (b)))
44
+
45
+ // When using ruby ALLOC* macros, we are using ruby_xmalloc, which counterpart
46
+ // is ruby_xfree. This macro helps enforcing that by showing us the way.
47
+ #define FREE ruby_xfree
@@ -0,0 +1,60 @@
1
+ /*
2
+ Utilities for the ruby CAPI
3
+ */
4
+
5
+ #ifndef RGEO_GEOS_RUBY_MORE_INCLUDED
6
+ #define RGEO_GEOS_RUBY_MORE_INCLUDED
7
+
8
+ #include "ruby_more.h"
9
+
10
+ #include <ruby.h>
11
+
12
+ #include "preface.h"
13
+
14
+ RGEO_BEGIN_C
15
+
16
+ struct funcall_args
17
+ {
18
+ VALUE recv;
19
+ ID mid;
20
+ int argc;
21
+ VALUE* argv;
22
+ };
23
+
24
+ static VALUE
25
+ inner_funcall(VALUE args_)
26
+ {
27
+ struct funcall_args* args = (struct funcall_args*)args_;
28
+ return rb_funcallv(args->recv, args->mid, args->argc, args->argv);
29
+ }
30
+
31
+ VALUE
32
+ rb_protect_funcall(VALUE recv, ID mid, int* state, int n, ...)
33
+ {
34
+ struct funcall_args args;
35
+ VALUE* argv;
36
+ va_list ar;
37
+
38
+ if (n > 0) {
39
+ long i;
40
+ va_start(ar, n);
41
+ argv = ALLOCA_N(VALUE, n);
42
+ for (i = 0; i < n; i++) {
43
+ argv[i] = va_arg(ar, VALUE);
44
+ }
45
+ va_end(ar);
46
+ } else {
47
+ argv = 0;
48
+ }
49
+
50
+ args.recv = recv;
51
+ args.mid = mid;
52
+ args.argc = n;
53
+ args.argv = argv;
54
+
55
+ return rb_protect(inner_funcall, (VALUE)&args, state);
56
+ }
57
+
58
+ RGEO_END_C
59
+
60
+ #endif
@@ -0,0 +1,17 @@
1
+ /*
2
+ Utilities for the ruby CAPI
3
+ */
4
+
5
+ #ifndef RGEO_GEOS_RUBY_MORE_INCLUDED
6
+ #define RGEO_GEOS_RUBY_MORE_INCLUDED
7
+
8
+ #include <ruby.h>
9
+
10
+ RGEO_BEGIN_C
11
+
12
+ VALUE
13
+ rb_protect_funcall(VALUE recv, ID mid, int* state, int n, ...);
14
+
15
+ RGEO_END_C
16
+
17
+ #endif
@@ -290,7 +290,7 @@ module RGeo
290
290
  false
291
291
  elsif @has_m && rhs.has_m && !opts[:ignore_m] && (@min_m > rhs.min_m || @max_m < rhs.max_m)
292
292
  false
293
- elsif @has_z && rhs.has_z && !opts[:ignore_z] && (@min_z > rhs.min_z || @max_z < rhs.max_z)
293
+ elsif @has_z && rhs.has_z && !opts[:ignore_z] && (@min_z > rhs.min_z || @max_z < rhs.max_z) # rubocop:disable Style/IfWithBooleanLiteralBranches
294
294
  false
295
295
  else
296
296
  true