ffi-geos 1.2.1 → 1.2.2

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 (49) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +20 -0
  3. data/.travis.yml +7 -3
  4. data/Gemfile +1 -1
  5. data/Guardfile +4 -5
  6. data/ffi-geos.gemspec +1 -1
  7. data/lib/ffi-geos.rb +212 -196
  8. data/lib/ffi-geos/buffer_params.rb +9 -20
  9. data/lib/ffi-geos/coordinate_sequence.rb +342 -58
  10. data/lib/ffi-geos/geometry.rb +167 -178
  11. data/lib/ffi-geos/geometry_collection.rb +60 -12
  12. data/lib/ffi-geos/interrupt.rb +2 -4
  13. data/lib/ffi-geos/line_string.rb +146 -37
  14. data/lib/ffi-geos/linear_ring.rb +2 -3
  15. data/lib/ffi-geos/multi_line_string.rb +1 -2
  16. data/lib/ffi-geos/multi_point.rb +0 -1
  17. data/lib/ffi-geos/multi_polygon.rb +0 -1
  18. data/lib/ffi-geos/point.rb +69 -14
  19. data/lib/ffi-geos/polygon.rb +110 -21
  20. data/lib/ffi-geos/prepared_geometry.rb +11 -12
  21. data/lib/ffi-geos/strtree.rb +41 -52
  22. data/lib/ffi-geos/tools.rb +15 -18
  23. data/lib/ffi-geos/utils.rb +27 -44
  24. data/lib/ffi-geos/version.rb +1 -3
  25. data/lib/ffi-geos/wkb_reader.rb +4 -9
  26. data/lib/ffi-geos/wkb_writer.rb +14 -18
  27. data/lib/ffi-geos/wkt_reader.rb +2 -5
  28. data/lib/ffi-geos/wkt_writer.rb +17 -22
  29. data/test/.rubocop.yml +36 -0
  30. data/test/coordinate_sequence_tests.rb +263 -14
  31. data/test/geometry_collection_tests.rb +412 -1
  32. data/test/geometry_tests.rb +156 -86
  33. data/test/interrupt_tests.rb +2 -4
  34. data/test/line_string_tests.rb +212 -23
  35. data/test/linear_ring_tests.rb +1 -2
  36. data/test/misc_tests.rb +28 -29
  37. data/test/multi_line_string_tests.rb +0 -1
  38. data/test/point_tests.rb +158 -1
  39. data/test/polygon_tests.rb +284 -1
  40. data/test/prepared_geometry_tests.rb +1 -3
  41. data/test/strtree_tests.rb +9 -10
  42. data/test/test_helper.rb +49 -18
  43. data/test/tools_tests.rb +1 -3
  44. data/test/utils_tests.rb +22 -22
  45. data/test/wkb_reader_tests.rb +10 -9
  46. data/test/wkb_writer_tests.rb +5 -13
  47. data/test/wkt_reader_tests.rb +1 -2
  48. data/test/wkt_writer_tests.rb +9 -14
  49. metadata +6 -3
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'test_helper'
@@ -72,11 +71,10 @@ class LineStringTests < Minitest::Test
72
71
  :offset_curve,
73
72
  'LINESTRING (0 2, 10 2)',
74
73
  'LINESTRING (0 0, 10 0)',
75
- 2, {
76
- :quad_segs => 0,
77
- :join => :round,
78
- :mitre_limit => 2
79
- }
74
+ 2,
75
+ quad_segs: 0,
76
+ join: :round,
77
+ mitre_limit: 2
80
78
  )
81
79
 
82
80
  # straight right
@@ -84,11 +82,10 @@ class LineStringTests < Minitest::Test
84
82
  :offset_curve,
85
83
  'LINESTRING (10 -2, 0 -2)',
86
84
  'LINESTRING (0 0, 10 0)',
87
- -2, {
88
- :quad_segs => 0,
89
- :join => :round,
90
- :mitre_limit => 2
91
- }
85
+ -2,
86
+ quad_segs: 0,
87
+ join: :round,
88
+ mitre_limit: 2
92
89
  )
93
90
 
94
91
  # outside curve
