ffi-geos 1.2.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +4851 -0
  3. data/.travis.yml +24 -9
  4. data/FUNDING.yml +2 -0
  5. data/Gemfile +12 -16
  6. data/Guardfile +6 -8
  7. data/MIT-LICENSE +1 -1
  8. data/README.rdoc +2 -20
  9. data/Rakefile +4 -2
  10. data/ffi-geos.gemspec +13 -14
  11. data/lib/ffi-geos.rb +342 -244
  12. data/lib/ffi-geos/buffer_params.rb +9 -20
  13. data/lib/ffi-geos/coordinate_sequence.rb +351 -65
  14. data/lib/ffi-geos/geometry.rb +267 -191
  15. data/lib/ffi-geos/geometry_collection.rb +74 -12
  16. data/lib/ffi-geos/interrupt.rb +11 -16
  17. data/lib/ffi-geos/line_string.rb +157 -33
  18. data/lib/ffi-geos/linear_ring.rb +2 -3
  19. data/lib/ffi-geos/multi_line_string.rb +1 -2
  20. data/lib/ffi-geos/multi_point.rb +0 -1
  21. data/lib/ffi-geos/multi_polygon.rb +0 -1
  22. data/lib/ffi-geos/point.rb +70 -15
  23. data/lib/ffi-geos/polygon.rb +124 -21
  24. data/lib/ffi-geos/prepared_geometry.rb +11 -12
  25. data/lib/ffi-geos/strtree.rb +64 -77
  26. data/lib/ffi-geos/tools.rb +16 -19
  27. data/lib/ffi-geos/utils.rb +36 -60
  28. data/lib/ffi-geos/version.rb +1 -3
  29. data/lib/ffi-geos/wkb_reader.rb +4 -9
  30. data/lib/ffi-geos/wkb_writer.rb +15 -20
  31. data/lib/ffi-geos/wkt_reader.rb +2 -5
  32. data/lib/ffi-geos/wkt_writer.rb +20 -31
  33. data/sonar-project.properties +16 -0
  34. data/test/.rubocop.yml +36 -0
  35. data/test/coordinate_sequence_tests.rb +322 -52
  36. data/test/geometry_collection_tests.rb +388 -4
  37. data/test/geometry_tests.rb +466 -121
  38. data/test/interrupt_tests.rb +9 -12
  39. data/test/line_string_tests.rb +213 -25
  40. data/test/linear_ring_tests.rb +1 -3
  41. data/test/misc_tests.rb +28 -30
  42. data/test/multi_line_string_tests.rb +0 -2
  43. data/test/point_tests.rb +158 -2
  44. data/test/polygon_tests.rb +283 -2
  45. data/test/prepared_geometry_tests.rb +8 -11
  46. data/test/strtree_tests.rb +14 -15
  47. data/test/test_helper.rb +75 -51
  48. data/test/tools_tests.rb +1 -4
  49. data/test/utils_tests.rb +85 -76
  50. data/test/wkb_reader_tests.rb +18 -18
  51. data/test/wkb_writer_tests.rb +15 -22
  52. data/test/wkt_reader_tests.rb +1 -4
  53. data/test/wkt_writer_tests.rb +8 -17
  54. metadata +11 -7
@@ -1,7 +1,5 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
- $: << File.dirname(__FILE__)
5
3
  require 'test_helper'
6
4
 
7
5
  class InterruptTests < Minitest::Test
@@ -37,11 +35,11 @@ class InterruptTests < Minitest::Test
37
35
  interrupt_tester do
38
36
  geom = read('LINESTRING(0 0, 1 0)')
39
37
 
40
- Geos::Interrupt.register(self.method(:interrupt_method))
38
+ Geos::Interrupt.register(method(:interrupt_method))
41
39
 
42
40
  begin
43
41
  buffer = geom.buffer(1, 8)
44
- rescue => e
42
+ rescue StandardError => e
45
43
  # no-op
46
44
  ensure
47
45
  assert_match(/^InterruptedException/, e.message)
