rgeo 2.3.1 → 3.0.0.pre.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +11 -10
  4. data/ext/geos_c_impl/analysis.c +8 -6
  5. data/ext/geos_c_impl/analysis.h +1 -3
  6. data/ext/geos_c_impl/errors.c +10 -8
  7. data/ext/geos_c_impl/errors.h +7 -3
  8. data/ext/geos_c_impl/extconf.rb +3 -0
  9. data/ext/geos_c_impl/factory.c +273 -202
  10. data/ext/geos_c_impl/factory.h +51 -63
  11. data/ext/geos_c_impl/geometry.c +124 -22
  12. data/ext/geos_c_impl/geometry.h +8 -3
  13. data/ext/geos_c_impl/geometry_collection.c +81 -185
  14. data/ext/geos_c_impl/geometry_collection.h +1 -14
  15. data/ext/geos_c_impl/globals.c +91 -0
  16. data/ext/geos_c_impl/globals.h +45 -0
  17. data/ext/geos_c_impl/line_string.c +28 -29
  18. data/ext/geos_c_impl/line_string.h +1 -3
  19. data/ext/geos_c_impl/main.c +10 -9
  20. data/ext/geos_c_impl/point.c +9 -8
  21. data/ext/geos_c_impl/point.h +1 -3
  22. data/ext/geos_c_impl/polygon.c +43 -72
  23. data/ext/geos_c_impl/polygon.h +1 -3
  24. data/ext/geos_c_impl/preface.h +12 -0
  25. data/ext/geos_c_impl/ruby_more.c +65 -0
  26. data/ext/geos_c_impl/ruby_more.h +16 -0
  27. data/lib/rgeo/cartesian/calculations.rb +54 -17
  28. data/lib/rgeo/cartesian/factory.rb +6 -14
  29. data/lib/rgeo/cartesian/feature_classes.rb +68 -46
  30. data/lib/rgeo/cartesian/feature_methods.rb +67 -20
  31. data/lib/rgeo/cartesian/interface.rb +0 -36
  32. data/lib/rgeo/cartesian/planar_graph.rb +379 -0
  33. data/lib/rgeo/cartesian/sweepline_intersector.rb +149 -0
  34. data/lib/rgeo/cartesian/valid_op.rb +71 -0
  35. data/lib/rgeo/cartesian.rb +3 -0
  36. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +6 -6
  37. data/lib/rgeo/coord_sys.rb +0 -11
  38. data/lib/rgeo/error.rb +15 -0
  39. data/lib/rgeo/feature/factory_generator.rb +0 -3
  40. data/lib/rgeo/feature/geometry.rb +107 -28
  41. data/lib/rgeo/feature/geometry_collection.rb +13 -5
  42. data/lib/rgeo/feature/line_string.rb +3 -3
  43. data/lib/rgeo/feature/multi_surface.rb +3 -3
  44. data/lib/rgeo/feature/point.rb +4 -4
  45. data/lib/rgeo/feature/surface.rb +3 -3
  46. data/lib/rgeo/geographic/factory.rb +6 -7
  47. data/lib/rgeo/geographic/interface.rb +6 -49
  48. data/lib/rgeo/geographic/proj4_projector.rb +0 -2
  49. data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
  50. data/lib/rgeo/geographic/projected_feature_methods.rb +67 -28
  51. data/lib/rgeo/geographic/simple_mercator_projector.rb +0 -2
  52. data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
  53. data/lib/rgeo/geographic/spherical_feature_methods.rb +79 -2
  54. data/lib/rgeo/geos/capi_factory.rb +21 -38
  55. data/lib/rgeo/geos/capi_feature_classes.rb +54 -11
  56. data/lib/rgeo/geos/ffi_factory.rb +6 -35
  57. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  58. data/lib/rgeo/geos/ffi_feature_methods.rb +39 -5
  59. data/lib/rgeo/geos/interface.rb +0 -24
  60. data/lib/rgeo/geos/zm_factory.rb +0 -19
  61. data/lib/rgeo/geos/zm_feature_methods.rb +16 -0
  62. data/lib/rgeo/geos.rb +6 -3
  63. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +4 -4
  64. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -1
  65. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +15 -19
  66. data/lib/rgeo/impl_helper/basic_point_methods.rb +1 -1
  67. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +1 -1
  68. data/lib/rgeo/impl_helper/valid_op.rb +354 -0
  69. data/lib/rgeo/impl_helper/validity_check.rb +139 -0
  70. data/lib/rgeo/impl_helper.rb +1 -0
  71. data/lib/rgeo/version.rb +1 -1
  72. metadata +45 -9
  73. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  74. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  75. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -11,6 +11,8 @@
