rgeo 2.4.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +21 -11
  4. data/ext/geos_c_impl/analysis.c +29 -26
  5. data/ext/geos_c_impl/analysis.h +8 -5
  6. data/ext/geos_c_impl/coordinates.c +27 -21
  7. data/ext/geos_c_impl/coordinates.h +5 -2
  8. data/ext/geos_c_impl/errors.c +19 -10
  9. data/ext/geos_c_impl/errors.h +11 -4
  10. data/ext/geos_c_impl/extconf.rb +41 -29
  11. data/ext/geos_c_impl/factory.c +441 -351
  12. data/ext/geos_c_impl/factory.h +98 -55
  13. data/ext/geos_c_impl/geometry.c +563 -384
  14. data/ext/geos_c_impl/geometry.h +10 -3
  15. data/ext/geos_c_impl/geometry_collection.c +288 -316
  16. data/ext/geos_c_impl/geometry_collection.h +6 -18
  17. data/ext/geos_c_impl/globals.c +99 -21
  18. data/ext/geos_c_impl/globals.h +3 -2
  19. data/ext/geos_c_impl/line_string.c +263 -222
  20. data/ext/geos_c_impl/line_string.h +5 -6
  21. data/ext/geos_c_impl/main.c +8 -9
  22. data/ext/geos_c_impl/point.c +62 -65
  23. data/ext/geos_c_impl/point.h +4 -5
  24. data/ext/geos_c_impl/polygon.c +134 -132
  25. data/ext/geos_c_impl/polygon.h +11 -9
  26. data/ext/geos_c_impl/preface.h +10 -12
  27. data/ext/geos_c_impl/ruby_more.c +67 -0
  28. data/ext/geos_c_impl/ruby_more.h +25 -0
  29. data/lib/rgeo/cartesian/analysis.rb +5 -3
  30. data/lib/rgeo/cartesian/bounding_box.rb +74 -79
  31. data/lib/rgeo/cartesian/calculations.rb +64 -33
  32. data/lib/rgeo/cartesian/factory.rb +57 -102
  33. data/lib/rgeo/cartesian/feature_classes.rb +68 -46
  34. data/lib/rgeo/cartesian/feature_methods.rb +67 -25
  35. data/lib/rgeo/cartesian/interface.rb +6 -41
  36. data/lib/rgeo/cartesian/planar_graph.rb +373 -0
  37. data/lib/rgeo/cartesian/sweepline_intersector.rb +147 -0
  38. data/lib/rgeo/cartesian/valid_op.rb +69 -0
  39. data/lib/rgeo/cartesian.rb +3 -0
  40. data/lib/rgeo/coord_sys/cs/entities.rb +299 -99
  41. data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
  42. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +90 -42
  43. data/lib/rgeo/coord_sys.rb +1 -20
  44. data/lib/rgeo/error.rb +15 -0
  45. data/lib/rgeo/feature/curve.rb +0 -11
  46. data/lib/rgeo/feature/factory.rb +26 -36
  47. data/lib/rgeo/feature/factory_generator.rb +6 -14
  48. data/lib/rgeo/feature/geometry.rb +146 -66
  49. data/lib/rgeo/feature/geometry_collection.rb +16 -9
  50. data/lib/rgeo/feature/line_string.rb +4 -5
  51. data/lib/rgeo/feature/linear_ring.rb +0 -1
  52. data/lib/rgeo/feature/multi_curve.rb +0 -6
  53. data/lib/rgeo/feature/multi_surface.rb +3 -4
  54. data/lib/rgeo/feature/point.rb +4 -5
  55. data/lib/rgeo/feature/polygon.rb +1 -2
  56. data/lib/rgeo/feature/surface.rb +3 -4
  57. data/lib/rgeo/feature/types.rb +73 -83
  58. data/lib/rgeo/geographic/factory.rb +98 -125
  59. data/lib/rgeo/geographic/interface.rb +66 -163
  60. data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
  61. data/lib/rgeo/geographic/projected_feature_methods.rb +67 -42
  62. data/lib/rgeo/geographic/projected_window.rb +36 -22
  63. data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -5
  64. data/lib/rgeo/geographic/simple_mercator_projector.rb +24 -23
  65. data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
  66. data/lib/rgeo/geographic/spherical_feature_methods.rb +86 -9
  67. data/lib/rgeo/geographic/spherical_math.rb +17 -20
  68. data/lib/rgeo/geographic.rb +1 -1
  69. data/lib/rgeo/geos/capi_factory.rb +87 -158
  70. data/lib/rgeo/geos/capi_feature_classes.rb +50 -36
  71. data/lib/rgeo/geos/ffi_factory.rb +95 -165
  72. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  73. data/lib/rgeo/geos/ffi_feature_methods.rb +105 -126
  74. data/lib/rgeo/geos/interface.rb +20 -59
  75. data/lib/rgeo/geos/utils.rb +3 -3
  76. data/lib/rgeo/geos/zm_factory.rb +53 -95
  77. data/lib/rgeo/geos/zm_feature_methods.rb +30 -32
  78. data/lib/rgeo/geos.rb +8 -8
  79. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +9 -22
  80. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
  81. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +28 -56
  82. data/lib/rgeo/impl_helper/basic_point_methods.rb +2 -14
  83. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +17 -26
  84. data/lib/rgeo/impl_helper/utils.rb +21 -0
  85. data/lib/rgeo/impl_helper/valid_op.rb +350 -0
  86. data/lib/rgeo/impl_helper/validity_check.rb +139 -0
  87. data/lib/rgeo/impl_helper.rb +1 -0
  88. data/lib/rgeo/version.rb +1 -1
  89. data/lib/rgeo/wkrep/wkb_generator.rb +73 -63
  90. data/lib/rgeo/wkrep/wkb_parser.rb +33 -31
  91. data/lib/rgeo/wkrep/wkt_generator.rb +52 -45
  92. data/lib/rgeo/wkrep/wkt_parser.rb +48 -35
  93. data/lib/rgeo.rb +1 -3
  94. metadata +51 -16
  95. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  96. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  97. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -9,7 +9,6 @@