@@ -64,7 +62,7 @@ class InterruptTests < Minitest::Test
64
62
 
65
63
  begin
66
64
  buffer = geom.buffer(1, 8)
67
- rescue => e
65
+ rescue StandardError => e
68
66
  # no-op
69
67
  ensure
70
68
  assert_match(/^InterruptedException/, e.message)
@@ -89,7 +87,7 @@ class InterruptTests < Minitest::Test
89
87
 
90
88
  begin
91
89
  buffer = geom.buffer(1, 8)
92
- rescue => e
90
+ rescue StandardError => e
93
91
  # no-op
94
92
  ensure
95
93
  assert_match(/^InterruptedException/, e.message)
@@ -116,7 +114,7 @@ class InterruptTests < Minitest::Test
116
114
  prc_1 = proc {
117
115
  interrupt_called
118
116
  called << :prc_1
119
- prev.call if prev
117
+ prev&.call
120
118
  }
121
119
 
122
120
  Geos::Interrupt.register(prc_0)
@@ -124,13 +122,13 @@ class InterruptTests < Minitest::Test
124
122
 
125
123
  begin
126
124
  buffer = geom.buffer(1, 8)
127
- rescue => e
125
+ rescue StandardError => e
128
126
  # no-op
129
127
  ensure
130
128
  assert_match(/^InterruptedException/, e.message)
131
129
  assert_nil(buffer)
132
130
  assert_interrupt_called(1)
133
- assert_equal([ :prc_1, :prc_0 ], called)
131
+ assert_equal([:prc_1, :prc_0], called)
134
132
  end
135
133
  end
136
134
  end
@@ -162,7 +160,7 @@ class InterruptTests < Minitest::Test
162
160
 
163
161
  begin
164
162
  buffer = geom.buffer(1, 8)
165
- rescue => e
163
+ rescue StandardError => e
166
164
  assert_match(/^InterruptedException/, e.message)
167
165
  assert_nil(buffer)
168
166
  end
@@ -184,7 +182,7 @@ class InterruptTests < Minitest::Test
184
182
  skip unless ENV['FORCE_TESTS'] || Geos::Interrupt.available?
185
183
 
186
184
  assert_raises(ArgumentError) do
187
- Geos::Interrupt.register(self.method(:interrupt_method)) do
185
+ Geos::Interrupt.register(method(:interrupt_method)) do
188
186
  # no-op
189
187
  end
190
188
  end
@@ -198,4 +196,3 @@ class InterruptTests < Minitest::Test
198
196
  end
199
197
  end
200
198
  end
201
-
@@ -1,7 +1,5 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
- $: << File.dirname(__FILE__)
5
3
  require 'test_helper'
6
4
 
7
5
  class LineStringTests < Minitest::Test
@@ -49,7 +47,7 @@ class LineStringTests < Minitest::Test
49
47
  'POINT (1 1)'
50
48
  ], geom[0, 2].collect { |g| write(g) })
51
49
 
52
- assert_equal(nil, geom[0, -1])
50
+ assert_nil(geom[0, -1])
53
51
  assert_equal([], geom[-1, 0])
54
52
  assert_equal([
55
53
  'POINT (1 1)',
@@ -73,11 +71,10 @@ class LineStringTests < Minitest::Test
73
71
  :offset_curve,
74
72
  'LINESTRING (0 2, 10 2)',
75
73
  'LINESTRING (0 0, 10 0)',
76
- 2, {
77
- :quad_segs => 0,
78
- :join => :round,
79
- :mitre_limit => 2
80
- }
74
+ 2,
75
+ quad_segs: 0,
76
+ join: :round,
77
+ mitre_limit: 2
81
78
  )
82
79
 
83
80
  # straight right
@@ -85,11 +82,10 @@ class LineStringTests < Minitest::Test
85
82
  :offset_curve,
86
83
  'LINESTRING (10 -2, 0 -2)',
87
84
  'LINESTRING (0 0, 10 0)',
88
- -2, {
89
- :quad_segs => 0,
90
- :join => :round,
91
- :mitre_limit => 2
92
- }
85
+ -2,
86
+ quad_segs: 0,
87
+ join: :round,
88
+ mitre_limit: 2
93
89
  )