11
11
  #include <ruby.h>
12
12
  #include <geos_c.h>
13
13
 
14
+ #include "globals.h"
15
+
14
16
  #include "factory.h"
15
17
  #include "geometry.h"
16
18
  #include "point.h"
@@ -29,7 +31,7 @@ static VALUE method_line_string_geometry_type(VALUE self)
29
31
  result = Qnil;
30
32
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
31
33
  if (self_data->geom) {
32
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_line_string;
34
+ result = rgeo_feature_line_string_module;
33
35
  }
34
36
  return result;
35
37
  }
@@ -43,7 +45,7 @@ static VALUE method_linear_ring_geometry_type(VALUE self)
43
45
  result = Qnil;
44
46
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
45
47
  if (self_data->geom) {
46
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_linear_ring;
48
+ result = rgeo_feature_linear_ring_module;
47
49
  }
48
50
  return result;
49
51
  }
@@ -57,7 +59,7 @@ static VALUE method_line_geometry_type(VALUE self)
57
59
  result = Qnil;
58
60
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
59
61
  if (self_data->geom) {
60
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_line;
62
+ result = rgeo_feature_line_module;
61
63
  }
62
64
  return result;
63
65
  }
@@ -264,7 +266,7 @@ static VALUE method_line_string_project_point(VALUE self, VALUE point)
264
266
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
265
267
 
266
268
  if(self_geom && point) {
267
- geos_point = rgeo_convert_to_geos_geometry(factory, point, factory_data->globals->geos_point);
269
+ geos_point = rgeo_convert_to_geos_geometry(factory, point, rgeo_geos_point_class);
268
270
  location = GEOSProject_r(self_data->geos_context, self_geom, geos_point);
269
271
  result = DBL2NUM(location);
270
272
  }
@@ -290,7 +292,7 @@ static VALUE method_line_string_interpolate_point(VALUE self, VALUE loc_num)
290
292
 
291
293
  if(self_geom) {
292
294
  geos_point = GEOSInterpolate_r(self_data->geos_context, self_geom, location);
293
- result = rgeo_wrap_geos_geometry(factory, geos_point, factory_data->globals->geos_point);
295
+ result = rgeo_wrap_geos_geometry(factory, geos_point, rgeo_geos_point_class);
294
296
  }
295
297
 
296
298
  return result;
@@ -343,7 +345,7 @@ static VALUE method_line_string_eql(VALUE self, VALUE rhs)
343
345
  result = rgeo_geos_klasses_and_factories_eql(self, rhs);
344
346
  if (RTEST(result)) {
345
347
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
346
- result = rgeo_geos_coordseqs_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
348
+ result = rgeo_geos_geometries_strict_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
347
349
  }
348
350
  return result;
349
351
  }
@@ -358,8 +360,7 @@ static VALUE method_line_string_hash(VALUE self)
358
360
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
359
361
  factory = self_data->factory;
360
362
  hash = rb_hash_start(0);
361
- hash = rgeo_geos_objbase_hash(factory,
362
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_line_string, hash);
363
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_line_string_module, hash);
363
364
  hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
364
365
  return LONG2FIX(rb_hash_end(hash));
365
366
  }
@@ -374,8 +375,7 @@ static VALUE method_linear_ring_hash(VALUE self)
374
375
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
375
376
  factory = self_data->factory;
376
377
  hash = rb_hash_start(0);
377
- hash = rgeo_geos_objbase_hash(factory,
378
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_linear_ring, hash);
378
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_linear_ring_module, hash);
379
379
  hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
380
380
  return LONG2FIX(rb_hash_end(hash));
381
381
  }
@@ -390,8 +390,7 @@ static VALUE method_line_hash(VALUE self)
390
390
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
391
391
  factory = self_data->factory;
392
392
  hash = rb_hash_start(0);
393
- hash = rgeo_geos_objbase_hash(factory,
394
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_line, hash);
393
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_line_module, hash);
395
394
  hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
