rgeo 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/History.rdoc +6 -0
  2. data/README.rdoc +1 -1
  3. data/Version +1 -1
  4. data/ext/geos_c_impl/extconf.rb +13 -13
  5. data/ext/geos_c_impl/factory.c +30 -18
  6. data/ext/geos_c_impl/factory.h +18 -12
  7. data/ext/geos_c_impl/geometry.c +11 -11
  8. data/ext/geos_c_impl/geometry.h +7 -7
  9. data/ext/geos_c_impl/geometry_collection.c +15 -15
  10. data/ext/geos_c_impl/geometry_collection.h +8 -8
  11. data/ext/geos_c_impl/line_string.c +14 -14
  12. data/ext/geos_c_impl/line_string.h +7 -7
  13. data/ext/geos_c_impl/main.c +7 -7
  14. data/ext/geos_c_impl/point.c +9 -9
  15. data/ext/geos_c_impl/point.h +7 -7
  16. data/ext/geos_c_impl/polygon.c +9 -9
  17. data/ext/geos_c_impl/polygon.h +7 -7
  18. data/ext/geos_c_impl/preface.h +7 -7
  19. data/ext/proj4_c_impl/extconf.rb +13 -13
  20. data/ext/proj4_c_impl/main.c +12 -12
  21. data/lib/rgeo.rb +26 -26
  22. data/lib/rgeo/cartesian.rb +12 -12
  23. data/lib/rgeo/cartesian/analysis.rb +26 -26
  24. data/lib/rgeo/cartesian/bounding_box.rb +83 -83
  25. data/lib/rgeo/cartesian/calculations.rb +36 -36
  26. data/lib/rgeo/cartesian/factory.rb +78 -78
  27. data/lib/rgeo/cartesian/feature_classes.rb +74 -74
  28. data/lib/rgeo/cartesian/feature_methods.rb +34 -34
  29. data/lib/rgeo/cartesian/interface.rb +33 -33
  30. data/lib/rgeo/coord_sys.rb +15 -15
  31. data/lib/rgeo/coord_sys/cs/entities.rb +533 -534
  32. data/lib/rgeo/coord_sys/cs/factories.rb +69 -69
  33. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +44 -44
  34. data/lib/rgeo/coord_sys/proj4.rb +85 -85
  35. data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +31 -31
  36. data/lib/rgeo/coord_sys/srs_database/interface.rb +44 -44
  37. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +31 -31
  38. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +31 -31
  39. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +29 -29
  40. data/lib/rgeo/error.rb +17 -17
  41. data/lib/rgeo/feature.rb +15 -15
  42. data/lib/rgeo/feature/curve.rb +58 -58
  43. data/lib/rgeo/feature/factory.rb +84 -84
  44. data/lib/rgeo/feature/factory_generator.rb +32 -32
  45. data/lib/rgeo/feature/geometry.rb +215 -215
  46. data/lib/rgeo/feature/geometry_collection.rb +46 -46
  47. data/lib/rgeo/feature/line.rb +21 -21
  48. data/lib/rgeo/feature/line_string.rb +35 -35
  49. data/lib/rgeo/feature/linear_ring.rb +20 -20
  50. data/lib/rgeo/feature/mixins.rb +61 -61
  51. data/lib/rgeo/feature/multi_curve.rb +37 -37
  52. data/lib/rgeo/feature/multi_line_string.rb +20 -20
  53. data/lib/rgeo/feature/multi_point.rb +22 -22
  54. data/lib/rgeo/feature/multi_polygon.rb +28 -28
  55. data/lib/rgeo/feature/multi_surface.rb +39 -39
  56. data/lib/rgeo/feature/point.rb +42 -42
  57. data/lib/rgeo/feature/polygon.rb +50 -50
  58. data/lib/rgeo/feature/surface.rb +42 -42
  59. data/lib/rgeo/feature/types.rb +58 -58
  60. data/lib/rgeo/geographic.rb +14 -14
  61. data/lib/rgeo/geographic/factory.rb +87 -87
  62. data/lib/rgeo/geographic/interface.rb +55 -55
  63. data/lib/rgeo/geographic/proj4_projector.rb +35 -35
  64. data/lib/rgeo/geographic/projected_feature_classes.rb +95 -95
  65. data/lib/rgeo/geographic/projected_feature_methods.rb +81 -81
  66. data/lib/rgeo/geographic/projected_window.rb +103 -103
  67. data/lib/rgeo/geographic/simple_mercator_projector.rb +32 -32
  68. data/lib/rgeo/geographic/spherical_feature_classes.rb +93 -93
  69. data/lib/rgeo/geographic/spherical_feature_methods.rb +25 -25
  70. data/lib/rgeo/geographic/spherical_math.rb +58 -58
  71. data/lib/rgeo/geos.rb +22 -17
  72. data/lib/rgeo/geos/factory.rb +93 -93
  73. data/lib/rgeo/geos/ffi_classes.rb +306 -231
  74. data/lib/rgeo/geos/ffi_factory.rb +100 -96
  75. data/lib/rgeo/geos/impl_additions.rb +22 -22
  76. data/lib/rgeo/geos/interface.rb +45 -45
  77. data/lib/rgeo/geos/zm_factory.rb +90 -90
  78. data/lib/rgeo/geos/zm_impl.rb +167 -167
  79. data/lib/rgeo/impl_helper.rb +11 -11
  80. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +71 -71
  81. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +29 -29
  82. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +61 -61
  83. data/lib/rgeo/impl_helper/basic_point_methods.rb +43 -43
  84. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +35 -35
  85. data/lib/rgeo/impl_helper/math.rb +13 -13
  86. data/lib/rgeo/version.rb +10 -10
  87. data/lib/rgeo/wkrep.rb +16 -16
  88. data/lib/rgeo/wkrep/wkb_generator.rb +51 -51
  89. data/lib/rgeo/wkrep/wkb_parser.rb +52 -52
  90. data/lib/rgeo/wkrep/wkt_generator.rb +51 -51
  91. data/lib/rgeo/wkrep/wkt_parser.rb +66 -66
  92. data/lib/rgeo/yaml.rb +14 -14
  93. data/test/common/geometry_collection_tests.rb +53 -53
  94. data/test/common/line_string_tests.rb +57 -57
  95. data/test/common/multi_line_string_tests.rb +43 -43
  96. data/test/common/multi_point_tests.rb +43 -43
  97. data/test/common/multi_polygon_tests.rb +43 -43
  98. data/test/common/point_tests.rb +75 -75
  99. data/test/common/polygon_tests.rb +37 -37
  100. data/test/coord_sys/tc_active_record_table.rb +25 -25
  101. data/test/coord_sys/tc_ogc_cs.rb +72 -72
  102. data/test/coord_sys/tc_proj4.rb +51 -51
  103. data/test/coord_sys/tc_proj4_srs_data.rb +17 -17
  104. data/test/coord_sys/tc_sr_org.rb +15 -15
  105. data/test/coord_sys/tc_url_reader.rb +19 -19
  106. data/test/geos_capi/tc_factory.rb +21 -21
  107. data/test/geos_capi/tc_geometry_collection.rb +15 -15
  108. data/test/geos_capi/tc_line_string.rb +15 -15
  109. data/test/geos_capi/tc_misc.rb +33 -22
  110. data/test/geos_capi/tc_multi_line_string.rb +15 -15
  111. data/test/geos_capi/tc_multi_point.rb +15 -15
  112. data/test/geos_capi/tc_multi_polygon.rb +15 -15
  113. data/test/geos_capi/tc_parsing_unparsing.rb +19 -19
  114. data/test/geos_capi/tc_point.rb +21 -21
  115. data/test/geos_capi/tc_polygon.rb +19 -19
  116. data/test/geos_capi/tc_zmfactory.rb +17 -17
  117. data/test/geos_ffi/tc_factory.rb +21 -21
  118. data/test/geos_ffi/tc_geometry_collection.rb +15 -15
  119. data/test/geos_ffi/tc_line_string.rb +15 -15
  120. data/test/geos_ffi/tc_misc.rb +49 -15
  121. data/test/geos_ffi/tc_multi_line_string.rb +15 -15
  122. data/test/geos_ffi/tc_multi_point.rb +15 -15
  123. data/test/geos_ffi/tc_multi_polygon.rb +15 -15
  124. data/test/geos_ffi/tc_parsing_unparsing.rb +19 -19
  125. data/test/geos_ffi/tc_point.rb +21 -21
  126. data/test/geos_ffi/tc_polygon.rb +19 -19
  127. data/test/geos_ffi/tc_zmfactory.rb +17 -17
  128. data/test/projected_geographic/tc_geometry_collection.rb +15 -15
  129. data/test/projected_geographic/tc_line_string.rb +15 -15
  130. data/test/projected_geographic/tc_multi_line_string.rb +15 -15
  131. data/test/projected_geographic/tc_multi_point.rb +15 -15
  132. data/test/projected_geographic/tc_multi_polygon.rb +15 -15
  133. data/test/projected_geographic/tc_point.rb +23 -23
  134. data/test/projected_geographic/tc_polygon.rb +15 -15
  135. data/test/simple_cartesian/tc_calculations.rb +31 -31
  136. data/test/simple_cartesian/tc_geometry_collection.rb +17 -17
  137. data/test/simple_cartesian/tc_line_string.rb +17 -17
  138. data/test/simple_cartesian/tc_multi_line_string.rb +17 -17
  139. data/test/simple_cartesian/tc_multi_point.rb +17 -17
  140. data/test/simple_cartesian/tc_multi_polygon.rb +17 -17
  141. data/test/simple_cartesian/tc_point.rb +21 -21
  142. data/test/simple_cartesian/tc_polygon.rb +17 -17
  143. data/test/simple_mercator/tc_geometry_collection.rb +15 -15
  144. data/test/simple_mercator/tc_line_string.rb +15 -15
  145. data/test/simple_mercator/tc_multi_line_string.rb +15 -15
  146. data/test/simple_mercator/tc_multi_point.rb +15 -15
  147. data/test/simple_mercator/tc_multi_polygon.rb +15 -15
  148. data/test/simple_mercator/tc_point.rb +23 -23
  149. data/test/simple_mercator/tc_polygon.rb +15 -15
  150. data/test/simple_mercator/tc_window.rb +50 -50
  151. data/test/spherical_geographic/tc_calculations.rb +47 -47
  152. data/test/spherical_geographic/tc_geometry_collection.rb +17 -17
  153. data/test/spherical_geographic/tc_line_string.rb +17 -17
  154. data/test/spherical_geographic/tc_multi_line_string.rb +17 -17
  155. data/test/spherical_geographic/tc_multi_point.rb +17 -17
  156. data/test/spherical_geographic/tc_multi_polygon.rb +17 -17
  157. data/test/spherical_geographic/tc_point.rb +23 -23
  158. data/test/spherical_geographic/tc_polygon.rb +17 -17
  159. data/test/tc_cartesian_analysis.rb +23 -23
  160. data/test/tc_mixins.rb +39 -39
  161. data/test/tc_oneoff.rb +15 -15
  162. data/test/tc_types.rb +17 -17
  163. data/test/wkrep/tc_wkb_generator.rb +67 -67
  164. data/test/wkrep/tc_wkb_parser.rb +73 -73
  165. data/test/wkrep/tc_wkt_generator.rb +75 -75
  166. data/test/wkrep/tc_wkt_parser.rb +97 -97
  167. metadata +3 -3
