ffi-geos 2.1.0 → 2.3.1

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.
@@ -23,18 +23,19 @@ module Geos
23
23
  geoms_and_objects = nil # forward declaration
24
24
  capacity = 10
25
25
 
26
- if args.first.is_a?(Integer)
27
- capacity = args.first
28
- elsif args.first.is_a?(Array)
29
- geoms_and_objects = if args.first.first.is_a?(Array)
30
- args.first
31
- else
32
- args
33
- end
26
+ case args.first
27
+ when Integer
28
+ capacity = args.first
29
+ when Array
30
+ geoms_and_objects = if args.first.first.is_a?(Array)
31
+ args.first
32
+ else
33
+ args
34
+ end
34
35
 
35
- geoms_and_objects.each do |geom, _obj|
36
- check_geometry(geom)
37
- end
36
+ geoms_and_objects.each do |geom, _obj|
37
+ check_geometry(geom)
38
+ end
38
39
  end
39
40
 
40
41
  raise ArgumentError, 'STRtree capacity must be greater than 0' if capacity <= 0
@@ -59,7 +60,7 @@ module Geos
59
60
  end
60
61
  end
61
62
 
62
- def self.release(ptr) #:nodoc:
63
+ def self.release(ptr) # :nodoc:
63
64
  FFIGeos.GEOSSTRtree_destroy_r(Geos.current_handle_pointer, ptr)
64
65
  end
65
66
 
@@ -97,7 +98,7 @@ module Geos
97
98
  def remove(geom, item)
98
99
  check_geometry(geom)
99
100
 
100
- key = if storage = @storage.detect { |_k, v| v[:item] == item }
101
+ key = if (storage = @storage.detect { |_k, v| v[:item] == item })
101
102
  storage[0]
102
103
  end
103
104
 
@@ -137,16 +138,17 @@ module Geos
137
138
 
138
139
  def query(geom, ret = :item)