396
395
  return LONG2FIX(rb_hash_end(hash));
397
396
  }
@@ -415,7 +414,7 @@ static GEOSCoordSequence* coord_seq_from_array(VALUE factory, VALUE array, char
415
414
 
416
415
  Check_Type(array, T_ARRAY);
417
416
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
418
- point_type = factory_data->globals->feature_point;
417
+ point_type = rgeo_feature_point_module;
419
418
  len = (unsigned int)RARRAY_LEN(array);
420
419
  has_z = (char)(RGEO_FACTORY_DATA_PTR(factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
421
420
  dims = has_z ? 3 : 2;
@@ -448,7 +447,7 @@ static GEOSCoordSequence* coord_seq_from_array(VALUE factory, VALUE array, char
448
447
  }
449
448
  }
450
449
  if (!good) {
451
- free(coords);
450
+ FREE(coords);
452
451
  return NULL;
453
452
  }
454
453
  }
@@ -473,7 +472,7 @@ static GEOSCoordSequence* coord_seq_from_array(VALUE factory, VALUE array, char
473
472
  GEOSCoordSeq_setZ_r(context, coord_seq, len, has_z ? coords[2] : 0);
474
473
  }
475
474
  }
476
- free(coords);
475
+ FREE(coords);
477
476
  return coord_seq;
478
477
  }
479
478
 
@@ -491,7 +490,7 @@ static VALUE cmethod_create_line_string(VALUE module, VALUE factory, VALUE array
491
490
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
492
491
  geom = GEOSGeom_createLineString_r(factory_data->geos_context, coord_seq);
493
492
  if (geom) {
494
- result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_line_string);
493
+ result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_line_string_class);
495
494
  }
496
495
  }
497
496
  return result;
@@ -511,7 +510,7 @@ static VALUE cmethod_create_linear_ring(VALUE module, VALUE factory, VALUE array
511
510
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
512
511
  geom = GEOSGeom_createLinearRing_r(factory_data->geos_context, coord_seq);
513
512
  if (geom) {
514
- result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_linear_ring);
513
+ result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_linear_ring_class);
515
514
  }
516
515
  }
517
516
  return result;
@@ -557,7 +556,7 @@ static VALUE cmethod_create_line(VALUE module, VALUE factory, VALUE start, VALUE
557
556
  result = Qnil;
558
557
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
559
558
  has_z = (char)(factory_data->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
560
- point_type = factory_data->globals->feature_point;
559
+ point_type = rgeo_feature_point_module;
561
560
  context = factory_data->geos_context;
562
561
 
563
562
  start_geom = rgeo_convert_to_geos_geometry(factory, start, point_type);
@@ -570,7 +569,7 @@ static VALUE cmethod_create_line(VALUE module, VALUE factory, VALUE start, VALUE
570
569
  populate_geom_into_coord_seq(context, end_geom, coord_seq, 1, has_z);
571
570
  geom = GEOSGeom_createLineString_r(context, coord_seq);
572
571
  if (geom) {
573
- result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_line);
572
+ result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_line_class);
574
573
  }
575
574
  }
576
575
  }
@@ -631,26 +630,26 @@ static VALUE cmethod_linear_ring_copy_from(VALUE klass, VALUE factory, VALUE ori
631
630
  }
632
631
 
633
632
 