94
90
 
95
91
  # outside curve
@@ -97,11 +93,10 @@ class LineStringTests < Minitest::Test
97
93
  :offset_curve,
98
94
  'LINESTRING (12 10, 12 0, 10 -2, 0 -2)',
99
95
  'LINESTRING (0 0, 10 0, 10 10)',
100
- -2, {
101
- :quad_segs => 1,
102
- :join => :round,
103
- :mitre_limit => 2
104
- }
96
+ -2,
97
+ quad_segs: 1,
98
+ join: :round,
99
+ mitre_limit: 2
105
100
  )
106
101
 
107
102
  # inside curve
@@ -109,11 +104,10 @@ class LineStringTests < Minitest::Test
109
104
  :offset_curve,
110
105
  'LINESTRING (0 2, 8 2, 8 10)',
111
106
  'LINESTRING (0 0, 10 0, 10 10)',
112
- 2, {
113
- :quad_segs => 1,
114
- :join => :round,
115
- :mitre_limit => 2
116
- }
107
+ 2,
108
+ quad_segs: 1,
109
+ join: :round,
110
+ mitre_limit: 2
117
111
  )
118
112
  end
119
113
 
@@ -174,7 +168,7 @@ class LineStringTests < Minitest::Test
174
168
 
175
169
  srid_copy_tester(:to_linear_ring, expected, 0, :zero, wkt)
176
170
  srid_copy_tester(:to_linear_ring, expected, 4326, :lenient, wkt)
177
- srid_copy_tester(:to_linear_ring, expected, 4326, :strict, wkt)
171
+ srid_copy_tester(:to_linear_ring, expected, 4326, :strict, wkt)
178
172
  end
179
173
 
180
174
  def test_to_polygon
@@ -192,6 +186,200 @@ class LineStringTests < Minitest::Test
192
186
 
193
187
  srid_copy_tester(:to_polygon, expected, 0, :zero, wkt)
194
188
  srid_copy_tester(:to_polygon, expected, 4326, :lenient, wkt)