@@ -96,11 +93,10 @@ class LineStringTests < Minitest::Test
96
93
  :offset_curve,
97
94
  'LINESTRING (12 10, 12 0, 10 -2, 0 -2)',
98
95
  'LINESTRING (0 0, 10 0, 10 10)',
99
- -2, {
100
- :quad_segs => 1,
101
- :join => :round,
102
- :mitre_limit => 2
103
- }
96
+ -2,
97
+ quad_segs: 1,
98
+ join: :round,
99
+ mitre_limit: 2
104
100
  )
105
101
 
106
102
  # inside curve
@@ -108,11 +104,10 @@ class LineStringTests < Minitest::Test
108
104
  :offset_curve,
109
105
  'LINESTRING (0 2, 8 2, 8 10)',
110
106
  'LINESTRING (0 0, 10 0, 10 10)',
111
- 2, {
112
- :quad_segs => 1,
113
- :join => :round,
114
- :mitre_limit => 2
115
- }
107
+ 2,
108
+ quad_segs: 1,
109
+ join: :round,
110
+ mitre_limit: 2
116
111
  )
117
112
  end
118
113
 
@@ -173,7 +168,7 @@ class LineStringTests < Minitest::Test
173
168
 
174
169
  srid_copy_tester(:to_linear_ring, expected, 0, :zero, wkt)
175
170
  srid_copy_tester(:to_linear_ring, expected, 4326, :lenient, wkt)
176
- srid_copy_tester(:to_linear_ring, expected, 4326, :strict, wkt)
171
+ srid_copy_tester(:to_linear_ring, expected, 4326, :strict, wkt)
177
172
  end
178
173
 
179
174
  def test_to_polygon
@@ -191,6 +186,200 @@ class LineStringTests < Minitest::Test
191
186
 
192
187
  srid_copy_tester(:to_polygon, expected, 0, :zero, wkt)
193
188
  srid_copy_tester(:to_polygon, expected, 4326, :lenient, wkt)
194
- 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)
195
384
  end
196
385
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'test_helper'
@@ -40,6 +39,6 @@ class LinearRingTests < Minitest::Test
40
39
 
41
40
  srid_copy_tester(:to_line_string, expected, 0, :zero, wkt)
42
41
  srid_copy_tester(:to_line_string, expected, 4326, :lenient, wkt)
43
- srid_copy_tester(:to_line_string, expected, 4326, :strict, wkt)
42
+ srid_copy_tester(:to_line_string, expected, 4326, :strict, wkt)
44
43
  end
45
44
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'test_helper'
@@ -9,7 +8,7 @@ class MiscTests < Minitest::Test
9
8
  def thread_tester(name, dims, byte_order, polygon, pause)
10
9
  msg = proc { |*args| @messages << "#{name}: #{args.inspect}" }
11
10
 
12
- 3.times {
11
+ 3.times do
13
12
  sleep(pause)
14
13
  wktr = Geos::WktReader.new
15
14
  wkbw = Geos::WkbWriter.new
@@ -19,36 +18,36 @@ class MiscTests < Minitest::Test
19
18
  msg[geom.valid?]
20
19
  msg[wkbw.write_hex(geom)]
21
20
  GC.start
22
- }
21
+ end
23
22
  end
24
23
 
25
24
  def test_multithreading
26
25
  @messages = []
27
26
 
28
- t1 = Thread.new {
29
- thread_tester('t1', 2, 0, 'POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))', 0.2)
30
- }
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
31
30
 
32
- t2 = Thread.new {
33
- thread_tester('t2', 3, 1, 'POLYGON((0 0 0, 0 5 0, 5 5 0, 5 10 0, 0 0 0))', 0.1)
34
- }
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
35
34
 
36
- t1.join
37
- t2.join
35
+ thread_1.join
36
+ thread_2.join
38
37
 