634
- void rgeo_init_geos_line_string(RGeo_Globals* globals)
633
+ void rgeo_init_geos_line_string()
635
634
  {
636
635
  VALUE geos_line_string_methods;
637
636
  VALUE geos_linear_ring_methods;
638
637
  VALUE geos_line_methods;
639
638
 
640
639
  // Class methods for CAPILineStringImpl
641
- rb_define_module_function(globals->geos_line_string, "create", cmethod_create_line_string, 2);
642
- rb_define_module_function(globals->geos_line_string, "_copy_from", cmethod_line_string_copy_from, 2);
640
+ rb_define_module_function(rgeo_geos_line_string_class, "create", cmethod_create_line_string, 2);
641
+ rb_define_module_function(rgeo_geos_line_string_class, "_copy_from", cmethod_line_string_copy_from, 2);
643
642
 
644
643
  // Class methods for CAPILinearRingImpl
645
- rb_define_module_function(globals->geos_linear_ring, "create", cmethod_create_linear_ring, 2);
646
- rb_define_module_function(globals->geos_linear_ring, "_copy_from", cmethod_linear_ring_copy_from, 2);
644
+ rb_define_module_function(rgeo_geos_linear_ring_class, "create", cmethod_create_linear_ring, 2);
645
+ rb_define_module_function(rgeo_geos_linear_ring_class, "_copy_from", cmethod_linear_ring_copy_from, 2);
647
646
 
648
647
  // Class methods for CAPILineImpl
649
- rb_define_module_function(globals->geos_line, "create", cmethod_create_line, 3);
650
- rb_define_module_function(globals->geos_line, "_copy_from", cmethod_line_copy_from, 2);
648
+ rb_define_module_function(rgeo_geos_line_class, "create", cmethod_create_line, 3);
649
+ rb_define_module_function(rgeo_geos_line_class, "_copy_from", cmethod_line_copy_from, 2);
651
650
 
652
651
  // CAPILineStringMethods module
653
- geos_line_string_methods = rb_define_module_under(globals->geos_module, "CAPILineStringMethods");
652
+ geos_line_string_methods = rb_define_module_under(rgeo_geos_module, "CAPILineStringMethods");
654
653
  rb_define_method(geos_line_string_methods, "rep_equals?", method_line_string_eql, 1);
655
654
  rb_define_method(geos_line_string_methods, "eql?", method_line_string_eql, 1);
656
655
  rb_define_method(geos_line_string_methods, "hash", method_line_string_hash, 0);
@@ -668,12 +667,12 @@ void rgeo_init_geos_line_string(RGeo_Globals* globals)
668
667
  rb_define_method(geos_line_string_methods, "coordinates", method_line_string_coordinates, 0);
669
668
 
670
669
  // CAPILinearRingMethods module
671
- geos_linear_ring_methods = rb_define_module_under(globals->geos_module, "CAPILinearRingMethods");
670
+ geos_linear_ring_methods = rb_define_module_under(rgeo_geos_module, "CAPILinearRingMethods");
672
671
  rb_define_method(geos_linear_ring_methods, "geometry_type", method_linear_ring_geometry_type, 0);
673
672
  rb_define_method(geos_linear_ring_methods, "hash", method_linear_ring_hash, 0);
674
673
 
675
674
  // CAPILineMethods module
676
- geos_line_methods = rb_define_module_under(globals->geos_module, "CAPILineMethods");
675
+ geos_line_methods = rb_define_module_under(rgeo_geos_module, "CAPILineMethods");
677
676
  rb_define_method(geos_line_methods, "geometry_type", method_line_geometry_type, 0);
678
677
  rb_define_method(geos_line_methods, "hash", method_line_hash, 0);
679
678
  }
@@ -9,8 +9,6 @@
9
9
  #include <ruby.h>
10
10
  #include <geos_c.h>
11
11
 
12
- #include "factory.h"
13
-
14
12
  RGEO_BEGIN_C
15
13
 
16
14
 
@@ -18,7 +16,7 @@ RGEO_BEGIN_C
18
16
  Initializes the line string module. This should be called after
19
17
  the geometry module is initialized.
20
18
  */
21
- void rgeo_init_geos_line_string(RGeo_Globals* globals);
19
+ void rgeo_init_geos_line_string();
22
20
 