data/History.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.3.4 / 2012-02-21
2
+
3
+ * The FFI-GEOS implementation now uses prepared geometries.
4
+ * Fixed a segfault that sometimes happened when passing a non-GEOS geometry as an argument to a GEOS function under Ruby 1.8.7. (Reported by Greg Hazel.)
5
+ * A few minor optimizations in the C extension for GEOS.
6
+
1
7
  === 0.3.3 / 2011-12-19
2
8
 
3
9
  * Recognizes MultiPoint WKTs in which individual points are not contained in parens. This is technically incorrect syntax, but apparently there are examples in the wild so we are now supporting it. (Reported by J Smith.)
data/README.rdoc CHANGED
@@ -49,7 +49,7 @@ RGeo is known to work with the following Ruby implementations:
49
49
  * Standard "MRI" Ruby 1.8.7 or later. (1.9.2 or later preferred.)
50
50
  * Rubinius 1.1 or later.
51
51
  * Partial support for JRuby 1.6.3 or later. The FFI implementation of
52
- GEOS is available (ffi-geos gem is required) but CAPI is not.
52
+ GEOS is available (ffi-geos gem required) but CAPI is not.
53
53
  Proj4 support is expected in the future.
54
54
 
55
55
  Some features also require the following:
data/Version CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Makefile builder for GEOS wrapper
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,13 +35,13 @@
35
35
 