9
9
  module RGeo
10
10
  module Geos
11
11
  # A factory for Geos that handles both Z and M.
12
-
13
12
  class ZMFactory
14
13
  include Feature::Factory::Instance
15
14
  include ImplHelper::Utils
@@ -41,24 +40,14 @@ module RGeo
41
40
  end
42
41
 
43
42
  def initialize(opts = {}) # :nodoc:
44
- proj4 = opts[:proj4]
45
43
  coord_sys = opts[:coord_sys]
46
44
  srid = opts[:srid]
47
- if (!proj4 || !coord_sys) && srid && (db = opts[:srs_database])
48
- entry = db.get(srid.to_i)
49
- if entry
50
- proj4 ||= entry.proj4
51
- coord_sys ||= entry.coord_sys
52
- end
53
- end
54
45
  srid ||= coord_sys.authority_code if coord_sys
55
46
  config = {
56
- uses_lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions] ||
57
- opts[:uses_lenient_multi_polygon_assertions],
58
47
  buffer_resolution: opts[:buffer_resolution], auto_prepare: opts[:auto_prepare],
59
48
  wkt_generator: opts[:wkt_generator], wkt_parser: opts[:wkt_parser],
60
49
  wkb_generator: opts[:wkb_generator], wkb_parser: opts[:wkb_parser],
61
- srid: srid.to_i, proj4: proj4, coord_sys: coord_sys
50
+ srid: srid.to_i, coord_sys: coord_sys
62
51
  }
63
52
  native_interface = opts[:native_interface] || Geos.preferred_native_interface
64
53
  if native_interface == :ffi
@@ -70,33 +59,37 @@ module RGeo
70
59
  end
71
60
 
72
61
  wkt_generator = opts[:wkt_generator]