195
- srid_copy_tester(:to_polygon, expected, 4326, :strict, wkt)
189
+ srid_copy_tester(:to_polygon, expected, 4326, :strict, wkt)
190
+ end
191
+
192
+ def test_x_max
193
+ geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
194
+ assert_equal(8, geom.x_max)
195
+ end
196
+
197
+ def test_x_min
198
+ geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
199
+ assert_equal(-10, geom.x_min)
200
+ end
201
+
202
+ def test_y_max
203
+ geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
204
+ assert_equal(9, geom.y_max)
205
+ end
206
+
207
+ def test_y_min
208
+ geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
209
+ assert_equal(0, geom.y_min)
210
+ end
211
+
212
+ def test_z_max
213
+ geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
214
+ assert_equal(0, geom.z_max)
215
+
216
+ geom = read('LINESTRING Z (0 0 0, 5 0 3, 8 9 4, -10 5 3, 0 0 0)')
217
+ assert_equal(4, geom.z_max)
218
+ end
219
+
220
+ def test_z_min
221
+ geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
222
+ assert_equal(0, geom.z_min)
223
+
224
+ geom = read('LINESTRING Z (0 0 0, 5 0 3, 8 9 4, -10 5 3, 0 0 0)')
225
+ assert_equal(0, geom.z_min)
226
+ end
227
+
228
+ def test_snap_to_grid
229
+ wkt = 'LINESTRING (-10.12 0, -10.12 5, -10.12 5, -10.12 6, -10.12 6, -10.12 6, -10.12 7, -10.12 7, -10.12 7, -10.12 8, -10.12 8, -9 8, -9 9, -10.12 0)'
230
+ expected = 'LINESTRING (-10 0, -10 5, -10 6, -10 7, -10 8, -9 8, -9 9, -10 0)'
231
+
232
+ simple_bang_tester(:snap_to_grid, expected, wkt, 1)
233
+ end
234
+
235
+ def test_snap_to_grid_empty
236
+ assert(read('LINESTRING EMPTY').snap_to_grid!.empty?, 'Expected an empty LineString')
237
+ end
238
+
239
+ def test_snap_to_grid_with_srid
240
+ wkt = 'LINESTRING (0.1 0.1, 0.1 5.1, 5.1 5.1, 5.1 0.1, 0.1 0.1)'
241
+ expected = 'LINESTRING (0 0, 0 5, 5 5, 5 0, 0 0)'
242
+
243
+ srid_copy_tester(:snap_to_grid, expected, 0, :zero, wkt, 1)
244
+ srid_copy_tester(:snap_to_grid, expected, 4326, :lenient, wkt, 1)
245
+ srid_copy_tester(:snap_to_grid, expected, 4326, :strict, wkt, 1)
246
+ end
247
+
248
+ def test_rotate
249
+ writer.rounding_precision = 2
250
+
251
+ wkt = 'LINESTRING (0 0, 10 10)'
252
+
253
+ affine_tester(:rotate, 'LINESTRING (30 10, 20 20)', wkt, Math::PI / 2, [10.0, 20.0])
254
+ affine_tester(:rotate, 'LINESTRING (-3 1, 7 -9)', wkt, -Math::PI / 2, [-1.0, 2.0])
255
+ affine_tester(:rotate, 'LINESTRING (2 2, -8 -8)', wkt, Math::PI, read('POINT(1 1)'))
256
+ affine_tester(:rotate, 'LINESTRING (0.5 -0.5, -9.5 9.5)', wkt, Math::PI / 2, read('LINESTRING(0 0, 1 0)'))
257
+ end
258
+
259
+ def test_rotate_x
260
+ writer.output_dimensions = 3
261
+ writer.rounding_precision = 2
262
+
263
+ wkt = 'LINESTRING Z (1 1 1, 10 10 10)'
264
+
265
+ affine_tester(:rotate_x, 'LINESTRING Z (1 -1 -1, 10 -10 -10)', wkt, Math::PI)
266
+ affine_tester(:rotate_x, 'LINESTRING Z (1 -1 1, 10 -10 10)', wkt, Math::PI / 2)
267
+ affine_tester(:rotate_x, 'LINESTRING Z (1 1 -1, 10 10 -10)', wkt, Math::PI + Math::PI / 2)
268
+ affine_tester(:rotate_x, wkt, wkt, Math::PI * 2)
269
+ end
270
+
271
+ def test_rotate_y
272
+ writer.output_dimensions = 3
273
+ writer.rounding_precision = 2
274
+
275
+ wkt = 'LINESTRING Z (1 1 1, 10 10 10)'
276
+
277
+ affine_tester(:rotate_y, 'LINESTRING Z (-1 1 -1, -10 10 -10)', wkt, Math::PI)
278
+ affine_tester(:rotate_y, 'LINESTRING Z (1 1 -1, 10 10 -10)', wkt, Math::PI / 2)
279
+ affine_tester(:rotate_y, 'LINESTRING Z (-1 1 1, -10 10 10)', wkt, Math::PI + Math::PI / 2)
280
+ affine_tester(:rotate_y, wkt, wkt, Math::PI * 2)
281
+ end
282
+
283
+ def test_rotate_z
284
+ writer.rounding_precision = 2
285
+
286
+ wkt = 'LINESTRING (1 1, 10 10)'
287
+
288
+ affine_tester(:rotate_z, 'LINESTRING (-1 -1, -10 -10)', wkt, Math::PI)
289
+ affine_tester(:rotate_z, 'LINESTRING (-1 1, -10 10)', wkt, Math::PI / 2)
290
+ affine_tester(:rotate_z, 'LINESTRING (1 -1, 10 -10)', wkt, Math::PI + Math::PI / 2)
291
+ affine_tester(:rotate_z, wkt, wkt, Math::PI * 2)
292
+ end
293
+
294
+ def test_scale
295
+ affine_tester(:scale, 'LINESTRING (5 5, 50 50)', 'LINESTRING (1 1, 10 10)', 5, 5)
296
+ affine_tester(:scale, 'LINESTRING (3 2, 30 20)', 'LINESTRING (1 1, 10 10)', 3, 2)
297
+
298
+ writer.output_dimensions = 3
299
+ affine_tester(:scale, 'LINESTRING Z (40 40 40, 80 80 80)', 'LINESTRING Z (10 20 -5, 20 40 -10)', 4, 2, -8)
300
+ end
301
+
302
+ def test_scale_hash
303
+ affine_tester(:scale, 'LINESTRING (5 5, 50 50)', 'LINESTRING (1 1, 10 10)', x: 5, y: 5)
304
+ affine_tester(:scale, 'LINESTRING (3 2, 30 20)', 'LINESTRING (1 1, 10 10)', x: 3, y: 2)
305
+
306
+ writer.output_dimensions = 3
307
+ affine_tester(:scale, 'LINESTRING Z (40 40 40, 80 80 80)', 'LINESTRING Z (10 20 -5, 20 40 -10)', x: 4, y: 2, z: -8)
308
+ end
309
+
310
+ def test_trans_scale
311
+ affine_tester(:trans_scale, 'LINESTRING (2 2, 11 11)', 'LINESTRING (1 1, 10 10)', 1, 1, 1, 1)
312
+ affine_tester(:trans_scale, 'LINESTRING (3 3, 12 12)', 'LINESTRING (2 2, 11 11)', 1, 1, 1, 1)
313
+ affine_tester(:trans_scale, 'LINESTRING (0 0, -9 -9)', 'LINESTRING (1 1, 10 10)', -1, -1, -1, -1)
314
+ affine_tester(:trans_scale, 'LINESTRING (1 2, 10 11)', 'LINESTRING (1 1, 10 10)', 0, 1, 1, 1)
315
+ affine_tester(:trans_scale, 'LINESTRING (2 1, 11 10)', 'LINESTRING (1 1, 10 10)', 1, 0, 1, 1)
316
+ affine_tester(:trans_scale, 'LINESTRING (0 2, 0 11)', 'LINESTRING (1 1, 10 10)', 1, 1, 0, 1)
317
+ affine_tester(:trans_scale, 'LINESTRING (2 0, 11 0)', 'LINESTRING (1 1, 10 10)', 1, 1, 1, 0)
318
+ affine_tester(:trans_scale, 'LINESTRING (3 2, 12 11)', 'LINESTRING (1 1, 10 10)', 2, 1, 1, 1)
319
+ affine_tester(:trans_scale, 'LINESTRING (2 3, 11 12)', 'LINESTRING (1 1, 10 10)', 1, 2, 1, 1)
320
+ affine_tester(:trans_scale, 'LINESTRING (4 2, 22 11)', 'LINESTRING (1 1, 10 10)', 1, 1, 2, 1)
321
+ affine_tester(:trans_scale, 'LINESTRING (2 4, 11 22)', 'LINESTRING (1 1, 10 10)', 1, 1, 1, 2)
322
+ affine_tester(:trans_scale, 'LINESTRING (15 28, 60 91)', 'LINESTRING (1 1, 10 10)', 2, 3, 5, 7)
323
+
324
+ writer.output_dimensions = 3
325
+ affine_tester(:trans_scale, 'LINESTRING Z (15 28 1, 60 91 10)', 'LINESTRING Z (1 1 1, 10 10 10)', 2, 3, 5, 7)
326
+ end
327
+
328
+ def test_trans_scale_hash
329
+ affine_tester(:trans_scale, 'LINESTRING (2 2, 11 11)', 'LINESTRING (1 1, 10 10)', delta_x: 1, delta_y: 1, x_factor: 1, y_factor: 1)
330
+
331
+ writer.output_dimensions = 3
332
+ affine_tester(:trans_scale, 'LINESTRING Z (15 28 1, 60 91 10)', 'LINESTRING Z (1 1 1, 10 10 10)', delta_x: 2, delta_y: 3, x_factor: 5, y_factor: 7)
333
+ affine_tester(:trans_scale, 'LINESTRING Z (3 1 1, 12 10 10)', 'LINESTRING Z (1 1 1, 10 10 10)', delta_x: 2, z_factor: 2)
334
+ end
335
+
336
+ def test_translate
337
+ affine_tester(:translate, 'LINESTRING (5 12, 15 22)', 'LINESTRING (0 0, 10 10)', 5, 12)
338
+
339
+ writer.output_dimensions = 3
340
+ affine_tester(:translate, 'LINESTRING Z (-3 -7 3, 7 3 13)', 'LINESTRING Z (0 0 0, 10 10 10)', -3, -7, 3)
341
+ end
342
+
343
+ def test_translate_hash
344
+ affine_tester(:translate, 'LINESTRING (5 12, 15 22)', 'LINESTRING (0 0, 10 10)', x: 5, y: 12)
345
+
346
+ writer.output_dimensions = 3
347
+ affine_tester(:translate, 'LINESTRING Z (-3 -7 3, 7 3 13)', 'LINESTRING Z (0 0 0, 10 10 10)', x: -3, y: -7, z: 3)
348
+ end
349
+
350
+ def test_line_interpolate_point
351
+ %w{
352
+ line_interpolate_point
353
+ interpolate_point
354
+ }.each do |method|
355
+ writer.output_dimensions = 2
356
+ simple_tester(method, 'POINT (0 0)', 'LINESTRING (0 0, 1 1)', 0)
357
+ simple_tester(method, 'POINT (1 1)', 'LINESTRING (0 0, 1 1)', 1)
358
+ simple_tester(method, 'POINT (0 25)', 'LINESTRING (0 0, 0 25, 0 50, 0 75, 0 100)', 0.25)
359
+
360
+ writer.output_dimensions = 3
361
+ simple_tester(method, 'POINT Z (0.5 0.5 7.5)', 'LINESTRING(0 0 10, 1 1 5)', 0.5)
362
+ end
363
+ end
364
+
365
+ def test_line_interpolate_point_with_srid
366
+ writer.trim = true
367
+
368
+ srid_copy_tester(:line_interpolate_point, 'POINT (0 0)', 0, :zero, 'LINESTRING (0 0, 1 1)', 0)
369
+ srid_copy_tester(:line_interpolate_point, 'POINT (0 0)', 4326, :lenient, 'LINESTRING (0 0, 1 1)', 0)
370
+ srid_copy_tester(:line_interpolate_point, 'POINT (0 0)', 4326, :strict, 'LINESTRING (0 0, 1 1)', 0)
371
+
372
+ srid_copy_tester(:line_interpolate_point, 'POINT (1 1)', 0, :zero, 'LINESTRING (0 0, 1 1)', 1)
373
+ srid_copy_tester(:line_interpolate_point, 'POINT (1 1)', 4326, :lenient, 'LINESTRING (0 0, 1 1)', 1)
374
+ srid_copy_tester(:line_interpolate_point, 'POINT (1 1)', 4326, :strict, 'LINESTRING (0 0, 1 1)', 1)
375
+
376
+ srid_copy_tester(:line_interpolate_point, 'POINT (0 25)', 0, :zero, 'LINESTRING (0 0, 0 25, 0 50, 0 75, 0 100)', 0.25)
377
+ srid_copy_tester(:line_interpolate_point, 'POINT (0 25)', 4326, :lenient, 'LINESTRING (0 0, 0 25, 0 50, 0 75, 0 100)', 0.25)
378
+ srid_copy_tester(:line_interpolate_point, 'POINT (0 25)', 4326, :strict, 'LINESTRING (0 0, 0 25, 0 50, 0 75, 0 100)', 0.25)
379
+
380
+ writer.output_dimensions = 3
381
+ srid_copy_tester(:line_interpolate_point, 'POINT Z (0.5 0.5 7.5)', 0, :zero, 'LINESTRING(0 0 10, 1 1 5)', 0.5)
382
+ srid_copy_tester(:line_interpolate_point, 'POINT Z (0.5 0.5 7.5)', 4326, :lenient, 'LINESTRING(0 0 10, 1 1 5)', 0.5)
383
+ srid_copy_tester(:line_interpolate_point, 'POINT Z (0.5 0.5 7.5)', 4326, :strict, 'LINESTRING(0 0 10, 1 1 5)', 0.5)
196
384
  end