36
36
 
37
37
  if ::RUBY_DESCRIPTION =~ /^jruby\s/
38
-
38
+
39
39
  ::File.open('Makefile', 'w'){ |f_| f_.write(".PHONY: install\ninstall:\n") }
40
-
40
+
41
41
  else
42
-
42
+
43
43
  require 'mkmf'
44
-
44
+
45
45
  header_dirs_ =
46
46
  [
47
47
  '/usr/local/include',
@@ -66,7 +66,7 @@ else
66
66
  ]
67
67
  header_dirs_.delete_if{ |path_| !::File.directory?(path_) }
68
68
  lib_dirs_.delete_if{ |path_| !::File.directory?(path_) }
69
-
69
+
70
70
  found_geos_ = false
71
71
  header_dirs_, lib_dirs_ = dir_config('geos', header_dirs_, lib_dirs_)
72
72
  if have_header('geos_c.h')
@@ -84,5 +84,5 @@ else
84
84
  puts "**** Compiling without GEOS support."
85
85
  end
86
86
  create_makefile('rgeo/geos/geos_c_impl')
87
-
87
+
88
88
  end
@@ -1,16 +1,16 @@
1
1
  /*
2
2
  -----------------------------------------------------------------------------
3
-
3
+
4
4
  Factory and utility functions for GEOS wrapper
5
-
5
+
6
6
  -----------------------------------------------------------------------------
7
- Copyright 2010 Daniel Azuma
8
-
7
+ Copyright 2010-2012 Daniel Azuma
8
+
9
9
  All rights reserved.
10
-
10
+
11
11
  Redistribution and use in source and binary forms, with or without
12
12
  modification, are permitted provided that the following conditions are met:
13
-
13
+
14
14
  * Redistributions of source code must retain the above copyright notice,
15
15
  this list of conditions and the following disclaimer.
16
16
  * Redistributions in binary form must reproduce the above copyright notice,
@@ -19,7 +19,7 @@
19
19
  * Neither the name of the copyright holder, nor the names of any other
20
20
  contributors to this software, may be used to endorse or promote products
21
21
  derived from this software without specific prior written permission.
22
-
22
+
23
23
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
24
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
25
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -180,7 +180,7 @@ static VALUE method_factory_parse_wkt(VALUE self, VALUE str)
180
180
  GEOSWKTReader* wkt_reader;
181
181
  VALUE result;
182
182
  GEOSGeometry* geom;
183
-
183
+
184
184
  Check_Type(str, T_STRING);
185
185
  self_data = RGEO_FACTORY_DATA_PTR(self);
186
186
  self_context = self_data->geos_context;
@@ -207,7 +207,7 @@ static VALUE method_factory_parse_wkb(VALUE self, VALUE str)
207
207
  GEOSWKBReader* wkb_reader;
208
208
  VALUE result;
209
209
  GEOSGeometry* geom;
210
-
210
+
211
211
  Check_Type(str, T_STRING);
212
212
  self_data = RGEO_FACTORY_DATA_PTR(self);
213
213
  self_context = self_data->geos_context;
@@ -234,7 +234,7 @@ static VALUE cmethod_factory_create(VALUE klass, VALUE flags, VALUE srid, VALUE
234
234
  RGeo_FactoryData* data;
235
235
  GEOSContextHandle_t context;
236
236
  VALUE wrapped_globals;
237
-
237
+
238
238
  result = Qnil;
239
239
  data = ALLOC(RGeo_FactoryData);
240
240
  if (data) {
@@ -277,7 +277,13 @@ RGeo_Globals* rgeo_init_geos_factory()
277
277
  globals->geos_module = rb_define_module_under(rgeo_module, "Geos");
278
278
  globals->feature_module = rb_define_module_under(rgeo_module, "Feature");
279
279
  globals->global_mixins = rb_const_get_at(rb_const_get_at(globals->feature_module, rb_intern("MixinCollection")), rb_intern("GLOBAL"));
280
-
280
+
281
+ globals->id_cast = rb_intern("cast");
282
+ globals->id_eql = rb_intern("eql?");
283
+ globals->id_generate = rb_intern("generate");
284
+ globals->sym_force_new = ID2SYM(rb_intern("force_new"));
285
+ globals->sym_keep_subtype = ID2SYM(rb_intern("keep_subtype"));
286
+
281
287
  // Add C methods to the factory.
282
288
  geos_factory_class = rb_const_get_at(globals->geos_module, rb_intern("Factory"));
283
289
  rb_define_method(geos_factory_class, "_parse_wkt_impl", method_factory_parse_wkt, 1);
@@ -286,12 +292,12 @@ RGeo_Globals* rgeo_init_geos_factory()
286
292
  rb_define_method(geos_factory_class, "_buffer_resolution", method_factory_buffer_resolution, 0);
287
293
  rb_define_method(geos_factory_class, "_flags", method_factory_flags, 0);
288
294
  rb_define_module_function(geos_factory_class, "_create", cmethod_factory_create, 5);
289
-
295
+
290
296
  // Wrap the globals in a Ruby object and store it off so we have access
291
297
  // to it later. Each factory instance will reference it internally.
292
298
  wrapped_globals = Data_Wrap_Struct(rb_cObject, mark_globals_func, destroy_globals_func, globals);
293
299
  rb_define_const(geos_factory_class, "INTERNAL_CGLOBALS", wrapped_globals);
294
-
300
+
295
301
  return globals;
296
302
  }
297
303
 
@@ -395,12 +401,14 @@ const GEOSGeometry* rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALU
395
401
  {
396
402
  VALUE object;
397
403
  const GEOSGeometry* geom;
404
+ RGeo_Globals* globals;
398
405
 
399
- if (NIL_P(type) && RGEO_GEOMETRY_DATA_PTR(obj)->factory == factory) {
406
+ if (NIL_P(type) && TYPE(obj) == T_DATA && RDATA(obj)->dfree == (RUBY_DATA_FUNC)destroy_geometry_func && RGEO_GEOMETRY_DATA_PTR(obj)->factory == factory) {
400
407
  object = obj;
401
408
  }
402
409
  else {
403
- object = rb_funcall(RGEO_FACTORY_DATA_PTR(factory)->globals->feature_module, rb_intern("cast"), 3, obj, factory, type);
410
+ globals = RGEO_FACTORY_DATA_PTR(factory)->globals;
411
+ object = rb_funcall(globals->feature_module, globals->id_cast, 3, obj, factory, type);
404
412
  }
405
413
  geom = NULL;
406
414
  if (!NIL_P(object)) {
@@ -416,11 +424,13 @@ GEOSGeometry* rgeo_convert_to_detached_geos_geometry(VALUE obj, VALUE factory, V
416
424
  GEOSGeometry* geom;
417
425
  RGeo_GeometryData* object_data;
418
426
  const GEOSPreparedGeometry* prep;
427
+ RGeo_Globals* globals;
419
428
 
420
429
  if (klasses) {
421
430
  *klasses = Qnil;
422
431
  }
423
- object = rb_funcall(RGEO_FACTORY_DATA_PTR(factory)->globals->feature_module, rb_intern("cast"), 5, obj, factory, type, ID2SYM(rb_intern("force_new")), ID2SYM(rb_intern("keep_subtype")));
432
+ globals = RGEO_FACTORY_DATA_PTR(factory)->globals;
433
+ object = rb_funcall(globals->feature_module, globals->id_cast, 5, obj, factory, type, globals->sym_force_new, globals->sym_keep_subtype);
424
434
  geom = NULL;
425
435
  if (!NIL_P(object)) {
426
436
  object_data = RGEO_GEOMETRY_DATA_PTR(object);
@@ -533,13 +543,15 @@ VALUE rgeo_geos_coordseqs_eql(GEOSContextHandle_t context, const GEOSGeometry* g
533
543
  VALUE rgeo_geos_klasses_and_factories_eql(VALUE obj1, VALUE obj2)
534
544
  {
535
545
  VALUE result;
536
-
546
+ VALUE factory;
547
+
537
548
  result = Qnil;
538
549
  if (rb_obj_class(obj1) != rb_obj_class(obj2)) {
539
550
  result = Qfalse;
540
551
  }
541
552
  else {
542
- result = rb_funcall(RGEO_GEOMETRY_DATA_PTR(obj1)->factory, rb_intern("eql?"), 1, RGEO_GEOMETRY_DATA_PTR(obj2)->factory);
553
+ factory = RGEO_GEOMETRY_DATA_PTR(obj1)->factory;
554
+ result = rb_funcall(factory, RGEO_FACTORY_DATA_PTR(factory)->globals->id_eql, 1, RGEO_GEOMETRY_DATA_PTR(obj2)->factory);
543
555
  }
544
556
  return result;
545
557
  }
@@ -1,16 +1,16 @@
1
1
  /*
2
2
  -----------------------------------------------------------------------------
3
-
3
+
4
4
  Factory and utility functions for GEOS wrapper
5
-
5
+
6
6
  -----------------------------------------------------------------------------
7
- Copyright 2010 Daniel Azuma
8
-
7
+ Copyright 2010-2012 Daniel Azuma
8
+
9
9
  All rights reserved.
10
-
10
+
11
11
  Redistribution and use in source and binary forms, with or without
12
12
  modification, are permitted provided that the following conditions are met:
13
-
13
+
14
14
  * Redistributions of source code must retain the above copyright notice,
15
15
  this list of conditions and the following disclaimer.
16
16
  * Redistributions in binary form must reproduce the above copyright notice,
@@ -19,7 +19,7 @@
19
19
  * Neither the name of the copyright holder, nor the names of any other
20
20
  contributors to this software, may be used to endorse or promote products
21
21
  derived from this software without specific prior written permission.
22
-
22
+
23
23
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
24
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
25
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -46,8 +46,9 @@ RGEO_BEGIN_C
46
46
 
47
47
  /*
48
48
  Per-interpreter globals.
49
- Most of these are cached references to commonly used classes and modules
50
- so we don't have to do a lot of constant lookups.
49
+ Most of these are cached references to commonly used classes, modules,
50
+ and symbols so we don't have to do a lot of constant lookups and calls
51
+ to rb_intern.
51
52
  */