139
140
  query_all(geom).collect { |storage|
140
- item = if ret.is_a?(Array)
141
- storage.inject({}) do |memo, k|
142
- memo.tap do
143
- memo[k] = storage[k]
141
+ item = case ret
142
+ when Array
143
+ storage.inject({}) do |memo, k|
144
+ memo.tap do
145
+ memo[k] = storage[k]
146
+ end
144
147
  end
145
- end
146
- elsif ret == :all
147
- storage
148
- else
149
- storage[ret]
148
+ when :all
149
+ storage
150
+ else
151
+ storage[ret]
150
152
  end
151
153
 
152
154
  item.tap do
@@ -164,10 +166,8 @@ module Geos
164
166
  end
165
167
  alias query_geoms query_geometries
166
168
 
167
- def iterate
168
- @storage.each_value do |v|
169
- yield(v)
170
- end
169
+ def iterate(&block)
170
+ @storage.each_value(&block)
171
171
  end
172
172
 
173
173
  if FFIGeos.respond_to?(:GEOSSTRtree_nearest_generic_r)
@@ -30,17 +30,18 @@ module Geos
30
30
  def create_point(*args)
31
31
  options = extract_options!(args)
32
32
 
33
- if args.length == 1
34
- cs = args.first
35
- elsif args.length == 2
36
- cs = CoordinateSequence.new(1, 2)
37
- cs.x[0] = args[0].to_f
38
- cs.y[0] = args[1].to_f
39
- elsif args.length == 3
40
- cs = CoordinateSequence.new(1, 3)
41
- cs.x[0], cs.y[0], cs.z[0] = args.map(&:to_f)
42
- else
43
- raise ArgumentError, "Wrong number of arguments (#{args.length} for 1-3)"
33
+ case args.length
34
+ when 1
35
+ cs = args.first
36
+ when 2
37
+ cs = CoordinateSequence.new(1, 2)
38
+ cs.x[0] = args[0].to_f
39
+ cs.y[0] = args[1].to_f
40
+ when 3
41
+ cs = CoordinateSequence.new(1, 3)
42
+ cs.x[0], cs.y[0], cs.z[0] = args.map(&:to_f)
43
+ else
44
+ raise ArgumentError, "Wrong number of arguments (#{args.length} for 1-3)"
44
45
  end
45
46
 
46
47
  raise ArgumentError, 'IllegalArgumentException: Point coordinate list must contain a single element' if cs.length != 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Geos
4
- VERSION = '2.1.0'
4
+ VERSION = '2.3.1'
5
5
  end
@@ -34,7 +34,7 @@ module Geos
34
34
  raise ParseError, e
35
35
  end
36
36
 
37
- def self.release(ptr) #:nodoc:
37
+ def self.release(ptr) # :nodoc:
38
38
  FFIGeos.GEOSWKBReader_destroy_r(Geos.current_handle_pointer, ptr)
39
39
  end
40
40
  end
@@ -20,7 +20,7 @@ module Geos
20
20
  set_options(options)
21
21
  end
22
22
 
23
- def self.release(ptr) #:nodoc:
23
+ def self.release(ptr) # :nodoc:
24
24
  FFIGeos.GEOSWKBWriter_destroy_r(Geos.current_handle_pointer, ptr)
25
25
  end
26
26
 
@@ -85,7 +85,7 @@ module Geos
85
85
 
86
86
  private
87
87
 
88
- def set_options(options) #:nodoc:
88
+ def set_options(options) # :nodoc:
89
89
  self.include_srid = options[:include_srid] if options.key?(:include_srid)
90
90
  end
91
91
  end
@@ -28,7 +28,7 @@ module Geos
28
28
  raise ParseError, e
29
29
  end
30
30
 
31
- def self.release(ptr) #:nodoc:
31
+ def self.release(ptr) # :nodoc:
32
32
  FFIGeos.GEOSWKTReader_destroy_r(Geos.current_handle_pointer, ptr)
33
33
  end
34
34
  end
@@ -2,10 +2,7 @@
2
2
 
3
3
  module Geos
4
4
  class WktWriter
5
- attr_reader :ptr
6
- attr_reader :old_3d
7
- attr_reader :rounding_precision
8
- attr_reader :trim
5
+ attr_reader :ptr, :old_3d, :rounding_precision, :trim
9
6
 
10
7
  def initialize(options = {})
11
8
  options = {
@@ -24,11 +21,11 @@ module Geos
24
21
  set_options(options)
25
22
  end
26
23
 
27
- def self.release(ptr) #:nodoc:
24
+ def self.release(ptr) # :nodoc:
28
25
  FFIGeos.GEOSWKTWriter_destroy_r(Geos.current_handle_pointer, ptr)
29
26
  end
30
27
 
31
- def set_options(options) #:nodoc:
28
+ def set_options(options) # :nodoc:
32
29
  [:trim, :old_3d, :rounding_precision, :output_dimensions].each do |k|
33
30
  send("#{k}=", options[k]) if respond_to?("#{k}=") && options.key?(k)
34
31
  end
data/lib/ffi-geos.rb CHANGED
@@ -50,15 +50,20 @@ module Geos
50
50
 
51
51
  module FFIGeos
52
52
  def self.search_paths
53
- @search_paths ||= begin
53
+ @search_paths ||= \
54
54
  if ENV['GEOS_LIBRARY_PATH']
55
55
  [ENV['GEOS_LIBRARY_PATH']]
56
56
  elsif FFI::Platform::IS_WINDOWS
57
57
  ENV['PATH'].split(File::PATH_SEPARATOR)
58
58
  else
59
- ['/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}', '/usr/lib/{x86_64,i386}-linux-gnu']
59
+ [
60
+ '/usr/local/{lib64,lib}',
61
+ '/opt/local/{lib64,lib}',
62
+ '/usr/{lib64,lib}',
63
+ '/opt/homebrew/lib',
64
+ '/usr/lib/{x86_64,i386,aarch64}-linux-gnu'
65
+ ]
60
66
  end
61
- end
62
67
  end
63
68
 
64
69
  def self.find_lib(lib)
@@ -72,10 +77,9 @@ module Geos
72
77
  end
73
78
 
74
79
  def self.geos_library_path
75
- @geos_library_path ||= begin
80
+ @geos_library_path ||= \
76
81
  # On MingW the libraries have version numbers
77
82
  find_lib('{lib,}geos_c{,-?}')
78
- end
79
83
  end
80
84
 
81
85
  # For backwards compatibility with older ffi-geos versions where this
@@ -406,6 +410,11 @@ module Geos
406
410
  :pointer, :pointer, :pointer, :pointer
407
411
  ],
408
412
 
413
+ GEOSIntersectionPrec_r: [
414
+ # *geom, *handle, *geom_a, *geom_b, precision
415
+ :pointer, :pointer, :pointer, :pointer, :double
416
+ ],
417
+
409
418
  GEOSBufferWithParams_r: [
410
419
  # *geom, *handle, *geom, *params, width
411
420
  :pointer, :pointer, :pointer, :pointer, :double
@@ -442,11 +451,21 @@ module Geos
442
451
  :pointer, :pointer, :pointer, :pointer
443
452
  ],
444
453
 
454
+ GEOSDifferencePrec_r: [
455
+ # *geom, *handle, *geom_a, *geom_b, precision
456
+ :pointer, :pointer, :pointer, :pointer, :double
457
+ ],
458
+
445
459
  GEOSSymDifference_r: [
446
460
  # *geom, *handle, *geom_a, *geom_b
447
461
  :pointer, :pointer, :pointer, :pointer
448
462
  ],
449
463
 
464
+ GEOSSymDifferencePrec_r: [
465
+ # *geom, *handle, *geom_a, *geom_b, precision
466
+ :pointer, :pointer, :pointer, :pointer, :double
467
+ ],
468
+
450
469
  GEOSBoundary_r: [
451
470
  # *geom, *handle, *geom
452
471
  :pointer, :pointer, :pointer
@@ -457,6 +476,11 @@ module Geos
457
476
  :pointer, :pointer, :pointer, :pointer
458
477
  ],
459
478
 
479
+ GEOSUnionPrec_r: [
480
+ # *geom, *handle, *geom_a, *geom_b, precision
481
+ :pointer, :pointer, :pointer, :pointer, :double
482
+ ],
483
+
460
484
  GEOSCoverageUnion_r: [
461
485
  # *geom, *handle, *geom
462
486
  :pointer, :pointer, :pointer
@@ -467,6 +491,11 @@ module Geos
467
491
  :pointer, :pointer, :pointer
468
492
  ],
469
493
 
494
+ GEOSUnaryUnionPrec_r: [
495
+ # *geom, *handle, *geom, precision
496
+ :pointer, :pointer, :pointer, :double
497
+ ],
498
+
470
499
  GEOSNode_r: [
471
500
  # *geom, *handle, *geom
472
501
  :pointer, :pointer, :pointer
@@ -798,6 +827,16 @@ module Geos
798
827
  :pointer, :pointer, :pointer
799
828
  ],
800
829
 
830
+ GEOSMaximumInscribedCircle_r: [
831
+ # *geom, *handle, *geom, tolerance
832
+ :pointer, :pointer, :pointer, :double
833
+ ],
834
+
835
+ GEOSLargestEmptyCircle_r: [
836
+ # *geom, *handle, *geom, *geom, tolerance
837
+ :pointer, :pointer, :pointer, :pointer, :double
838
+ ],
839
+
801
840
  GEOSMinimumWidth_r: [
802
841
  # *geom, *handle, *geom
803
842
  :pointer, :pointer, :pointer
@@ -1330,12 +1369,14 @@ module Geos
1330
1369
  GEOS_CAPI_VERSION,
1331
1370
  GEOS_CAPI_VERSION_MAJOR, GEOS_CAPI_VERSION_MINOR, GEOS_CAPI_VERSION_PATCH,
1332
1371
  GEOS_SVN_REVISION =
1333
- if !(versions = Geos.version.scan(/^
1372
+ if (versions = Geos.version.scan(/^
1334
1373
  ((\d+)\.(\d+)\.(\d+)((?:dev|rc|beta|alpha)\d*)?)
1335
1374
  -CAPI-
1336
1375
  ((\d+)\.(\d+)\.(\d+))
1337
1376
  (?:\s+r?(\h+))?
1338
1377
  $/x)).empty?
1378
+ ['0.0.0', 0, 0, 0, nil, '0.0.0', 0, 0, 0]
1379
+ else
1339
1380
  versions = versions[0]
1340
1381
  [
1341
1382
  versions[0],
@@ -1349,11 +1390,13 @@ module Geos
1349
1390
  versions[8].to_i,
1350
1391
  versions[9]&.to_i
1351
1392
  ]
1352
- else
1353
- ['0.0.0', 0, 0, 0, nil, '0.0.0', 0, 0, 0]
1354
1393
  end
1355
1394
  GEOS_CAPI_FIRST_INTERFACE = GEOS_CAPI_VERSION_MAJOR.to_i
1356
1395
  GEOS_CAPI_LAST_INTERFACE = GEOS_CAPI_VERSION_MAJOR.to_i + GEOS_CAPI_VERSION_MINOR.to_i
1396
+
1397
+ GEOS_NICE_VERSION = [GEOS_VERSION_MAJOR, GEOS_VERSION_MINOR, GEOS_VERSION_PATCH].collect { |version|
1398
+ version.to_s.rjust(2, '0')
1399
+ }.join
1357
1400
  end
1358
1401
 
1359
1402
  module Constants
@@ -2,15 +2,15 @@ sonar.projectKey=dark-panda_ffi-geos
2
2
  sonar.organization=dark-panda
3
3
 
4
4
  # This is the name and version displayed in the SonarCloud UI.
5
- #sonar.projectName=ffi-geos
6
- #sonar.projectVersion=1.0
5
+ sonar.projectName=ffi-geos
6
+ sonar.projectVersion=1.0
7
7
 
8
8
  # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
9
9
  sonar.sources=lib, test
10
10
 
11
11
  # Encoding of the source code. Default is default system encoding
12
- #sonar.sourceEncoding=UTF-8
12
+ sonar.sourceEncoding=UTF-8
13
13
 
14
14
  # Additional reports
15
15
  sonar.ruby.rubocop.reportPaths=rubocop-report.json
16
- sonar.ruby.coverage.reportPaths=coverage/.resultset.json
16
+ sonar.ruby.coverage.reportPaths=coverage/coverage.json
@@ -284,7 +284,7 @@ class CoordinateSequenceTests < Minitest::Test
284
284
 
285
285
  assert_kind_of(Enumerable, cs.x.each)
286
286
  assert_kind_of(Enumerable, cs.x.to_enum)
287
- assert_equal(cs.x, cs.x.each {})
287
+ assert_equal(cs.x, cs.x.each(&EMPTY_BLOCK))
288
288
  end
289
289
 
290
290
  def test_options_hash
@@ -299,7 +299,7 @@ class CoordinateSequenceTests < Minitest::Test
299
299
 
300
300
  assert_kind_of(Enumerable, cs.each)
301
301
  assert_kind_of(Enumerable, cs.to_enum)
302
- assert_equal(cs, cs.each {})
302
+ assert_equal(cs, cs.each(&EMPTY_BLOCK))
303
303
  end
304
304
 
305
305
  def test_array_like_access
@@ -515,16 +515,16 @@ class CoordinateSequenceTests < Minitest::Test
515
515
  end
516
516
 
517
517
  undef :affine_tester
518
- def affine_tester(method, expected, coords, *args)
518
+ def affine_tester(method, expected, coords, *args, **options)
519
519
  cs = Geos::CoordinateSequence.new(coords)
520
- cs.send("#{method}!", *args)
520
+ cs.__safe_send__("#{method}!", *args, **options)
521
521
 
522
522
  expected.length.times do |i|
523
523
  assert_in_delta(expected[i], cs.get_ordinate(0, i), TOLERANCE)
524
524
  end
525
525
 
526
526
  cs = Geos::CoordinateSequence.new(coords)
527
- cs_2 = cs.send(method, *args)
527
+ cs_2 = cs.__safe_send__(method, *args, **options)
528
528
 
529
529
  expected.length.times do |i|
530
530
  assert_in_delta(coords[i], cs.get_ordinate(0, i), TOLERANCE)
@@ -542,21 +542,21 @@ class CoordinateSequenceTests < Minitest::Test
542
542
  def test_rotate_x
543
543
  affine_tester(:rotate_x, [1, -1, -1], [1, 1, 1], Math::PI)
544
544
  affine_tester(:rotate_x, [1, -1, 1], [1, 1, 1], Math::PI / 2)
545
- affine_tester(:rotate_x, [1, 1, -1], [1, 1, 1], Math::PI + Math::PI / 2)
545
+ affine_tester(:rotate_x, [1, 1, -1], [1, 1, 1], Math::PI + (Math::PI / 2))
546
546
  affine_tester(:rotate_x, [1, 1, 1], [1, 1, 1], Math::PI * 2)
547
547
  end
548
548
 
549
549
  def test_rotate_y
550
550
  affine_tester(:rotate_y, [-1, 1, -1], [1, 1, 1], Math::PI)
551
551
  affine_tester(:rotate_y, [1, 1, -1], [1, 1, 1], Math::PI / 2)
552
- affine_tester(:rotate_y, [-1, 1, 1], [1, 1, 1], Math::PI + Math::PI / 2)
552
+ affine_tester(:rotate_y, [-1, 1, 1], [1, 1, 1], Math::PI + (Math::PI / 2))
553
553
  affine_tester(:rotate_y, [1, 1, 1], [1, 1, 1], Math::PI * 2)
554
554
  end
555
555
 
556
556
  def test_rotate_z
557
557
  affine_tester(:rotate_z, [-1, -1], [1, 1], Math::PI)
558
558
  affine_tester(:rotate_z, [-1, 1], [1, 1], Math::PI / 2)
559
- affine_tester(:rotate_z, [1, -1], [1, 1], Math::PI + Math::PI / 2)
559
+ affine_tester(:rotate_z, [1, -1], [1, 1], Math::PI + (Math::PI / 2))
560
560
  affine_tester(:rotate_z, [1, 1], [1, 1], Math::PI * 2)
561
561
  end
562
562
 
@@ -16,7 +16,7 @@ class GeometryCollectionTests < Minitest::Test
16
16
  geom = read('GEOMETRYCOLLECTION(POINT(0 0))')
17
17
  assert_kind_of(Enumerable, geom.each)
18
18
  assert_kind_of(Enumerable, geom.to_enum)
19
- assert_equal(geom, geom.each {})
19
+ assert_equal(geom, geom.each(&EMPTY_BLOCK))
20
20
  end
21
21
 
22
22
  def test_geometry_collection_array
@@ -173,7 +173,8 @@ class GeometryCollectionTests < Minitest::Test
173
173
  end
174
174
 
175
175
  def test_snap_to_grid
176
- wkt = 'GEOMETRYCOLLECTION (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), POLYGON ((-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)), POINT (10.12 10.12))'
176
+ wkt = 'GEOMETRYCOLLECTION (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), ' \
177
+ 'POLYGON ((-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)), POINT (10.12 10.12))'
177
178
 
178
179
  expected = 'GEOMETRYCOLLECTION (LINESTRING (-10 0, -10 5, -10 5, -10 6, -10 6, -10 6, -10 7, -10 7, -10 7, -10 8, -10 8, -9 8, -9 9, -10 0), POLYGON ((-10 0, -10 5, -10 5, -10 6, -10 6, -10 6, -10 7, -10 7, -10 7, -10 8, -10 8, -9 8, -9 9, -10 0)), POINT (10 10))'
179
180
 
@@ -254,7 +255,7 @@ class GeometryCollectionTests < Minitest::Test
254
255
  affine_tester(:rotate_x,
255
256
  'GEOMETRYCOLLECTION Z (POINT Z (1 1 -1), LINESTRING Z (1 1 -1, 10 10 -10), POLYGON Z ((0 0 0, 5 0 0, 5 0 -5, 0 0 -5, 0 0 0)))',
256
257
  wkt,
257
- Math::PI + Math::PI / 2)
258
+ Math::PI + (Math::PI / 2))
258
259
 
259
260
  affine_tester(:rotate_x,
260
261
  wkt,
@@ -281,7 +282,7 @@ class GeometryCollectionTests < Minitest::Test
281
282
  affine_tester(:rotate_y,
282
283
  'GEOMETRYCOLLECTION Z (POINT Z (-1 1 1), LINESTRING Z (-1 1 1, -10 10 10), POLYGON Z ((0 0 0, 0 0 5, 0 5 5, 0 5 0, 0 0 0)))',
283
284
  wkt,
284
- Math::PI + Math::PI / 2)
285
+ Math::PI + (Math::PI / 2))
285
286
 
286
287
  affine_tester(:rotate_y,
287
288
  wkt,
@@ -307,7 +308,7 @@ class GeometryCollectionTests < Minitest::Test
307
308
  affine_tester(:rotate_z,
308
309
  'GEOMETRYCOLLECTION (POINT (1 -1), LINESTRING (0 0, 10 -10), POLYGON ((0 0, 0 -5, 5 -5, 5 0, 0 0)))',
309
310
  wkt,
310
- Math::PI + Math::PI / 2)
311
+ Math::PI + (Math::PI / 2))
311
312
 
312
313
  affine_tester(:rotate_z,
313
314
  wkt,