197
385
  end
@@ -1,7 +1,5 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
- $: << File.dirname(__FILE__)
5
3
  require 'test_helper'
6
4
 
7
5
  class LinearRingTests < Minitest::Test
@@ -41,6 +39,6 @@ class LinearRingTests < Minitest::Test
41
39
 
42
40
  srid_copy_tester(:to_line_string, expected, 0, :zero, wkt)
43
41
  srid_copy_tester(:to_line_string, expected, 4326, :lenient, wkt)
44
- srid_copy_tester(:to_line_string, expected, 4326, :strict, wkt)
42
+ srid_copy_tester(:to_line_string, expected, 4326, :strict, wkt)
45
43
  end
46
44
  end
data/test/misc_tests.rb CHANGED
@@ -1,7 +1,5 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
- $: << File.dirname(__FILE__)
5
3
  require 'test_helper'
6
4
 
7
5
  class MiscTests < Minitest::Test
@@ -10,7 +8,7 @@ class MiscTests < Minitest::Test
10
8
  def thread_tester(name, dims, byte_order, polygon, pause)
11
9
  msg = proc { |*args| @messages << "#{name}: #{args.inspect}" }
12
10
 
13
- 3.times {
11
+ 3.times do
14
12
  sleep(pause)
15
13
  wktr = Geos::WktReader.new
16
14
  wkbw = Geos::WkbWriter.new
@@ -20,36 +18,36 @@ class MiscTests < Minitest::Test
20
18
  msg[geom.valid?]
21
19
  msg[wkbw.write_hex(geom)]
22
20
  GC.start
23
- }
21
+ end
24
22
  end