23
21
  /*
24
22
  Determines whether the given GEOS line string is closed.
@@ -9,6 +9,8 @@
9
9
  #include <ruby.h>
10
10
  #include <geos_c.h>
11
11
 
12
+ #include "ruby_more.h"
13
+ #include "globals.h"
12
14
  #include "errors.h"
13
15
 
14
16
  #include "factory.h"
@@ -26,15 +28,14 @@ RGEO_BEGIN_C
26
28
  void Init_geos_c_impl()
27
29
  {
28
30
  #ifdef RGEO_GEOS_SUPPORTED
29
- RGeo_Globals* globals;
30
-
31
- globals = rgeo_init_geos_factory();
32
- rgeo_init_geos_geometry(globals);
33
- rgeo_init_geos_point(globals);
34
- rgeo_init_geos_line_string(globals);
35
- rgeo_init_geos_polygon(globals);
36
- rgeo_init_geos_geometry_collection(globals);
37
- rgeo_init_geos_analysis(globals);
31
+ rgeo_init_geos_globals();
32
+ rgeo_init_geos_factory();
33
+ rgeo_init_geos_geometry();
34
+ rgeo_init_geos_point();
35
+ rgeo_init_geos_line_string();
36
+ rgeo_init_geos_polygon();
37
+ rgeo_init_geos_geometry_collection();
38
+ rgeo_init_geos_analysis();
38
39
  rgeo_init_geos_errors();
39
40
  #endif
40
41
  }
@@ -9,6 +9,8 @@
9
9
  #include <ruby.h>
10
10
  #include <geos_c.h>
11
11
 
12
+ #include "globals.h"
13
+
12
14
  #include "factory.h"
13
15
  #include "geometry.h"
14
16
  #include "point.h"
@@ -26,7 +28,7 @@ static VALUE method_point_geometry_type(VALUE self)
26
28
  result = Qnil;
27
29
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
28
30
  if (self_data->geom) {
29
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_point;
31
+ result = rgeo_feature_point_module;
30
32
  }
31
33
  return result;
32
34
  }
@@ -153,7 +155,7 @@ static VALUE method_point_eql(VALUE self, VALUE rhs)
153
155
  result = rgeo_geos_klasses_and_factories_eql(self, rhs);
154
156
  if (RTEST(result)) {
155
157
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
156
- result = rgeo_geos_coordseqs_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
158
+ result = rgeo_geos_geometries_strict_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
157
159
  }
158
160
  return result;
159
161
  }
@@ -168,8 +170,7 @@ static VALUE method_point_hash(VALUE self)
168
170
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
169
171
  factory = self_data->factory;
170
172
  hash = rb_hash_start(0);
171
- hash = rgeo_geos_objbase_hash(factory,
172
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_point, hash);
173
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_point_module, hash);
173
174
  hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
174
175
  return LONG2FIX(rb_hash_end(hash));
175
176
  }
@@ -182,15 +183,15 @@ static VALUE cmethod_create(VALUE module, VALUE factory, VALUE x, VALUE y, VALUE
182
183
  }
183
184
 
184
185
 
185
- void rgeo_init_geos_point(RGeo_Globals* globals)
186
+ void rgeo_init_geos_point()
186
187
  {
187
188
  VALUE geos_point_methods;
188
189
 
189
190
  // Class methods for CAPIPointImpl
190
- rb_define_module_function(globals->geos_point, "create", cmethod_create, 4);
191
+ rb_define_module_function(rgeo_geos_point_class, "create", cmethod_create, 4);
191
192
 
192
193
  // CAPIPointMethods module
193
- geos_point_methods = rb_define_module_under(globals->geos_module, "CAPIPointMethods");
194
+ geos_point_methods = rb_define_module_under(rgeo_geos_module, "CAPIPointMethods");
194
195
  rb_define_method(geos_point_methods, "rep_equals?", method_point_eql, 1);
195
196
  rb_define_method(geos_point_methods, "eql?", method_point_eql, 1);
196
197
  rb_define_method(geos_point_methods, "hash", method_point_hash, 0);
@@ -221,7 +222,7 @@ VALUE rgeo_create_geos_point(VALUE factory, double x, double y, double z)
221
222
  if (GEOSCoordSeq_setZ_r(context, coord_seq, 0, z)) {
222
223
  geom = GEOSGeom_createPoint_r(context, coord_seq);
223
224
  if (geom) {
224
- result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_point);
225
+ result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_point_class);
225
226
  }
226
227
  }
227
228
  }
@@ -8,8 +8,6 @@
8
8
 
9
9
  #include <ruby.h>
10
10
 
11
- #include "factory.h"
12
-
13
11
  RGEO_BEGIN_C
14
12
 
15
13
 
@@ -17,7 +15,7 @@ RGEO_BEGIN_C
17
15
  Initializes the point module. This should be called after
18
16
  the geometry module is initialized.
19
17
  */
20
- void rgeo_init_geos_point(RGeo_Globals* globals);
18
+ void rgeo_init_geos_point();
21
19
 