39
38
  assert_equal([
40
- "t1: [\"000000000300000001000000050000000000000000000000000000000000000000000000004014000000000000401400000000000040140000000000004014000000000000000000000000000000000000000000000000000000000000\"]",
41
- "t1: [\"000000000300000001000000050000000000000000000000000000000000000000000000004014000000000000401400000000000040140000000000004014000000000000000000000000000000000000000000000000000000000000\"]",
42
- "t1: [\"000000000300000001000000050000000000000000000000000000000000000000000000004014000000000000401400000000000040140000000000004014000000000000000000000000000000000000000000000000000000000000\"]",
43
- "t1: [true]",
44
- "t1: [true]",
45
- "t1: [true]",
46
- "t2: [\"01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000000000000144000000000000014400000000000000000000000000000144000000000000024400000000000000000000000000000000000000000000000000000000000000000\"]",
47
- "t2: [\"01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000000000000144000000000000014400000000000000000000000000000144000000000000024400000000000000000000000000000000000000000000000000000000000000000\"]",
48
- "t2: [\"01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000000000000144000000000000014400000000000000000000000000000144000000000000024400000000000000000000000000000000000000000000000000000000000000000\"]",
49
- "t2: [false]",
50
- "t2: [false]",
51
- "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]'
52
51
  ], @messages.sort)
53
52
  end
54
53
 
@@ -107,12 +106,12 @@ class MiscTests < Minitest::Test
107
106
  end
108
107
 
109
108
  def notice_handler_tester
110
- results = ''.dup
109
+ results = +''
111
110
  geom = read('POLYGON((0 0, 0 5, 5 0, 5 5, 0 0))')
112
111
 
113
112
  yield results
114
113
 
115
- refute(geom.valid?, "Expected geom to be invalid")
114
+ refute(geom.valid?, 'Expected geom to be invalid')
116
115
  assert_match(/^NOTICE: .+$/, results)
117
116
  ensure
118
117
  Geos.current_handle.reset_notice_handler
@@ -151,7 +150,7 @@ class MiscTests < Minitest::Test
151
150
  end
152
151
 
153
152
  def error_handler_tester
154
- results = ''.dup
153
+ results = +''
155
154
  geom = nil
156
155
 
157
156
  yield results
@@ -167,7 +166,7 @@ class MiscTests < Minitest::Test
167
166
  end
168
167
 
169
168
  def error_handler_method(results, *args)
170
- message = "ERROR: #{args[0] % args[1]}".dup
169
+ message = +"ERROR: #{args[0] % args[1]}"
171
170
  results << message
172
171
  raise message
173
172
  end
@@ -185,7 +184,7 @@ class MiscTests < Minitest::Test
185
184
 
186
185
  error_handler_tester do |results|
187
186
  Geos.current_handle.error_handler = proc do |*args|
188
- message = "ERROR: #{args[0] % args[1]}".dup
187
+ message = +"ERROR: #{args[0] % args[1]}"
189
188
  results << message
190
189
  raise message
191
190
  end
@@ -197,7 +196,7 @@ class MiscTests < Minitest::Test
197
196
 
198
197
  error_handler_tester do |results|
199
198
  Geos.current_handle.error_handler do |*args|
200
- message = "ERROR: #{args[0] % args[1]}".dup
199
+ message = +"ERROR: #{args[0] % args[1]}"
201
200
  results << message
202
201
  raise message
203
202
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'test_helper'
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'test_helper'
@@ -102,4 +101,162 @@ class PointTests < Minitest::Test
102
101
  assert_equal(geom.object_id, geom.normalize.object_id)
103
102
  assert_equal(geom.object_id, geom.normalize!.object_id)
104
103
  end