25
23
 
26
24
  def test_multithreading
27
25
  @messages = []
28
26
 
29
- t1 = Thread.new {
30
- thread_tester('t1', 2, 0, 'POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))', 0.2)
31
- }
27
+ thread_1 = Thread.new do
28
+ thread_tester('thread_1', 2, 0, 'POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))', 0.2)
29
+ end
32
30
 
33
- t2 = Thread.new {
34
- thread_tester('t2', 3, 1, 'POLYGON((0 0 0, 0 5 0, 5 5 0, 5 10 0, 0 0 0))', 0.1)
35
- }
31
+ thread_2 = Thread.new do
32
+ thread_tester('thread_2', 3, 1, 'POLYGON((0 0 0, 0 5 0, 5 5 0, 5 10 0, 0 0 0))', 0.1)
33
+ end
36
34
 
37
- t1.join
38
- t2.join
35
+ thread_1.join
36
+ thread_2.join
39
37
 
40
38
  assert_equal([
41
- "t1: [\"000000000300000001000000050000000000000000000000000000000000000000000000004014000000000000401400000000000040140000000000004014000000000000000000000000000000000000000000000000000000000000\"]",
42
- "t1: [\"000000000300000001000000050000000000000000000000000000000000000000000000004014000000000000401400000000000040140000000000004014000000000000000000000000000000000000000000000000000000000000\"]",
43
- "t1: [\"000000000300000001000000050000000000000000000000000000000000000000000000004014000000000000401400000000000040140000000000004014000000000000000000000000000000000000000000000000000000000000\"]",
44
- "t1: [true]",
45
- "t1: [true]",
46
- "t1: [true]",
47
- "t2: [\"01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000000000000144000000000000014400000000000000000000000000000144000000000000024400000000000000000000000000000000000000000000000000000000000000000\"]",
48
- "t2: [\"01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000000000000144000000000000014400000000000000000000000000000144000000000000024400000000000000000000000000000000000000000000000000000000000000000\"]",
49
- "t2: [\"01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000000000000144000000000000014400000000000000000000000000000144000000000000024400000000000000000000000000000000000000000000000000000000000000000\"]",
50
- "t2: [false]",
51
- "t2: [false]",
52
- "t2: [false]"
39
+ 'thread_1: ["000000000300000001000000050000000000000000000000000000000000000000000000004014000000000000401400000000000040140000000000004014000000000000000000000000000000000000000000000000000000000000"]',
40
+ 'thread_1: ["000000000300000001000000050000000000000000000000000000000000000000000000004014000000000000401400000000000040140000000000004014000000000000000000000000000000000000000000000000000000000000"]',
41
+ 'thread_1: ["000000000300000001000000050000000000000000000000000000000000000000000000004014000000000000401400000000000040140000000000004014000000000000000000000000000000000000000000000000000000000000"]',
42
+ 'thread_1: [true]',
43
+ 'thread_1: [true]',
44
+ 'thread_1: [true]',
45
+ 'thread_2: ["01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000000000000144000000000000014400000000000000000000000000000144000000000000024400000000000000000000000000000000000000000000000000000000000000000"]',
46
+ 'thread_2: ["01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000000000000144000000000000014400000000000000000000000000000144000000000000024400000000000000000000000000000000000000000000000000000000000000000"]',
47
+ 'thread_2: ["01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000000000000144000000000000014400000000000000000000000000000144000000000000024400000000000000000000000000000000000000000000000000000000000000000"]',
48
+ 'thread_2: [false]',
49
+ 'thread_2: [false]',
50
+ 'thread_2: [false]'
53
51
  ], @messages.sort)