22
20
  /*
23
21
  Creates a 3d point and returns the ruby object.
@@ -10,6 +10,8 @@
10
10
  #include <ruby.h>
11
11
  #include <geos_c.h>
12
12
 
13
+ #include "globals.h"
14
+
13
15
  #include "factory.h"
14
16
  #include "geometry.h"
15
17
  #include "line_string.h"
@@ -28,7 +30,7 @@ static VALUE method_polygon_eql(VALUE self, VALUE rhs)
28
30
  result = rgeo_geos_klasses_and_factories_eql(self, rhs);
29
31
  if (RTEST(result)) {
30
32
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
31
- result = rgeo_geos_polygons_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
33
+ result = rgeo_geos_geometries_strict_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
32
34
  }
33
35
  return result;
34
36
  }
@@ -43,8 +45,7 @@ static VALUE method_polygon_hash(VALUE self)
43
45
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
44
46
  factory = self_data->factory;
45
47
  hash = rb_hash_start(0);
46
- hash = rgeo_geos_objbase_hash(factory,
47
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_polygon, hash);
48
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_polygon_module, hash);
48
49
  hash = rgeo_geos_polygon_hash(self_data->geos_context, self_data->geom, hash);
49
50
  return LONG2FIX(rb_hash_end(hash));
50
51
  }
@@ -58,7 +59,7 @@ static VALUE method_polygon_geometry_type(VALUE self)
58
59
  result = Qnil;
59
60
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
60
61
  if (self_data->geom) {
61
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_polygon;
62
+ result = rgeo_feature_polygon_module;
62
63
  }
63
64
  return result;
64
65
  }
@@ -93,7 +94,7 @@ static VALUE method_polygon_centroid(VALUE self)
93
94
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
94
95
  self_geom = self_data->geom;
95
96
  if (self_geom) {
96
- result = rgeo_wrap_geos_geometry(self_data->factory, GEOSGetCentroid_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_point);
97
+ result = rgeo_wrap_geos_geometry(self_data->factory, GEOSGetCentroid_r(self_data->geos_context, self_geom), rgeo_geos_point_class);
97
98
  }
98
99
  return result;
99
100
  }
@@ -109,7 +110,7 @@ static VALUE method_polygon_point_on_surface(VALUE self)
109
110
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
110
111
  self_geom = self_data->geom;
111
112
  if (self_geom) {
112
- result = rgeo_wrap_geos_geometry(self_data->factory, GEOSPointOnSurface_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_point);
113
+ result = rgeo_wrap_geos_geometry(self_data->factory, GEOSPointOnSurface_r(self_data->geos_context, self_geom), rgeo_geos_point_class);
113
114
  }
114
115
  return result;
115
116
  }
@@ -145,7 +146,7 @@ static VALUE method_polygon_exterior_ring(VALUE self)
145
146
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
146
147
  self_geom = self_data->geom;
147
148
  if (self_geom) {
148
- result = rgeo_wrap_geos_geometry_clone(self_data->factory, GEOSGetExteriorRing_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring);
149
+ result = rgeo_wrap_geos_geometry_clone(self_data->factory, GEOSGetExteriorRing_r(self_data->geos_context, self_geom), rgeo_geos_linear_ring_class);
149
150
  }
150
151
  return result;
151
152
  }
@@ -191,7 +192,7 @@ static VALUE method_polygon_interior_ring_n(VALUE self, VALUE n)
191
192
  if (i < num) {
192
193
  result = rgeo_wrap_geos_geometry_clone(self_data->factory,
193
194
  GEOSGetInteriorRingN_r(self_context, self_geom, i),
194
- RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring);
195
+ rgeo_geos_linear_ring_class);
195
196
  }
196
197
  }
197
198
  }
@@ -219,9 +220,8 @@ static VALUE method_polygon_interior_rings(VALUE self)
219
220
  if (count >= 0) {
220
221
  result = rb_ary_new2(count);
221
222
  factory = self_data->factory;
222
- linear_ring_class = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring;
223
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), linear_ring_class));
224
+ rb_ary_store(result, i, rgeo_wrap_geos_geometry_clone(factory, GEOSGetInteriorRingN_r(self_context, self_geom, i), rgeo_geos_linear_ring_class));
225
225
  }
226
226
  }
227
227
  }
@@ -241,50 +241,57 @@ static VALUE cmethod_create(VALUE module, VALUE factory, VALUE exterior, VALUE i
241
241
  unsigned int i;
242
242
  GEOSGeometry* interior_geom;
243
243
  GEOSGeometry* polygon;
244
+ int state = 0;
244
245
 
245
246
  Check_Type(interior_array, T_ARRAY);
246
247
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
247
- linear_ring_type = factory_data->globals->feature_linear_ring;
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
- }
248
+ linear_ring_type = rgeo_feature_linear_ring_module;
249
+ exterior_geom = rgeo_convert_to_detached_geos_geometry(exterior, factory, linear_ring_type, NULL, &state);
250
+ if (state) { rb_exc_raise(rb_errinfo()); }
251
+ if (!exterior_geom) { return Qnil; }
252
+
253
+ context = factory_data->geos_context;
254
+ len = (unsigned int)RARRAY_LEN(interior_array);
255
+ interior_geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
256
+ if (interior_geoms) {
257
+ actual_len = 0;
258
+ for (i=0; i<len; ++i) {
259
+ interior_geom = rgeo_convert_to_detached_geos_geometry(rb_ary_entry(interior_array, i), factory, linear_ring_type, NULL, &state);
260
+ if (interior_geom) {
261
+ interior_geoms[actual_len++] = interior_geom;
260
262
  }
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, factory_data->globals->geos_polygon);
266
- }
263
+ if (state) {
264
+ break;
267
265
  }
268
- for (i=0; i<actual_len; ++i) {
269
- GEOSGeom_destroy_r(context, interior_geoms[i]);
266
+ }
267
+ if (len == actual_len) {
268
+ polygon = GEOSGeom_createPolygon_r(context, exterior_geom, interior_geoms, actual_len);
269
+ if (polygon) {
270
+ FREE(interior_geoms);
271
+ // NOTE: we can return safely here, state cannot be other than 0.
272
+ return rgeo_wrap_geos_geometry(factory, polygon, rgeo_geos_polygon_class);
270
273
  }
271
- free(interior_geoms);
272
274
  }
273
- GEOSGeom_destroy_r(context, exterior_geom);
275
+ for (i=0; i<actual_len; ++i) {
276
+ GEOSGeom_destroy_r(context, interior_geoms[i]);
277
+ }
278
+ FREE(interior_geoms);
274
279
  }
280
+ GEOSGeom_destroy_r(context, exterior_geom);
281
+ if (state) { rb_exc_raise(rb_errinfo()); }
275
282
  return Qnil;
276
283
  }
277
284
 
278
285
 
279
- void rgeo_init_geos_polygon(RGeo_Globals* globals)
286
+ void rgeo_init_geos_polygon()
280
287
  {
281
288
  VALUE geos_polygon_methods;
282
289
 
283
290
  // Class methods for CAPIPolygonImpl
284
- rb_define_module_function(globals->geos_polygon, "create", cmethod_create, 3);
291
+ rb_define_module_function(rgeo_geos_polygon_class, "create", cmethod_create, 3);
285
292
 
286
293
  // CAPIPolygonMethods module
287
- geos_polygon_methods = rb_define_module_under(globals->geos_module, "CAPIPolygonMethods");
294
+ geos_polygon_methods = rb_define_module_under(rgeo_geos_module, "CAPIPolygonMethods");
288
295
  rb_define_method(geos_polygon_methods, "rep_equals?", method_polygon_eql, 1);
289
296
  rb_define_method(geos_polygon_methods, "eql?", method_polygon_eql, 1);
290
297
  rb_define_method(geos_polygon_methods, "hash", method_polygon_hash, 0);
@@ -299,42 +306,6 @@ void rgeo_init_geos_polygon(RGeo_Globals* globals)
299
306
  rb_define_method(geos_polygon_methods, "coordinates", method_polygon_coordinates, 0);
300
307
  }
301
308
 
302
-
303
- VALUE rgeo_geos_polygons_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z)
304
- {
305
- VALUE result;
306
- int len1;
307
- int len2;
308
- int i;
309
-
310
- result = Qnil;
311
- if (geom1 && geom2) {
312
- result = rgeo_geos_coordseqs_eql(context, GEOSGetExteriorRing_r(context, geom1), GEOSGetExteriorRing_r(context, geom2), check_z);
313
- if (RTEST(result)) {
314
- len1 = GEOSGetNumInteriorRings_r(context, geom1);
315
- len2 = GEOSGetNumInteriorRings_r(context, geom2);
316
- if (len1 >= 0 && len2 >= 0) {
317
- if (len1 == len2) {
318
- for (i=0; i<len1; ++i) {
319
- result = rgeo_geos_coordseqs_eql(context, GEOSGetInteriorRingN_r(context, geom1, i), GEOSGetInteriorRingN_r(context, geom2, i), check_z);
320
- if (!RTEST(result)) {
321
- break;
322
- }
323
- }
324
- }
325
- else {
326
- result = Qfalse;
327
- }
328
- }
329
- else {
330
- result = Qnil;
331
- }
332
- }
333
- }
334
- return result;
335
- }
336
-
337
-
338
309
  st_index_t rgeo_geos_polygon_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash)
339
310
  {
340
311
  unsigned int len;
@@ -9,8 +9,6 @@
9
9
  #include <ruby.h>
10
10
  #include <geos_c.h>
11
11
 
12
- #include "factory.h"
13
-
14
12
  RGEO_BEGIN_C
15
13
 
16
14
 
@@ -18,7 +16,7 @@ RGEO_BEGIN_C
18
16
  Initializes the polygon module. This should be called after
19
17
  the geometry module is initialized.
20
18
  */