73
- case wkt_generator
74
- when Hash
75
- @wkt_generator = WKRep::WKTGenerator.new(wkt_generator)
76
- else
77
- @wkt_generator = WKRep::WKTGenerator.new(convert_case: :upper)
78
- end
62
+ @wkt_generator =
63
+ case wkt_generator
64
+ when Hash
65
+ WKRep::WKTGenerator.new(wkt_generator)
66
+ else
67
+ WKRep::WKTGenerator.new(convert_case: :upper)
68
+ end
79
69
  wkb_generator = opts[:wkb_generator]
80
- case wkb_generator
81
- when Hash
82
- @wkb_generator = WKRep::WKBGenerator.new(wkb_generator)
83
- else
84
- @wkb_generator = WKRep::WKBGenerator.new
85
- end
70
+ @wkb_generator =
71
+ case wkb_generator
72
+ when Hash
73
+ WKRep::WKBGenerator.new(wkb_generator)
74
+ else
75
+ WKRep::WKBGenerator.new
76
+ end
86
77
  wkt_parser = opts[:wkt_parser]
87
- case wkt_parser
88
- when Hash
89
- @wkt_parser = WKRep::WKTParser.new(self, wkt_parser)
90
- else
91
- @wkt_parser = WKRep::WKTParser.new(self)
92
- end
78
+ @wkt_parser =
79
+ case wkt_parser
80
+ when Hash
81
+ WKRep::WKTParser.new(self, wkt_parser)
82
+ else
83
+ WKRep::WKTParser.new(self)
84
+ end
93
85
  wkb_parser = opts[:wkb_parser]
94
- case wkb_parser
95
- when Hash
96
- @wkb_parser = WKRep::WKBParser.new(self, wkb_parser)
97
- else
98
- @wkb_parser = WKRep::WKBParser.new(self)
99
- end
86
+ @wkb_parser =
87
+ case wkb_parser
88
+ when Hash
89
+ WKRep::WKBParser.new(self, wkb_parser)
90
+ else
91
+ WKRep::WKBParser.new(self)
92
+ end
100
93
  end
101
94
 
102
95
  # Marshal support
@@ -109,29 +102,18 @@ module RGeo
109
102
  "wkbg" => @wkb_generator.properties,
110
103
  "wktp" => @wkt_parser.properties,
111
104
  "wkbp" => @wkb_parser.properties,
112
- "lmpa" => @zfactory.lenient_multi_polygon_assertions?,
113
105
  "apre" => @zfactory.property(:auto_prepare) == :simple,
114
106
  "nffi" => @zfactory.is_a?(FFIFactory)
115
107
  }
116
- proj4 = @zfactory.proj4
117
108
  coord_sys = @zfactory.coord_sys
118
- hash["proj4"] = proj4.marshal_dump if proj4
119
109
  hash["cs"] = coord_sys.to_wkt if coord_sys
120
110
  hash
121
111
  end
122
112
 
123
113
  def marshal_load(data) # :nodoc:
124
- if (proj4_data = data["proj4"]) && CoordSys.check!(:proj4)
125
- proj4 = CoordSys::Proj4.allocate
126
- proj4.marshal_load(proj4_data)
127
- else
128
- proj4 = nil
129
- end
130
- if (coord_sys_data = data["cs"])
131
- coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data)
132
- else
133
- coord_sys = nil
134
- end
114
+ cs_class = CoordSys::CONFIG.default_coord_sys_class
115
+ coord_sys = data["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
116
+
135
117
  initialize(
136
118
  native_interface: (data["nffi"] ? :ffi : :capi),
137
119
  has_z_coordinate: data["hasz"],
@@ -142,9 +124,7 @@ module RGeo
142
124
  wkb_generator: symbolize_hash(data["wkbg"]),
143
125
  wkt_parser: symbolize_hash(data["wktp"]),
144
126
  wkb_parser: symbolize_hash(data["wkbp"]),
145
- uses_lenient_multi_polygon_assertions: data["lmpa"],
146
127
  auto_prepare: (data["apre"] ? :simple : :disabled),
147
- proj4: proj4,
148
128
  coord_sys: coord_sys
149
129
  )
150
130
  end
@@ -154,38 +134,22 @@ module RGeo
154
134
  def encode_with(coder) # :nodoc:
155
135
  coder["srid"] = @zfactory.srid
156
136
  coder["buffer_resolution"] = @zfactory.buffer_resolution
157
- coder["lenient_multi_polygon_assertions"] = @zfactory.lenient_multi_polygon_assertions?
158
137
  coder["wkt_generator"] = @wkt_generator.properties
159
138
  coder["wkb_generator"] = @wkb_generator.properties
160
139
  coder["wkt_parser"] = @wkt_parser.properties
161
140
  coder["wkb_parser"] = @wkb_parser.properties
162
141
  coder["auto_prepare"] = @zfactory.property(:auto_prepare).to_s
163
142
  coder["native_interface"] = @zfactory.is_a?(FFIFactory) ? "ffi" : "capi"
164
- if (proj4 = @zfactory.proj4)
165
- str = proj4.original_str || proj4.canonical_str
166
- coder["proj4"] = proj4.radians? ? { "proj4" => str, "radians" => true } : str
167
- end
168
- if (coord_sys = @zfactory.coord_sys)
169
- coder["coord_sys"] = coord_sys.to_wkt
170
- end
143
+
144
+ return unless (coord_sys = @zfactory.coord_sys)
145
+
146
+ coder["coord_sys"] = coord_sys.to_wkt
171
147
  end
172
148
 
173
149
  def init_with(coder) # :nodoc:
174
- if (proj4_data = coder["proj4"])
175
- CoordSys.check!(:proj4)
176
- if proj4_data.is_a?(Hash)
177
- proj4 = CoordSys::Proj4.create(proj4_data["proj4"], radians: proj4_data["radians"])
178
- else
179
- proj4 = CoordSys::Proj4.create(proj4_data.to_s)
180
- end
181
- else
182
- proj4 = nil
183
- end
184
- if (coord_sys_data = coder["cs"])
185
- coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data.to_s)
186
- else
187
- coord_sys = nil
188
- end
150
+ cs_class = CoordSys::CONFIG.default_coord_sys_class
151
+ coord_sys = coder["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
152
+
189
153
  initialize(
190
154
  native_interface: coder["native_interface"] == "ffi" ? :ffi : :capi,
191
155
  has_z_coordinate: coder["has_z_coordinate"],
@@ -197,8 +161,6 @@ module RGeo
197
161
  wkt_parser: symbolize_hash(coder["wkt_parser"]),
198
162
  wkb_parser: symbolize_hash(coder["wkb_parser"]),
199
163
  auto_prepare: coder["auto_prepare"] == "disabled" ? :disabled : :simple,
200
- uses_lenient_multi_polygon_assertions: coder["lenient_multi_polygon_assertions"],
201
- proj4: proj4,
202
164
  coord_sys: coord_sys
203
165
  )
204
166
  end
@@ -216,12 +178,6 @@ module RGeo
216
178
  @zfactory.buffer_resolution
217
179
  end
218
180
 
219
- # Returns true if this factory is lenient with MultiPolygon assertions
220
-
221
- def lenient_multi_polygon_assertions?
222
- @zfactory.lenient_multi_polygon_assertions?
223
- end
224
-
225
181
  # Returns the z-only factory corresponding to this factory.
226
182
 
227
183
  def z_factory
@@ -236,8 +192,8 @@ module RGeo
236
192
 
237
193
  # Factory equivalence test.
238
194
 
239
- def eql?(rhs)
240
- rhs.is_a?(ZMFactory) && rhs.z_factory == @zfactory
195
+ def eql?(other)
196
+ other.is_a?(ZMFactory) && other.z_factory == @zfactory
241
197
  end
242
198
  alias == eql?
243
199
 
@@ -271,7 +227,11 @@ module RGeo
271
227
  # See RGeo::Feature::Factory#point
272
228
 
273
229
  def point(x, y, z = 0, m = 0)
274
- create_feature(ZMPointImpl, @zfactory.point(x, y, z), @mfactory.point(x, y, m))
230
+ create_feature(
231
+ ZMPointImpl,
232
+ @zfactory.point(x, y, z),
233
+ @mfactory.point(x, y, m)
234
+ )
275
235
  end
276
236
 
277
237
  # See RGeo::Feature::Factory#line_string
@@ -295,7 +255,11 @@ module RGeo
295
255
  # See RGeo::Feature::Factory#polygon
296
256
 
297
257
  def polygon(outer_ring, inner_rings = nil)
298
- create_feature(ZMPolygonImpl, @zfactory.polygon(outer_ring, inner_rings), @mfactory.polygon(outer_ring, inner_rings))
258
+ create_feature(
259
+ ZMPolygonImpl,
260
+ @zfactory.polygon(outer_ring, inner_rings),
261
+ @mfactory.polygon(outer_ring, inner_rings)
262
+ )
299
263
  end
300
264
 
301
265
  # See RGeo::Feature::Factory#collection
@@ -322,12 +286,6 @@ module RGeo
322
286
  create_feature(ZMMultiPolygonImpl, @zfactory.multi_polygon(elems), @mfactory.multi_polygon(elems))
323
287
  end
324
288
 
325
- # See RGeo::Feature::Factory#proj4
326
-
327
- def proj4
328
- @zfactory.proj4
329
- end
330
-
331
289
  # See RGeo::Feature::Factory#coord_sys
332
290
 
333
291
  def coord_sys
@@ -347,7 +305,7 @@ module RGeo
347
305
  # Optimization if we're just changing factories, but to
348
306
  # another ZM factory.
349
307
  if original.factory != self && ntype == type &&
350
- (!project || original.factory.proj4 == @proj4)
308
+ (!project || original.factory.coord_sys == @coord_sys)
351
309
  zresult = original.z_geometry.dup
352
310
  zresult.factory = @zfactory
353
311
  mresult = original.m_geometry.dup
@@ -356,7 +314,7 @@ module RGeo
356
314
  end
357
315
  # LineString conversion optimization.
358
316
  if (original.factory != self || ntype != type) &&
359
- (!project || original.factory.proj4 == @proj4) &&
317
+ (!project || original.factory.coord_sys == @coord_sys) &&
360
318
  type.subtypeof?(Feature::LineString) && ntype.subtypeof?(Feature::LineString)
361
319
  klass = Factory::IMPL_CLASSES[ntype]
362
320
  zresult = klass._copy_from(@zfactory, original.z_geometry)
@@ -26,7 +26,7 @@ module RGeo
26
26
  end
27
27
 
28
28
  def hash
29
- @factory.hash ^ @zgeometry.hash ^ @mgeometry.hash
29
+ [@factory, @zgeometry, @mgeometry].hash
30
30
  end
31
31
 
32
32
  def factory
@@ -45,6 +45,14 @@ module RGeo
45
45
  @zgeometry.dimension
46
46
  end
47
47
 
48
+ def coordinate_dimension
49
+ 4
50
+ end
51
+
52
+ def spatial_dimension
53
+ 3
54
+ end
55
+
48
56
  def geometry_type
49
57
  @zgeometry.geometry_type
50
58
  end
@@ -69,18 +77,16 @@ module RGeo
69
77
  @zgeometry.empty?
70
78
  end
71
79
 
72
- def is_empty?
73
- warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
74
- empty?
75
- end
76
-
77
80
  def simple?
78
81
  @zgeometry.simple?
79
82
  end
80
83
 
81
- def is_simple?
82
- warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
83
- simple?
84
+ def is_3d?
85
+ true
86
+ end
87
+
88
+ def measured?
89
+ true
84
90
  end
85
91
 
86
92
  def boundary
@@ -153,12 +159,19 @@ module RGeo
153
159
 
154
160
  def sym_difference(rhs)
155
161
  rhs = RGeo::Feature.cast(rhs, self)
156
- @factory.create_feature(nil, @zgeometry.sym_difference(rhs.z_geometry), @mgeometry.sym_difference(rhs.m_geometry))
162
+ @factory.create_feature(
163
+ nil,
164
+ @zgeometry.sym_difference(rhs.z_geometry),
165
+ @mgeometry.sym_difference(rhs.m_geometry)
166
+ )
157
167
  end
158
168
 
159
169
  def rep_equals?(rhs)
160
170
  rhs = RGeo::Feature.cast(rhs, self)
161
- rhs.is_a?(self.class) && @factory.eql?(rhs.factory) && @zgeometry.rep_equals?(rhs.z_geometry) && @mgeometry.rep_equals?(rhs.m_geometry)
171
+ rhs.is_a?(self.class) &&
172
+ @factory.eql?(rhs.factory) &&
173
+ @zgeometry.rep_equals?(rhs.z_geometry) &&
174
+ @mgeometry.rep_equals?(rhs.m_geometry)
162
175
  end
163
176
 
164
177
  alias eql? rep_equals?
@@ -236,26 +249,16 @@ module RGeo
236
249
  @zgeometry.closed?
237
250
  end
238
251
 
239
- def is_closed?
240
- warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
241
- closed?
242
- end
243
-
244
252
  def ring?
245
253
  @zgeometry.ring?
246
254
  end
247
255
 
248
- def is_ring?
249
- warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
250
- ring?
251
- end
252
-
253
256
  def num_points
254
257
  @zgeometry.num_points
255
258
  end
256
259
 
257
- def point_n(n)
258
- @factory.create_feature(ZMPointImpl, @zgeometry.point_n(n), @mgeometry.point_n(n))
260
+ def point_n(idx)
261
+ @factory.create_feature(ZMPointImpl, @zgeometry.point_n(idx), @mgeometry.point_n(idx))
259
262
  end
260
263
 
261
264
  def points
@@ -294,8 +297,8 @@ module RGeo
294
297
  @zgeometry.num_interior_rings
295
298
  end
296
299
 
297
- def interior_ring_n(n)
298
- @factory.create_feature(ZMLineStringImpl, @zgeometry.interior_ring_n(n), @mgeometry.interior_ring_n(n))
300
+ def interior_ring_n(idx)
301
+ @factory.create_feature(ZMLineStringImpl, @zgeometry.interior_ring_n(idx), @mgeometry.interior_ring_n(idx))
299
302
  end
300
303
 
301
304
  def interior_rings
@@ -319,8 +322,8 @@ module RGeo
319
322
  end
320
323
  alias size num_geometries
321
324
 
322
- def geometry_n(n)
323
- @factory.create_feature(nil, @zgeometry.geometry_n(n), @mgeometry.geometry_n(n))
325
+ def geometry_n(idx)
326
+ @factory.create_feature(nil, @zgeometry.geometry_n(idx), @mgeometry.geometry_n(idx))
324
327
  end
325
328
  alias [] geometry_n
326
329
 
@@ -347,11 +350,6 @@ module RGeo
347
350
  @zgeometry.closed?
348
351
  end
349
352
 
350
- def is_closed?
351
- warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
352
- closed?
353
- end
354
-
355
353
  def coordinates
356
354
  each.map(&:coordinates)
357
355
  end
data/lib/rgeo/geos.rb CHANGED
@@ -33,9 +33,6 @@ module RGeo
33
33
  require_relative "geos/capi_feature_classes"
34
34
  require_relative "geos/capi_factory"
35
35
  end
36
- require_relative "geos/ffi_feature_methods"
37
- require_relative "geos/ffi_feature_classes"
38
- require_relative "geos/ffi_factory"
39
36
  require_relative "geos/zm_feature_methods"
40
37
  require_relative "geos/zm_feature_classes"
41
38
  require_relative "geos/zm_factory"
@@ -48,12 +45,15 @@ module RGeo
48
45
  raise "Problem loading FFI" unless ::FFI::AutoPointer
49
46
  FFI_SUPPORTED = true
50
47
  FFI_SUPPORT_EXCEPTION = nil
51
- rescue LoadError => ex
48
+ rescue LoadError, StandardError => e
52
49
  FFI_SUPPORTED = false
53
- FFI_SUPPORT_EXCEPTION = ex
54
- rescue StandardError => ex
55
- FFI_SUPPORTED = false
56
- FFI_SUPPORT_EXCEPTION = ex
50
+ FFI_SUPPORT_EXCEPTION = e
51
+ end
52
+
53
+ if FFI_SUPPORTED
54
+ require_relative "geos/ffi_feature_methods"
55
+ require_relative "geos/ffi_feature_classes"
56
+ require_relative "geos/ffi_factory"
57
57
  end
58
58
 
59
59
  # Default preferred native interface
@@ -20,19 +20,19 @@ module RGeo
20
20
  raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
21
21
  elem
22
22
  end
23
- validate_geometry
23
+ init_geometry
24
24
  end
25
25
 
26
26
  def num_geometries
27
27
  @elements.size
28
28
  end
29
29
 
30
- def geometry_n(n)
31
- n < 0 ? nil : @elements[n]
30
+ def geometry_n(idx)
31
+ idx < 0 ? nil : @elements[idx]
32
32
  end
33
33
 
34
- def [](n)
35
- @elements[n]
34
+ def [](idx)
35
+ @elements[idx]
36
36
  end
37
37
 
38
38
  def each(&block)
@@ -55,11 +55,6 @@ module RGeo
55
55
  @elements.size == 0
56
56
  end
57
57
 
58
- def is_empty?
59
- warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
60
- empty?
61
- end
62
-
63
58
  def rep_equals?(rhs)
64
59
  if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @elements.size == rhs.num_geometries
65
60
  rhs.each_with_index { |p, i| return false unless @elements[i].rep_equals?(p) }
@@ -69,10 +64,7 @@ module RGeo
69
64
  end
70
65
 
71
66
  def hash
72
- @hash ||= begin
73
- hash = [factory, geometry_type].hash
74
- @elements.inject(hash) { |h, g| (1_664_525 * h + g.hash).hash }
75
- end
67
+ @hash ||= [factory, geometry_type, *@elements].hash
76
68
  end
77
69
 
78
70
  private
@@ -91,7 +83,7 @@ module RGeo
91
83
  raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
92
84
  elem
93
85
  end
94
- validate_geometry
86
+ init_geometry
95
87
  end
96
88
 
97
89
  def geometry_type
@@ -102,11 +94,6 @@ module RGeo
102
94
  all?(&:closed?)
103
95
  end
104
96
 
105
- def is_closed?
106
- warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
107
- closed?
108
- end
109
-
110
97
  def length
111
98
  @elements.inject(0.0) { |sum, obj| sum + obj.length }
112
99
  end
@@ -152,7 +139,7 @@ module RGeo
152
139
  raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
153
140
  elem
154
141
  end
155
- validate_geometry
142
+ init_geometry
156
143
  end
157
144
 
158
145
  def geometry_type
@@ -176,7 +163,7 @@ module RGeo
176
163
  raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
177
164
  elem
178
165
  end
179
- validate_geometry
166
+ init_geometry
180
167
  end
181
168
 
182
169
  def geometry_type
@@ -52,8 +52,7 @@ module RGeo
52
52
  @factory = obj.factory
53
53
  end
54
54
 
55
- def validate_geometry
56
- end
55
+ def init_geometry; end
57
56
  end
58
57
  end
59
58
  end