104
+
105
+ def test_x_max
106
+ geom = read('POINT (-10 -15)')
107
+ assert_equal(-10, geom.x_max)
108
+ end
109
+
110
+ def test_x_min
111
+ geom = read('POINT (-10 -15)')
112
+ assert_equal(-10, geom.x_min)
113
+ end
114
+
115
+ def test_y_max
116
+ geom = read('POINT (-10 -15)')
117
+ assert_equal(-15, geom.y_max)
118
+ end
119
+
120
+ def test_y_min
121
+ geom = read('POINT (-10 -15)')
122
+ assert_equal(-15, geom.y_min)
123
+ end
124
+
125
+ def test_z_max
126
+ geom = read('POINT (-10 -15)')
127
+ assert_equal(0, geom.z_max)
128
+
129
+ geom = read('POINT Z (-10 -15 -20)')
130
+ assert_equal(-20, geom.z_max)
131
+ end
132
+
133
+ def test_z_min
134
+ geom = read('POINT (-10 -15)')
135
+ assert_equal(0, geom.z_min)
136
+
137
+ geom = read('POINT Z (-10 -15 -20)')
138
+ assert_equal(-20, geom.z_min)
139
+ end
140
+
141
+ def test_snap_to_grid
142
+ wkt = 'POINT (10.12 10.12)'
143
+ expected = 'POINT (10 10)'
144
+
145
+ simple_bang_tester(:snap_to_grid, expected, wkt, 1)
146
+ end
147
+
148
+ def test_snap_to_grid_empty
149
+ assert(read('POINT EMPTY').snap_to_grid!.empty?, 'Expected an empty Point')
150
+ end
151
+
152
+ def test_snap_to_grid_with_srid
153
+ wkt = 'POINT (10.12 10.12)'
154
+ expected = 'POINT (10 10)'
155
+
156
+ srid_copy_tester(:snap_to_grid, expected, 0, :zero, wkt, 1)
157
+ srid_copy_tester(:snap_to_grid, expected, 4326, :lenient, wkt, 1)
158
+ srid_copy_tester(:snap_to_grid, expected, 4326, :strict, wkt, 1)
159
+ end
160
+
161
+ def test_rotate
162
+ writer.rounding_precision = 3
163
+
164
+ wkt = 'POINT (1 1)'
165
+
166
+ affine_tester(:rotate, 'POINT (29 11)', wkt, Math::PI / 2, [ 10.0, 20.0 ])
167
+ affine_tester(:rotate, 'POINT (-2 0)', wkt, -Math::PI / 2, [ -1.0, 2.0 ])
168
+ affine_tester(:rotate, 'POINT (19 1)', wkt, Math::PI / 2, read('POINT(10 10)'))
169
+ affine_tester(:rotate, 'POINT (-0.5 0.5)', wkt, Math::PI / 2, read('LINESTRING(0 0, 1 0)'))
170
+ end
171
+
172
+ def test_rotate_x
173
+ writer.rounding_precision = 0
174
+ writer.output_dimensions = 3
175
+
176
+ wkt = 'POINT Z (1 1 1)'
177
+
178
+ affine_tester(:rotate_x, 'POINT Z (1 -1 -1)', wkt, Math::PI)
179
+ affine_tester(:rotate_x, 'POINT Z (1 -1 1)', wkt, Math::PI / 2)
180
+ affine_tester(:rotate_x, 'POINT Z (1 1 -1)', wkt, Math::PI + Math::PI / 2)
181
+ affine_tester(:rotate_x, wkt, wkt, Math::PI * 2)
182
+ end
183
+
184
+ def test_rotate_y
185
+ writer.rounding_precision = 0
186
+ writer.output_dimensions = 3
187
+
188
+ wkt = 'POINT Z (1 1 1)'
189
+
190
+ affine_tester(:rotate_y, 'POINT Z (-1 1 -1)', wkt, Math::PI)
191
+ affine_tester(:rotate_y, 'POINT Z (1 1 -1)', wkt, Math::PI / 2)
192
+ affine_tester(:rotate_y, 'POINT Z (-1 1 1)', wkt, Math::PI + Math::PI / 2)
193
+ affine_tester(:rotate_y, wkt, wkt, Math::PI * 2)
194
+ end
195
+
196
+ def test_rotate_z
197
+ writer.rounding_precision = 0
198
+
199
+ wkt = 'POINT (1 1)'
200
+
201
+ affine_tester(:rotate_z, 'POINT (-1 -1)', wkt, Math::PI)
202
+ affine_tester(:rotate_z, 'POINT (-1 1)', wkt, Math::PI / 2)
203
+ affine_tester(:rotate_z, 'POINT (1 -1)', wkt, Math::PI + Math::PI / 2)
204
+ affine_tester(:rotate_z, wkt, wkt, Math::PI * 2)
205
+ end
206
+
207
+ def test_scale
208
+ affine_tester(:scale, 'POINT (5 5)', 'POINT (1 1)', 5, 5)
209
+ affine_tester(:scale, 'POINT (3 2)', 'POINT (1 1)', 3, 2)
210
+
211
+ writer.output_dimensions = 3
212
+ affine_tester(:scale, 'POINT Z (40 40 40)', 'POINT Z (10 20 -5)', 4, 2, -8)
213
+ end
214
+
215
+ def test_scale_hash
216
+ affine_tester(:scale, 'POINT (5 5)', 'POINT (1 1)', x: 5, y: 5)
217
+ affine_tester(:scale, 'POINT (3 2)', 'POINT (1 1)', x: 3, y: 2)
218
+
219
+ writer.output_dimensions = 3
220
+ affine_tester(:scale, 'POINT Z (40 40 40)', 'POINT Z (10 20 -5)', x: 4, y: 2, z: -8)
221
+ end
222
+
223
+ def test_trans_scale
224
+ affine_tester(:trans_scale, 'POINT (2 2)', 'POINT (1 1)', 1, 1, 1, 1)
225
+ affine_tester(:trans_scale, 'POINT (3 3)', 'POINT (2 2)', 1, 1, 1, 1)
226
+ affine_tester(:trans_scale, 'POINT (0 0)', 'POINT (1 1)', -1, -1, -1, -1)
227
+ affine_tester(:trans_scale, 'POINT (1 2)', 'POINT (1 1)', 0, 1, 1, 1)
228
+ affine_tester(:trans_scale, 'POINT (2 1)', 'POINT (1 1)', 1, 0, 1, 1)
229
+ affine_tester(:trans_scale, 'POINT (0 2)', 'POINT (1 1)', 1, 1, 0, 1)
230
+ affine_tester(:trans_scale, 'POINT (2 0)', 'POINT (1 1)', 1, 1, 1, 0)
231
+ affine_tester(:trans_scale, 'POINT (3 2)', 'POINT (1 1)', 2, 1, 1, 1)
232
+ affine_tester(:trans_scale, 'POINT (2 3)', 'POINT (1 1)', 1, 2, 1, 1)
233
+ affine_tester(:trans_scale, 'POINT (4 2)', 'POINT (1 1)', 1, 1, 2, 1)
234
+ affine_tester(:trans_scale, 'POINT (2 4)', 'POINT (1 1)', 1, 1, 1, 2)
235
+ affine_tester(:trans_scale, 'POINT (15 28)', 'POINT (1 1)', 2, 3, 5, 7)
236
+
237
+ writer.output_dimensions = 3
238
+ affine_tester(:trans_scale, 'POINT Z (15 28 1)', 'POINT Z (1 1 1)', 2, 3, 5, 7)
239
+ end
240
+
241
+ def test_trans_scale_hash
242
+ affine_tester(:trans_scale, 'POINT (2 2)', 'POINT (1 1)', delta_x: 1, delta_y: 1, x_factor: 1, y_factor: 1)
243
+
244
+ writer.output_dimensions = 3
245
+ affine_tester(:trans_scale, 'POINT Z (15 28 1)', 'POINT Z (1 1 1)', delta_x: 2, delta_y: 3, x_factor: 5, y_factor: 7)
246
+ affine_tester(:trans_scale, 'POINT Z (3 1 1)', 'POINT Z (1 1 1)', delta_x: 2, z_factor: 2)
247
+ end
248
+
249
+ def test_translate
250
+ affine_tester(:translate, 'POINT (5 12)', 'POINT (0 0)', 5, 12)
251
+
252
+ writer.output_dimensions = 3
253
+ affine_tester(:translate, 'POINT Z (-3 -7 3)', 'POINT Z (0 0 0)', -3, -7, 3)
254
+ end
255
+
256
+ def test_translate_hash
257
+ affine_tester(:translate, 'POINT (5 12)', 'POINT (0 0)', x: 5, y: 12)
258
+
259
+ writer.output_dimensions = 3
260
+ affine_tester(:translate, 'POINT Z (-3 -7 3)', 'POINT Z (0 0 0)', x: -3, y: -7, z: 3)
261
+ end
105
262
  end