21
- void rgeo_init_geos_polygon(RGeo_Globals* globals);
19
+ void rgeo_init_geos_polygon();
22
20
 
23
21
  /*
24
22
  Comopares the values of two GEOS polygons. The two given geometries MUST
@@ -27,6 +27,11 @@
27
27
  #ifdef HAVE_RB_MEMHASH
28
28
  #define RGEO_SUPPORTS_NEW_HASHING
29
29
  #endif
30
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
31
+ #define mark rb_gc_mark_movable
32
+ #else
33
+ #define mark rb_gc_mark
34
+ #endif
30
35
 
31
36
  #ifndef RGEO_SUPPORTS_NEW_HASHING
32
37
  #define st_index_t int
@@ -42,3 +47,10 @@
42
47
  #define RGEO_BEGIN_C
43
48
  #define RGEO_END_C
44
49
  #endif
50
+
51
+ // https://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html
52
+ #define streq(a, b) (!strcmp((a),(b)))
53
+
54
+ // When using ruby ALLOC* macros, we are using ruby_xmalloc, which counterpart
55
+ // is ruby_xfree. This macro helps enforcing that by showing us the way.
56
+ #define FREE ruby_xfree
@@ -0,0 +1,65 @@
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
+ #include "preface.h"
11
+ #include "ruby_more.h"
12
+
13
+ RGEO_BEGIN_C
14
+
15
+ struct funcall_args
16
+ {
17
+ VALUE recv;
18
+ ID mid;
19
+ int argc;
20
+ VALUE *argv;
21
+ };
22
+
23
+ static VALUE inner_funcall(VALUE args_)
24
+ {
25
+ struct funcall_args *args = (struct funcall_args *)args_;
26
+ return rb_funcallv(
27
+ args->recv,
28
+ args->mid,
29
+ args->argc,
30
+ args->argv);
31
+ }
32
+
33
+ VALUE rb_protect_funcall(VALUE recv, ID mid, int *state, int n, ...)
34
+ {
35
+ struct funcall_args args;
36
+ VALUE *argv;
37
+ va_list ar;
38
+
39
+ if (n > 0)
40
+ {
41
+ long i;
42
+ va_start(ar, n);
43
+ argv = ALLOCA_N(VALUE, n);
44
+ for (i = 0; i < n; i++)
45
+ {
46
+ argv[i] = va_arg(ar, VALUE);
47
+ }
48
+ va_end(ar);
49
+ }
50
+ else
51
+ {
52
+ argv = 0;
53
+ }
54
+
55
+ args.recv = recv;
56
+ args.mid = mid;
57
+ args.argc = n;
58
+ args.argv = argv;
59
+
60
+ return rb_protect(inner_funcall, (VALUE)&args, state);
61
+ }
62
+
63
+ RGEO_END_C
64
+
65
+ #endif
@@ -0,0 +1,16 @@
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 rb_protect_funcall(VALUE recv, ID mid, int *state, int n, ...);
13
+
14
+ RGEO_END_C
15
+
16
+ #endif