52
53
  typedef struct {
53
54
  VALUE feature_module;
@@ -73,6 +74,11 @@ typedef struct {
73
74
  VALUE geos_multi_point;
74
75
  VALUE geos_multi_line_string;
75
76
  VALUE geos_multi_polygon;
77
+ ID id_cast;
78
+ ID id_eql;
79
+ ID id_generate;
80
+ VALUE sym_force_new;
81
+ VALUE sym_keep_subtype;
76
82
  } RGeo_Globals;
77
83
 
78
84
 
@@ -109,7 +115,7 @@ typedef struct {
109
115
  Includes a handle to the underlying GEOS geometry itself (which could
110
116
  be null for an uninitialized geometry).
111
117
  It also provides a handle to the factory that created this geometry.
112
-
118
+
113
119
  The klasses object is used by geometry collections. Its value is
114
120
  generally an array of the ruby classes for the colletion's elements,
115
121
  so that we can reproduce the exact class for those elements in cases
@@ -117,7 +123,7 @@ typedef struct {
117
123
  in Line objects, which have no GEOS type). Any array element, or the
118
124
  array itself, could be Qnil, indicating fall back to the default
119
125
  inferred from the GEOS type.
120
-
126
+
121
127
  The GEOS context handle is also included here. Ideally, it would be
122
128
  available by following the factory reference and getting it from the
123
129
  factory data. However, one use case is in the destroy_geometry_func
@@ -185,7 +191,7 @@ const GEOSGeometry* rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALU
185
191
  disables this auto-cast. The returned GEOS geometry is owned by the
186
192
  caller-- that is, if the original ruby object is already of the desired
187
193
  factory, the returned GEOS geometry is a clone of the original.
188
-
194
+
189
195
  If the klasses parameter is not NULL, its referent is set to the
190
196
  klasses saved in the original ruby Geometry object (if any), or else to
191
197
  the class of the converted GEOS object. This is so that you can use the
@@ -1,16 +1,16 @@
1
1
  /*
2
2
  -----------------------------------------------------------------------------
3
-
3
+
4
4
  Geometry base class methods for GEOS wrapper
5
-
5
+
6
6
  -----------------------------------------------------------------------------
7
- Copyright 2010 Daniel Azuma
8
-
7
+ Copyright 2010-2012 Daniel Azuma
8
+
9
9
  All rights reserved.
10
-
10
+
11
11
  Redistribution and use in source and binary forms, with or without
12
12
  modification, are permitted provided that the following conditions are met:
13
-
13
+
14
14
  * Redistributions of source code must retain the above copyright notice,
15
15
  this list of conditions and the following disclaimer.
16
16
  * Redistributions in binary form must reproduce the above copyright notice,
@@ -19,7 +19,7 @@
19
19
  * Neither the name of the copyright holder, nor the names of any other
20
20
  contributors to this software, may be used to endorse or promote products
21
21
  derived from this software without specific prior written permission.
22
-
22
+
23
23
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
24
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
25
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -310,7 +310,7 @@ static VALUE method_geometry_as_text(VALUE self)
310
310
  factory_data = RGEO_FACTORY_DATA_PTR(self_data->factory);
311
311
  wkt_generator = factory_data->wkrep_wkt_generator;
312
312
  if (!NIL_P(wkt_generator)) {
313
- result = rb_funcall(wkt_generator, rb_intern("generate"), 1, self);
313
+ result = rb_funcall(wkt_generator, factory_data->globals->id_generate, 1, self);
314
314
  }
315
315
  else {
316
316
  wkt_writer = factory_data->wkt_writer;
@@ -349,7 +349,7 @@ static VALUE method_geometry_as_binary(VALUE self)
349
349
  factory_data = RGEO_FACTORY_DATA_PTR(self_data->factory);
350
350
  wkb_generator = factory_data->wkrep_wkb_generator;
351
351
  if (!NIL_P(wkb_generator)) {
352
- result = rb_funcall(wkb_generator, rb_intern("generate"), 1, self);
352
+ result = rb_funcall(wkb_generator, factory_data->globals->id_generate, 1, self);
353
353
  }
354
354
  else {
355
355
  wkb_writer = factory_data->wkb_writer;
@@ -915,7 +915,7 @@ static VALUE method_geometry_initialize_copy(VALUE self, VALUE orig)
915
915
  self_data->geos_context = NULL;
916
916
  self_data->factory = Qnil;
917
917
  self_data->klasses = Qnil;
918
-
918
+
919
919
  // Copy value from orig
920
920
  geom = rgeo_get_geos_geometry_safe(orig);
921
921
  if (geom) {
@@ -949,7 +949,7 @@ void rgeo_init_geos_geometry(RGeo_Globals* globals)
949
949
  globals->feature_geometry = rb_const_get_at(globals->feature_module, rb_intern("Geometry"));
950
950
  rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
951
951
  globals->feature_geometry, geos_geometry_class);
952
-
952
+
953
953
  rb_define_alloc_func(geos_geometry_class, alloc_geometry);
954
954
  rb_define_method(geos_geometry_class, "_set_factory", method_geometry_set_factory, 1);
955
955
  rb_define_method(geos_geometry_class, "initialize_copy", method_geometry_initialize_copy, 1);
@@ -1,16 +1,16 @@
1
1
  /*
2
2
  -----------------------------------------------------------------------------
3
-
3
+
4
4
  Geometry base class methods for GEOS wrapper
5
-
5
+
6
6
  -----------------------------------------------------------------------------
7
- Copyright 2010 Daniel Azuma
8
-
7
+ Copyright 2010-2012 Daniel Azuma
8
+
9
9
  All rights reserved.
10
-
10
+
11
11
  Redistribution and use in source and binary forms, with or without
12
12
  modification, are permitted provided that the following conditions are met:
13
-
13
+
14
14
  * Redistributions of source code must retain the above copyright notice,
15
15
  this list of conditions and the following disclaimer.
16
16
  * Redistributions in binary form must reproduce the above copyright notice,
@@ -19,7 +19,7 @@
19
19
  * Neither the name of the copyright holder, nor the names of any other
20
20
  contributors to this software, may be used to endorse or promote products
21
21
  derived from this software without specific prior written permission.
22
-
22
+
23
23
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
24
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
25
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1,16 +1,16 @@
1
1
  /*
2
2
  -----------------------------------------------------------------------------
3
-
3
+
4
4
  Geometry collection methods for GEOS wrapper
5
-
5
+
6
6
  -----------------------------------------------------------------------------
7
- Copyright 2010 Daniel Azuma
8
-
7
+ Copyright 2010-2012 Daniel Azuma
8
+
9
9
  All rights reserved.
10
-
10
+
11
11
  Redistribution and use in source and binary forms, with or without
12
12
  modification, are permitted provided that the following conditions are met:
13
-
13
+
14
14
  * Redistributions of source code must retain the above copyright notice,
15
15
  this list of conditions and the following disclaimer.
16
16
  * Redistributions in binary form must reproduce the above copyright notice,
@@ -19,7 +19,7 @@
19
19
  * Neither the name of the copyright holder, nor the names of any other
20
20
  contributors to this software, may be used to endorse or promote products
21
21
  derived from this software without specific prior written permission.
22
-
22
+
23
23
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
24
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
25
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -155,7 +155,7 @@ static VALUE create_geometry_collection(VALUE module, int type, VALUE factory, V
155
155
  }
156
156
  free(geoms);
157
157
  }
158
-
158
+
159
159
  return result;
160
160
  }
161
161
 
@@ -466,13 +466,13 @@ void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
466
466
  globals->feature_geometry_collection = rb_const_get_at(globals->feature_module, rb_intern("GeometryCollection"));
467
467
  rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
468
468
  globals->feature_geometry_collection, geos_geometry_collection_class);
469
-
469
+
470
470
  geos_multi_point_class = rb_define_class_under(globals->geos_module, "MultiPointImpl", geos_geometry_collection_class);
471
471
  globals->geos_multi_point = geos_multi_point_class;
472
472
  globals->feature_multi_point = rb_const_get_at(globals->feature_module, rb_intern("MultiPoint"));
473
473
  rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
474
474
  globals->feature_multi_point, geos_multi_point_class);
475
-
475
+
476
476
  geos_multi_line_string_class = rb_define_class_under(globals->geos_module, "MultiLineStringImpl", geos_geometry_collection_class);
477
477
  globals->geos_multi_line_string = geos_multi_line_string_class;
478
478
  globals->feature_multi_line_string = rb_const_get_at(globals->feature_module, rb_intern("MultiLineString"));
@@ -480,7 +480,7 @@ void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
480
480
  rb_const_get_at(globals->feature_module, rb_intern("MultiCurve")), geos_multi_line_string_class);
481
481
  rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
482
482
  globals->feature_multi_line_string, geos_multi_line_string_class);
483
-
483
+
484
484
  geos_multi_polygon_class = rb_define_class_under(globals->geos_module, "MultiPolygonImpl", geos_geometry_collection_class);
485
485
  globals->geos_multi_polygon = geos_multi_polygon_class;
486
486
  globals->feature_multi_polygon = rb_const_get_at(globals->feature_module, rb_intern("MultiPolygon"));
@@ -488,7 +488,7 @@ void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
488
488
  rb_const_get_at(globals->feature_module, rb_intern("MultiSurface")), geos_multi_polygon_class);
489
489
  rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
490
490
  globals->feature_multi_polygon, geos_multi_polygon_class);
491
-
491
+
492
492
  // Methods for GeometryCollectionImpl
493
493
  rb_define_module_function(geos_geometry_collection_class, "create", cmethod_geometry_collection_create, 2);
494
494
  rb_include_module(geos_geometry_collection_class, rb_define_module("Enumerable"));
@@ -499,17 +499,17 @@ void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
499
499
  rb_define_method(geos_geometry_collection_class, "geometry_n", method_geometry_collection_geometry_n, 1);
500
500
  rb_define_method(geos_geometry_collection_class, "[]", method_geometry_collection_brackets, 1);
501
501
  rb_define_method(geos_geometry_collection_class, "each", method_geometry_collection_each, 0);
502
-
502
+
503
503
  // Methods for MultiPointImpl
504
504
  rb_define_module_function(geos_multi_point_class, "create", cmethod_multi_point_create, 2);
505
505
  rb_define_method(geos_multi_point_class, "geometry_type", method_multi_point_geometry_type, 0);
506
-
506
+
507
507
  // Methods for MultiLineStringImpl
508
508
  rb_define_module_function(geos_multi_line_string_class, "create", cmethod_multi_line_string_create, 2);
509
509
  rb_define_method(geos_multi_line_string_class, "geometry_type", method_multi_line_string_geometry_type, 0);
510
510
  rb_define_method(geos_multi_line_string_class, "length", method_multi_line_string_length, 0);
511
511
  rb_define_method(geos_multi_line_string_class, "is_closed?", method_multi_line_string_is_closed, 0);
512
-
512
+
513
513
  // Methods for MultiPolygonImpl
514
514
  rb_define_module_function(geos_multi_polygon_class, "create", cmethod_multi_polygon_create, 2);
515
515
  rb_define_method(geos_multi_polygon_class, "geometry_type", method_multi_polygon_geometry_type, 0);