54
52
  end
55
53
 
@@ -108,12 +106,12 @@ class MiscTests < Minitest::Test
108
106
  end
109
107
 
110
108
  def notice_handler_tester
111
- results = ''.dup
109
+ results = +''
112
110
  geom = read('POLYGON((0 0, 0 5, 5 0, 5 5, 0 0))')
113
111
 
114
112
  yield results
115
113
 
116
- refute(geom.valid?, "Expected geom to be invalid")
114
+ refute(geom.valid?, 'Expected geom to be invalid')
117
115
  assert_match(/^NOTICE: .+$/, results)
118
116
  ensure
119
117
  Geos.current_handle.reset_notice_handler
@@ -152,7 +150,7 @@ class MiscTests < Minitest::Test
152
150
  end
153
151
 
154
152
  def error_handler_tester
155
- results = ''.dup
153
+ results = +''
156
154
  geom = nil
157
155
 
158
156
  yield results
@@ -168,7 +166,7 @@ class MiscTests < Minitest::Test
168
166
  end
169
167
 
170
168
  def error_handler_method(results, *args)
171
- message = "ERROR: #{args[0] % args[1]}".dup
169
+ message = +"ERROR: #{args[0] % args[1]}"
172
170
  results << message
173
171
  raise message
174
172
  end
@@ -186,7 +184,7 @@ class MiscTests < Minitest::Test
186
184
 
187
185
  error_handler_tester do |results|
188
186
  Geos.current_handle.error_handler = proc do |*args|
189
- message = "ERROR: #{args[0] % args[1]}".dup
187
+ message = +"ERROR: #{args[0] % args[1]}"
190
188
  results << message
191
189
  raise message
192
190
  end
@@ -198,7 +196,7 @@ class MiscTests < Minitest::Test
198
196
 
199
197
  error_handler_tester do |results|
200
198
  Geos.current_handle.error_handler do |*args|
201
- message = "ERROR: #{args[0] % args[1]}".dup
199
+ message = +"ERROR: #{args[0] % args[1]}"
202
200
  results << message
203
201
  raise message
204
202
  end