ffi-geos 1.2.2 → 2.3.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.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +49 -0
- data/.rubocop.yml +5117 -4
- data/FUNDING.yml +2 -0
- data/Gemfile +9 -16
- data/Guardfile +3 -4
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -20
- data/Rakefile +3 -2
- data/ffi-geos.gemspec +7 -2
- data/lib/ffi-geos/buffer_params.rb +1 -1
- data/lib/ffi-geos/coordinate_sequence.rb +179 -177
- data/lib/ffi-geos/geometry.rb +118 -31
- data/lib/ffi-geos/geometry_collection.rb +26 -12
- data/lib/ffi-geos/interrupt.rb +11 -14
- data/lib/ffi-geos/line_string.rb +64 -49
- data/lib/ffi-geos/multi_line_string.rb +1 -1
- data/lib/ffi-geos/point.rb +18 -18
- data/lib/ffi-geos/polygon.rb +44 -30
- data/lib/ffi-geos/prepared_geometry.rb +1 -1
- data/lib/ffi-geos/strtree.rb +28 -30
- data/lib/ffi-geos/tools.rb +1 -1
- data/lib/ffi-geos/utils.rb +16 -23
- data/lib/ffi-geos/version.rb +1 -1
- data/lib/ffi-geos/wkb_reader.rb +1 -1
- data/lib/ffi-geos/wkb_writer.rb +4 -5
- data/lib/ffi-geos/wkt_reader.rb +1 -1
- data/lib/ffi-geos/wkt_writer.rb +7 -13
- data/lib/ffi-geos.rb +134 -48
- data/sonar-project.properties +16 -0
- data/test/coordinate_sequence_tests.rb +148 -126
- data/test/geometry_collection_tests.rb +41 -67
- data/test/geometry_tests.rb +341 -40
- data/test/interrupt_tests.rb +7 -7
- data/test/line_string_tests.rb +23 -15
- data/test/point_tests.rb +5 -5
- data/test/polygon_tests.rb +6 -7
- data/test/prepared_geometry_tests.rb +8 -8
- data/test/strtree_tests.rb +13 -12
- data/test/test_helper.rb +74 -56
- data/test/utils_tests.rb +69 -59
- data/test/wkb_reader_tests.rb +9 -9
- data/test/wkb_writer_tests.rb +14 -12
- data/test/wkt_reader_tests.rb +0 -1
- data/test/wkt_writer_tests.rb +2 -5
- metadata +12 -10
- data/.travis.yml +0 -21
    
        data/test/interrupt_tests.rb
    CHANGED
    
    | @@ -39,7 +39,7 @@ class InterruptTests < Minitest::Test | |
| 39 39 |  | 
| 40 40 | 
             
                  begin
         | 
| 41 41 | 
             
                    buffer = geom.buffer(1, 8)
         | 
| 42 | 
            -
                  rescue => e
         | 
| 42 | 
            +
                  rescue StandardError => e
         | 
| 43 43 | 
             
                    # no-op
         | 
| 44 44 | 
             
                  ensure
         | 
| 45 45 | 
             
                    assert_match(/^InterruptedException/, e.message)
         | 
| @@ -62,7 +62,7 @@ class InterruptTests < Minitest::Test | |
| 62 62 |  | 
| 63 63 | 
             
                  begin
         | 
| 64 64 | 
             
                    buffer = geom.buffer(1, 8)
         | 
| 65 | 
            -
                  rescue => e
         | 
| 65 | 
            +
                  rescue StandardError => e
         | 
| 66 66 | 
             
                    # no-op
         | 
| 67 67 | 
             
                  ensure
         | 
| 68 68 | 
             
                    assert_match(/^InterruptedException/, e.message)
         | 
| @@ -87,7 +87,7 @@ class InterruptTests < Minitest::Test | |
| 87 87 |  | 
| 88 88 | 
             
                  begin
         | 
| 89 89 | 
             
                    buffer = geom.buffer(1, 8)
         | 
| 90 | 
            -
                  rescue => e
         | 
| 90 | 
            +
                  rescue StandardError => e
         | 
| 91 91 | 
             
                    # no-op
         | 
| 92 92 | 
             
                  ensure
         | 
| 93 93 | 
             
                    assert_match(/^InterruptedException/, e.message)
         | 
| @@ -114,7 +114,7 @@ class InterruptTests < Minitest::Test | |
| 114 114 | 
             
                  prc_1 = proc {
         | 
| 115 115 | 
             
                    interrupt_called
         | 
| 116 116 | 
             
                    called << :prc_1
         | 
| 117 | 
            -
                    prev | 
| 117 | 
            +
                    prev&.call
         | 
| 118 118 | 
             
                  }
         | 
| 119 119 |  | 
| 120 120 | 
             
                  Geos::Interrupt.register(prc_0)
         | 
| @@ -122,13 +122,13 @@ class InterruptTests < Minitest::Test | |
| 122 122 |  | 
| 123 123 | 
             
                  begin
         | 
| 124 124 | 
             
                    buffer = geom.buffer(1, 8)
         | 
| 125 | 
            -
                  rescue => e
         | 
| 125 | 
            +
                  rescue StandardError => e
         | 
| 126 126 | 
             
                    # no-op
         | 
| 127 127 | 
             
                  ensure
         | 
| 128 128 | 
             
                    assert_match(/^InterruptedException/, e.message)
         | 
| 129 129 | 
             
                    assert_nil(buffer)
         | 
| 130 130 | 
             
                    assert_interrupt_called(1)
         | 
| 131 | 
            -
                    assert_equal([ | 
| 131 | 
            +
                    assert_equal([:prc_1, :prc_0], called)
         | 
| 132 132 | 
             
                  end
         | 
| 133 133 | 
             
                end
         | 
| 134 134 | 
             
              end
         | 
| @@ -160,7 +160,7 @@ class InterruptTests < Minitest::Test | |
| 160 160 |  | 
| 161 161 | 
             
                begin
         | 
| 162 162 | 
             
                  buffer = geom.buffer(1, 8)
         | 
| 163 | 
            -
                rescue => e
         | 
| 163 | 
            +
                rescue StandardError => e
         | 
| 164 164 | 
             
                  assert_match(/^InterruptedException/, e.message)
         | 
| 165 165 | 
             
                  assert_nil(buffer)
         | 
| 166 166 | 
             
                end
         | 
    
        data/test/line_string_tests.rb
    CHANGED
    
    | @@ -80,7 +80,11 @@ class LineStringTests < Minitest::Test | |
| 80 80 | 
             
                # straight right
         | 
| 81 81 | 
             
                simple_tester(
         | 
| 82 82 | 
             
                  :offset_curve,
         | 
| 83 | 
            -
                   | 
| 83 | 
            +
                  if Geos::GEOS_NICE_VERSION >= '031100'
         | 
| 84 | 
            +
                    'LINESTRING (0 -2, 10 -2)'
         | 
| 85 | 
            +
                  else
         | 
| 86 | 
            +
                    'LINESTRING (10 -2, 0 -2)'
         | 
| 87 | 
            +
                  end,
         | 
| 84 88 | 
             
                  'LINESTRING (0 0, 10 0)',
         | 
| 85 89 | 
             
                  -2,
         | 
| 86 90 | 
             
                  quad_segs: 0,
         | 
| @@ -91,7 +95,11 @@ class LineStringTests < Minitest::Test | |
| 91 95 | 
             
                # outside curve
         | 
| 92 96 | 
             
                simple_tester(
         | 
| 93 97 | 
             
                  :offset_curve,
         | 
| 94 | 
            -
                   | 
| 98 | 
            +
                  if Geos::GEOS_NICE_VERSION >= '031100'
         | 
| 99 | 
            +
                    'LINESTRING (0 -2, 10 -2, 12 0, 12 10)'
         | 
| 100 | 
            +
                  else
         | 
| 101 | 
            +
                    'LINESTRING (12 10, 12 0, 10 -2, 0 -2)'
         | 
| 102 | 
            +
                  end,
         | 
| 95 103 | 
             
                  'LINESTRING (0 0, 10 0, 10 10)',
         | 
| 96 104 | 
             
                  -2,
         | 
| 97 105 | 
             
                  quad_segs: 1,
         | 
| @@ -250,8 +258,8 @@ class LineStringTests < Minitest::Test | |
| 250 258 |  | 
| 251 259 | 
             
                wkt = 'LINESTRING (0 0, 10 10)'
         | 
| 252 260 |  | 
| 253 | 
            -
                affine_tester(:rotate, 'LINESTRING (30 10, 20 20)', wkt, Math::PI / 2, [ | 
| 254 | 
            -
                affine_tester(:rotate, 'LINESTRING (-3 1, 7 -9)', wkt, -Math::PI / 2, [ | 
| 261 | 
            +
                affine_tester(:rotate, 'LINESTRING (30 10, 20 20)', wkt, Math::PI / 2, [10.0, 20.0])
         | 
| 262 | 
            +
                affine_tester(:rotate, 'LINESTRING (-3 1, 7 -9)', wkt, -Math::PI / 2, [-1.0, 2.0])
         | 
| 255 263 | 
             
                affine_tester(:rotate, 'LINESTRING (2 2, -8 -8)', wkt, Math::PI, read('POINT(1 1)'))
         | 
| 256 264 | 
             
                affine_tester(:rotate, 'LINESTRING (0.5 -0.5, -9.5 9.5)', wkt, Math::PI / 2, read('LINESTRING(0 0, 1 0)'))
         | 
| 257 265 | 
             
              end
         | 
| @@ -264,7 +272,7 @@ class LineStringTests < Minitest::Test | |
| 264 272 |  | 
| 265 273 | 
             
                affine_tester(:rotate_x, 'LINESTRING Z (1 -1 -1, 10 -10 -10)', wkt, Math::PI)
         | 
| 266 274 | 
             
                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)
         | 
| 275 | 
            +
                affine_tester(:rotate_x, 'LINESTRING Z (1 1 -1, 10 10 -10)', wkt, Math::PI + (Math::PI / 2))
         | 
| 268 276 | 
             
                affine_tester(:rotate_x, wkt, wkt, Math::PI * 2)
         | 
| 269 277 | 
             
              end
         | 
| 270 278 |  | 
| @@ -276,7 +284,7 @@ class LineStringTests < Minitest::Test | |
| 276 284 |  | 
| 277 285 | 
             
                affine_tester(:rotate_y, 'LINESTRING Z (-1 1 -1, -10 10 -10)', wkt, Math::PI)
         | 
| 278 286 | 
             
                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)
         | 
| 287 | 
            +
                affine_tester(:rotate_y, 'LINESTRING Z (-1 1 1, -10 10 10)', wkt, Math::PI + (Math::PI / 2))
         | 
| 280 288 | 
             
                affine_tester(:rotate_y, wkt, wkt, Math::PI * 2)
         | 
| 281 289 | 
             
              end
         | 
| 282 290 |  | 
| @@ -287,7 +295,7 @@ class LineStringTests < Minitest::Test | |
| 287 295 |  | 
| 288 296 | 
             
                affine_tester(:rotate_z, 'LINESTRING (-1 -1, -10 -10)', wkt, Math::PI)
         | 
| 289 297 | 
             
                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)
         | 
| 298 | 
            +
                affine_tester(:rotate_z, 'LINESTRING (1 -1, 10 -10)', wkt, Math::PI + (Math::PI / 2))
         | 
| 291 299 | 
             
                affine_tester(:rotate_z, wkt, wkt, Math::PI * 2)
         | 
| 292 300 | 
             
              end
         | 
| 293 301 |  | 
| @@ -300,11 +308,11 @@ class LineStringTests < Minitest::Test | |
| 300 308 | 
             
              end
         | 
| 301 309 |  | 
| 302 310 | 
             
              def test_scale_hash
         | 
| 303 | 
            -
                affine_tester(:scale, 'LINESTRING (5 5, 50 50)', 'LINESTRING (1 1, 10 10)', : | 
| 304 | 
            -
                affine_tester(:scale, 'LINESTRING (3 2, 30 20)', 'LINESTRING (1 1, 10 10)', : | 
| 311 | 
            +
                affine_tester(:scale, 'LINESTRING (5 5, 50 50)', 'LINESTRING (1 1, 10 10)', x: 5, y: 5)
         | 
| 312 | 
            +
                affine_tester(:scale, 'LINESTRING (3 2, 30 20)', 'LINESTRING (1 1, 10 10)', x: 3, y: 2)
         | 
| 305 313 |  | 
| 306 314 | 
             
                writer.output_dimensions = 3
         | 
| 307 | 
            -
                affine_tester(:scale, 'LINESTRING Z (40 40 40, 80 80 80)', 'LINESTRING Z (10 20 -5, 20 40 -10)', : | 
| 315 | 
            +
                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 316 | 
             
              end
         | 
| 309 317 |  | 
| 310 318 | 
             
              def test_trans_scale
         | 
| @@ -326,11 +334,11 @@ class LineStringTests < Minitest::Test | |
| 326 334 | 
             
              end
         | 
| 327 335 |  | 
| 328 336 | 
             
              def test_trans_scale_hash
         | 
| 329 | 
            -
                affine_tester(:trans_scale, 'LINESTRING (2 2, 11 11)', 'LINESTRING (1 1, 10 10)', : | 
| 337 | 
            +
                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 338 |  | 
| 331 339 | 
             
                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)', : | 
| 333 | 
            -
                affine_tester(:trans_scale, 'LINESTRING Z (3 1 1, 12 10 10)', 'LINESTRING Z (1 1 1, 10 10 10)', : | 
| 340 | 
            +
                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)
         | 
| 341 | 
            +
                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 342 | 
             
              end
         | 
| 335 343 |  | 
| 336 344 | 
             
              def test_translate
         | 
| @@ -341,10 +349,10 @@ class LineStringTests < Minitest::Test | |
| 341 349 | 
             
              end
         | 
| 342 350 |  | 
| 343 351 | 
             
              def test_translate_hash
         | 
| 344 | 
            -
                affine_tester(:translate, 'LINESTRING (5 12, 15 22)', 'LINESTRING (0 0, 10 10)', : | 
| 352 | 
            +
                affine_tester(:translate, 'LINESTRING (5 12, 15 22)', 'LINESTRING (0 0, 10 10)', x: 5, y: 12)
         | 
| 345 353 |  | 
| 346 354 | 
             
                writer.output_dimensions = 3
         | 
| 347 | 
            -
                affine_tester(:translate, 'LINESTRING Z (-3 -7 3, 7 3 13)', 'LINESTRING Z (0 0 0, 10 10 10)', : | 
| 355 | 
            +
                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 356 | 
             
              end
         | 
| 349 357 |  | 
| 350 358 | 
             
              def test_line_interpolate_point
         | 
    
        data/test/point_tests.rb
    CHANGED
    
    | @@ -163,8 +163,8 @@ class PointTests < Minitest::Test | |
| 163 163 |  | 
| 164 164 | 
             
                wkt = 'POINT (1 1)'
         | 
| 165 165 |  | 
| 166 | 
            -
                affine_tester(:rotate, 'POINT (29 11)', wkt, Math::PI / 2, [ | 
| 167 | 
            -
                affine_tester(:rotate, 'POINT (-2 0)', wkt, -Math::PI / 2, [ | 
| 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 168 | 
             
                affine_tester(:rotate, 'POINT (19 1)', wkt, Math::PI / 2, read('POINT(10 10)'))
         | 
| 169 169 | 
             
                affine_tester(:rotate, 'POINT (-0.5 0.5)', wkt, Math::PI / 2, read('LINESTRING(0 0, 1 0)'))
         | 
| 170 170 | 
             
              end
         | 
| @@ -177,7 +177,7 @@ class PointTests < Minitest::Test | |
| 177 177 |  | 
| 178 178 | 
             
                affine_tester(:rotate_x, 'POINT Z (1 -1 -1)', wkt, Math::PI)
         | 
| 179 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)
         | 
| 180 | 
            +
                affine_tester(:rotate_x, 'POINT Z (1 1 -1)', wkt, Math::PI + (Math::PI / 2))
         | 
| 181 181 | 
             
                affine_tester(:rotate_x, wkt, wkt, Math::PI * 2)
         | 
| 182 182 | 
             
              end
         | 
| 183 183 |  | 
| @@ -189,7 +189,7 @@ class PointTests < Minitest::Test | |
| 189 189 |  | 
| 190 190 | 
             
                affine_tester(:rotate_y, 'POINT Z (-1 1 -1)', wkt, Math::PI)
         | 
| 191 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)
         | 
| 192 | 
            +
                affine_tester(:rotate_y, 'POINT Z (-1 1 1)', wkt, Math::PI + (Math::PI / 2))
         | 
| 193 193 | 
             
                affine_tester(:rotate_y, wkt, wkt, Math::PI * 2)
         | 
| 194 194 | 
             
              end
         | 
| 195 195 |  | 
| @@ -200,7 +200,7 @@ class PointTests < Minitest::Test | |
| 200 200 |  | 
| 201 201 | 
             
                affine_tester(:rotate_z, 'POINT (-1 -1)', wkt, Math::PI)
         | 
| 202 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)
         | 
| 203 | 
            +
                affine_tester(:rotate_z, 'POINT (1 -1)', wkt, Math::PI + (Math::PI / 2))
         | 
| 204 204 | 
             
                affine_tester(:rotate_z, wkt, wkt, Math::PI * 2)
         | 
| 205 205 | 
             
              end
         | 
| 206 206 |  | 
    
        data/test/polygon_tests.rb
    CHANGED
    
    | @@ -79,8 +79,7 @@ class PolygonTests < Minitest::Test | |
| 79 79 |  | 
| 80 80 | 
             
              def test_snap_to_grid_with_illegal_result
         | 
| 81 81 | 
             
                assert_raises(Geos::InvalidGeometryError) do
         | 
| 82 | 
            -
                  read('POLYGON ((1 1, 10 10, 10 10, 1 1))').
         | 
| 83 | 
            -
                    snap_to_grid
         | 
| 82 | 
            +
                  read('POLYGON ((1 1, 10 10, 10 10, 1 1))').snap_to_grid
         | 
| 84 83 | 
             
                end
         | 
| 85 84 | 
             
              end
         | 
| 86 85 |  | 
| @@ -110,13 +109,13 @@ class PolygonTests < Minitest::Test | |
| 110 109 | 
             
                  'POLYGON ((30 10, 30 15, 25 15, 25 10, 30 10))',
         | 
| 111 110 | 
             
                  wkt,
         | 
| 112 111 | 
             
                  Math::PI / 2,
         | 
| 113 | 
            -
                  [ | 
| 112 | 
            +
                  [10.0, 20.0])
         | 
| 114 113 |  | 
| 115 114 | 
             
                affine_tester(:rotate,
         | 
| 116 115 | 
             
                  'POLYGON ((-3 1, -3 -4, 2 -4, 2 1, -3 1))',
         | 
| 117 116 | 
             
                  wkt,
         | 
| 118 117 | 
             
                  -Math::PI / 2,
         | 
| 119 | 
            -
                  [ | 
| 118 | 
            +
                  [-1.0, 2.0])
         | 
| 120 119 |  | 
| 121 120 | 
             
                affine_tester(:rotate,
         | 
| 122 121 | 
             
                  'POLYGON ((2 2, -3 2, -3 -3, 2 -3, 2 2))',
         | 
| @@ -148,7 +147,7 @@ class PolygonTests < Minitest::Test | |
| 148 147 | 
             
                affine_tester(:rotate_x,
         | 
| 149 148 | 
             
                  'POLYGON Z ((0 0 0, 5 0 0, 5 0 -5, 0 0 -5, 0 0 0))',
         | 
| 150 149 | 
             
                  wkt,
         | 
| 151 | 
            -
                  Math::PI + Math::PI / 2)
         | 
| 150 | 
            +
                  Math::PI + (Math::PI / 2))
         | 
| 152 151 |  | 
| 153 152 | 
             
                affine_tester(:rotate_x,
         | 
| 154 153 | 
             
                  wkt,
         | 
| @@ -174,7 +173,7 @@ class PolygonTests < Minitest::Test | |
| 174 173 | 
             
                affine_tester(:rotate_y,
         | 
| 175 174 | 
             
                  'POLYGON Z ((0 0 0, 0 0 5, 0 5 5, 0 5 0, 0 0 0))',
         | 
| 176 175 | 
             
                  wkt,
         | 
| 177 | 
            -
                  Math::PI + Math::PI / 2)
         | 
| 176 | 
            +
                  Math::PI + (Math::PI / 2))
         | 
| 178 177 |  | 
| 179 178 | 
             
                affine_tester(:rotate_y,
         | 
| 180 179 | 
             
                  wkt,
         | 
| @@ -196,7 +195,7 @@ class PolygonTests < Minitest::Test | |
| 196 195 | 
             
                affine_tester(:rotate_z,
         | 
| 197 196 | 
             
                  'POLYGON ((0 0, 0 -5, 5 -5, 5 0, 0 0))',
         | 
| 198 197 | 
             
                  'POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))',
         | 
| 199 | 
            -
                  Math::PI + Math::PI / 2)
         | 
| 198 | 
            +
                  Math::PI + (Math::PI / 2))
         | 
| 200 199 |  | 
| 201 200 | 
             
                affine_tester(:rotate_z,
         | 
| 202 201 | 
             
                  'POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))',
         | 
| @@ -17,14 +17,14 @@ class PreparedGeometryTests < Minitest::Test | |
| 17 17 |  | 
| 18 18 | 
             
              def relationship_tester(method, *expected)
         | 
| 19 19 | 
             
                [
         | 
| 20 | 
            -
                  [ | 
| 21 | 
            -
                  [ | 
| 22 | 
            -
                  [ | 
| 23 | 
            -
                  [ | 
| 24 | 
            -
                  [ | 
| 25 | 
            -
                  [ | 
| 26 | 
            -
                  [ | 
| 27 | 
            -
                  [ | 
| 20 | 
            +
                  [POINT_A, POINT_A],
         | 
| 21 | 
            +
                  [POINT_A, LINESTRING_A],
         | 
| 22 | 
            +
                  [POINT_B, LINESTRING_A],
         | 
| 23 | 
            +
                  [LINESTRING_B, LINESTRING_A],
         | 
| 24 | 
            +
                  [LINESTRING_C, LINESTRING_A],
         | 
| 25 | 
            +
                  [LINESTRING_D, LINESTRING_A],
         | 
| 26 | 
            +
                  [POLYGON_A, POLYGON_B],
         | 
| 27 | 
            +
                  [POLYGON_A, POINT_C]
         | 
| 28 28 | 
             
                ].each_with_index do |(geom_a, geom_b), i|
         | 
| 29 29 | 
             
                  geom_a = read(geom_a).to_prepared
         | 
| 30 30 | 
             
                  geom_b = read(geom_b)
         | 
    
        data/test/strtree_tests.rb
    CHANGED
    
    | @@ -8,7 +8,7 @@ class STRtreeTests < Minitest::Test | |
| 8 8 | 
             
              def setup_tree
         | 
| 9 9 | 
             
                @tree = Geos::STRtree.new(3)
         | 
| 10 10 | 
             
                @item_1 = { item_1: :test }
         | 
| 11 | 
            -
                @item_2 = [ | 
| 11 | 
            +
                @item_2 = [:test]
         | 
| 12 12 | 
             
                @item_3 = Object.new
         | 
| 13 13 |  | 
| 14 14 | 
             
                @geom_1 = read('LINESTRING(0 0, 10 10)')
         | 
| @@ -183,9 +183,9 @@ class STRtreeTests < Minitest::Test | |
| 183 183 | 
             
                skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree)
         | 
| 184 184 |  | 
| 185 185 | 
             
                tree = Geos::STRtree.new(
         | 
| 186 | 
            -
                  [ | 
| 187 | 
            -
                  [ | 
| 188 | 
            -
                  [ | 
| 186 | 
            +
                  [read('LINESTRING(0 0, 10 10)'), item_1 = { item_1: :test }],
         | 
| 187 | 
            +
                  [read('LINESTRING(20 20, 30 30)'), item_2 = [:test]],
         | 
| 188 | 
            +
                  [read('LINESTRING(20 20, 30 30)'), item_3 = Object.new]
         | 
| 189 189 | 
             
                )
         | 
| 190 190 |  | 
| 191 191 | 
             
                assert_equal([item_1],
         | 
| @@ -233,7 +233,7 @@ class STRtreeTests < Minitest::Test | |
| 233 233 | 
             
              end
         | 
| 234 234 |  | 
| 235 235 | 
             
              def test_nearest
         | 
| 236 | 
            -
                skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest)
         | 
| 236 | 
            +
                skip unless ENV['FORCE_TESTS'] || (defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest))
         | 
| 237 237 |  | 
| 238 238 | 
             
                geom_1 = read('POINT (3 3)')
         | 
| 239 239 | 
             
                geom_2 = read('POINT (2 7)')
         | 
| @@ -250,7 +250,7 @@ class STRtreeTests < Minitest::Test | |
| 250 250 | 
             
              end
         | 
| 251 251 |  | 
| 252 252 | 
             
              def test_nearest_with_depth
         | 
| 253 | 
            -
                skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest)
         | 
| 253 | 
            +
                skip unless ENV['FORCE_TESTS'] || (defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest))
         | 
| 254 254 |  | 
| 255 255 | 
             
                number_of_geoms = 100
         | 
| 256 256 | 
             
                geoms = []
         | 
| @@ -284,7 +284,7 @@ class STRtreeTests < Minitest::Test | |
| 284 284 | 
             
              end
         | 
| 285 285 |  | 
| 286 286 | 
             
              def test_nearest_with_empty_tree
         | 
| 287 | 
            -
                skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest)
         | 
| 287 | 
            +
                skip unless ENV['FORCE_TESTS'] || (defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest))
         | 
| 288 288 |  | 
| 289 289 | 
             
                tree = Geos::STRtree.new(10)
         | 
| 290 290 | 
             
                geom_1 = read('POINT (3 3)')
         | 
| @@ -294,7 +294,7 @@ class STRtreeTests < Minitest::Test | |
| 294 294 | 
             
              end
         | 
| 295 295 |  | 
| 296 296 | 
             
              def test_nearest_with_some_empty_geometries
         | 
| 297 | 
            -
                skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest)
         | 
| 297 | 
            +
                skip unless ENV['FORCE_TESTS'] || (defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest))
         | 
| 298 298 |  | 
| 299 299 | 
             
                geom_1 = read('LINESTRING EMPTY')
         | 
| 300 300 | 
             
                geom_2 = read('POINT (2 7)')
         | 
| @@ -312,7 +312,8 @@ class STRtreeTests < Minitest::Test | |
| 312 312 | 
             
              end
         | 
| 313 313 |  | 
| 314 314 | 
             
              def test_nearest_with_only_empty_geometries
         | 
| 315 | 
            -
                skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest)
         | 
| 315 | 
            +
                skip unless ENV['FORCE_TESTS'] || (defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest))
         | 
| 316 | 
            +
                skip if Geos::GEOS_NICE_VERSION > '030900'
         | 
| 316 317 |  | 
| 317 318 | 
             
                geom_1 = read('LINESTRING EMPTY')
         | 
| 318 319 | 
             
                geom_2 = read('POINT (2 7)')
         | 
| @@ -326,7 +327,7 @@ class STRtreeTests < Minitest::Test | |
| 326 327 | 
             
              end
         | 
| 327 328 |  | 
| 328 329 | 
             
              def test_disallowed_inserts_on_nearest
         | 
| 329 | 
            -
                skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest)
         | 
| 330 | 
            +
                skip unless ENV['FORCE_TESTS'] || (defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest))
         | 
| 330 331 |  | 
| 331 332 | 
             
                setup_tree
         | 
| 332 333 |  | 
| @@ -338,7 +339,7 @@ class STRtreeTests < Minitest::Test | |
| 338 339 | 
             
              end
         | 
| 339 340 |  | 
| 340 341 | 
             
              def test_nearest_item
         | 
| 341 | 
            -
                skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest_item)
         | 
| 342 | 
            +
                skip unless ENV['FORCE_TESTS'] || (defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest_item))
         | 
| 342 343 |  | 
| 343 344 | 
             
                geom_1 = read('POINT (3 3)')
         | 
| 344 345 | 
             
                geom_2 = read('POINT (2 7)')
         | 
| @@ -346,7 +347,7 @@ class STRtreeTests < Minitest::Test | |
| 346 347 | 
             
                geom_4 = read('POINT (3 8)')
         | 
| 347 348 |  | 
| 348 349 | 
             
                item_1 = { item_1: :test }
         | 
| 349 | 
            -
                item_2 = [ | 
| 350 | 
            +
                item_2 = [:test]
         | 
| 350 351 | 
             
                item_3 = Object.new
         | 
| 351 352 |  | 
| 352 353 | 
             
                tree = Geos::STRtree.new(2)
         | 
    
        data/test/test_helper.rb
    CHANGED
    
    | @@ -1,19 +1,17 @@ | |
| 1 | 
            -
            #  | 
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
              require 'simplecov'
         | 
| 3 | 
            +
            require 'simplecov'
         | 
| 5 4 |  | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
              end
         | 
| 5 | 
            +
            SimpleCov.command_name('Unit Tests')
         | 
| 6 | 
            +
            SimpleCov.merge_timeout(3600)
         | 
| 7 | 
            +
            SimpleCov.start do
         | 
| 8 | 
            +
              add_filter '/test/'
         | 
| 9 | 
            +
              add_filter '/.bundle/'
         | 
| 12 10 | 
             
            end
         | 
| 13 11 |  | 
| 14 12 | 
             
            require 'rubygems'
         | 
| 15 13 | 
             
            require 'minitest/autorun'
         | 
| 16 | 
            -
            require 'minitest/reporters' | 
| 14 | 
            +
            require 'minitest/reporters'
         | 
| 17 15 |  | 
| 18 16 | 
             
            if ENV['USE_BINARY_GEOS']
         | 
| 19 17 | 
             
              require 'geos'
         | 
| @@ -25,17 +23,28 @@ puts "Ruby version #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} - #{RbConfig::CONFIG['RUB | |
| 25 23 | 
             
            puts "ffi version #{Gem.loaded_specs['ffi'].version}" if Gem.loaded_specs['ffi']
         | 
| 26 24 |  | 
| 27 25 | 
             
            if Geos.respond_to?(:version)
         | 
| 28 | 
            -
              puts "GEOS version #{Geos.version}"
         | 
| 26 | 
            +
              puts "GEOS version #{Geos.version} (#{Geos::GEOS_NICE_VERSION})"
         | 
| 29 27 | 
             
            else
         | 
| 30 | 
            -
              puts "GEOS version #{Geos::GEOS_VERSION}"
         | 
| 28 | 
            +
              puts "GEOS version #{Geos::GEOS_VERSION} (#{Geos::GEOS_NICE_VERSION})"
         | 
| 31 29 | 
             
            end
         | 
| 32 30 |  | 
| 33 31 | 
             
            puts "ffi-geos version #{Geos::VERSION}" if defined?(Geos::VERSION)
         | 
| 34 32 | 
             
            puts "Using #{Geos::FFIGeos.geos_library_path}" if defined?(Geos::FFIGeos)
         | 
| 33 | 
            +
            puts "Process #{$PID}"
         | 
| 35 34 |  | 
| 36 35 | 
             
            module TestHelper
         | 
| 37 36 | 
             
              TOLERANCE = 0.0000000000001
         | 
| 38 37 |  | 
| 38 | 
            +
              EMPTY_GEOMETRY = if Geos::GEOS_NICE_VERSION >= '030800'
         | 
| 39 | 
            +
                'POINT EMPTY'
         | 
| 40 | 
            +
              else
         | 
| 41 | 
            +
                'GEOMETRYCOLLECTION EMPTY'
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              EMPTY_BLOCK = proc do
         | 
| 45 | 
            +
                # no-op
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 39 48 | 
             
              def self.included(base)
         | 
| 40 49 | 
             
                base.class_eval do
         | 
| 41 50 | 
             
                  attr_reader :reader, :reader_hex, :writer
         | 
| @@ -49,16 +58,16 @@ module TestHelper | |
| 49 58 | 
             
                @writer = Geos::WktWriter.new
         | 
| 50 59 | 
             
              end
         | 
| 51 60 |  | 
| 52 | 
            -
              def read(*args)
         | 
| 53 | 
            -
                if args[0][0]  | 
| 54 | 
            -
                   | 
| 61 | 
            +
              def read(*args, **options)
         | 
| 62 | 
            +
                if args[0][0] == '0'
         | 
| 63 | 
            +
                  reader_hex.read_hex(*args, **options)
         | 
| 55 64 | 
             
                else
         | 
| 56 | 
            -
                   | 
| 65 | 
            +
                  reader.read(*args, **options)
         | 
| 57 66 | 
             
                end
         | 
| 58 67 | 
             
              end
         | 
| 59 68 |  | 
| 60 | 
            -
              def write(*args)
         | 
| 61 | 
            -
                writer.write(*args)
         | 
| 69 | 
            +
              def write(*args, **options)
         | 
| 70 | 
            +
                writer.write(*args, **options)
         | 
| 62 71 | 
             
              end
         | 
| 63 72 |  | 
| 64 73 | 
             
              def geom_from_geom_or_wkt(geom_or_wkt)
         | 
| @@ -69,11 +78,12 @@ module TestHelper | |
| 69 78 | 
             
                end
         | 
| 70 79 | 
             
              end
         | 
| 71 80 |  | 
| 72 | 
            -
              def srid_copy_tester(method, expected, expected_srid, srid_policy, wkt, *args)
         | 
| 81 | 
            +
              def srid_copy_tester(method, expected, expected_srid, srid_policy, wkt, *args, **options)
         | 
| 73 82 | 
             
                geom = read(wkt)
         | 
| 74 83 | 
             
                geom.srid = 4326
         | 
| 75 84 | 
             
                Geos.srid_copy_policy = srid_policy
         | 
| 76 | 
            -
             | 
| 85 | 
            +
             | 
| 86 | 
            +
                geom_b = geom.__safe_send__(method, *args, **options)
         | 
| 77 87 | 
             
                assert_equal(4326, geom.srid)
         | 
| 78 88 | 
             
                assert_equal(expected_srid, geom_b.srid)
         | 
| 79 89 | 
             
                assert_equal(expected, write(geom_b))
         | 
| @@ -104,90 +114,98 @@ module TestHelper | |
| 104 114 | 
             
                assert(geom.eql_exact?(result, tolerance), "Expected geom.eql_exact? to be within #{tolerance}")
         | 
| 105 115 | 
             
              end
         | 
| 106 116 |  | 
| 107 | 
            -
              def snapped_tester(method, expected, geom, *args)
         | 
| 117 | 
            +
              def snapped_tester(method, expected, geom, *args, **options)
         | 
| 108 118 | 
             
                geom = geom_from_geom_or_wkt(geom)
         | 
| 109 119 |  | 
| 110 | 
            -
                result = geom. | 
| 120 | 
            +
                result = geom.__safe_send__(method, *args, **options)
         | 
| 111 121 | 
             
                assert_equal(expected, write(result.snap_to_grid(1)))
         | 
| 112 122 | 
             
              end
         | 
| 113 123 |  | 
| 114 | 
            -
              def simple_tester(method, expected, geom, *args)
         | 
| 124 | 
            +
              def simple_tester(method, expected, geom, *args, **options)
         | 
| 115 125 | 
             
                geom = geom_from_geom_or_wkt(geom)
         | 
| 116 | 
            -
             | 
| 126 | 
            +
             | 
| 127 | 
            +
                result = geom.__safe_send__(method, *args, **options)
         | 
| 117 128 | 
             
                result = write(result) if result.is_a?(Geos::Geometry)
         | 
| 118 129 |  | 
| 119 | 
            -
                 | 
| 130 | 
            +
                if expected.nil?
         | 
| 131 | 
            +
                  assert_nil(result)
         | 
| 132 | 
            +
                else
         | 
| 133 | 
            +
                  assert_equal(expected, result)
         | 
| 134 | 
            +
                end
         | 
| 120 135 | 
             
              end
         | 
| 121 136 |  | 
| 122 | 
            -
              def simple_bang_tester(method, expected, wkt, *args)
         | 
| 137 | 
            +
              def simple_bang_tester(method, expected, wkt, *args, **options)
         | 
| 123 138 | 
             
                geom = read(wkt)
         | 
| 124 | 
            -
                result = geom. | 
| 139 | 
            +
                result = geom.__safe_send__(method, *args, **options)
         | 
| 125 140 |  | 
| 126 141 | 
             
                assert_equal(wkt, write(geom))
         | 
| 127 142 | 
             
                assert_equal(expected, write(result))
         | 
| 128 143 |  | 
| 129 144 | 
             
                geom = read(wkt)
         | 
| 130 | 
            -
                geom. | 
| 145 | 
            +
                geom.__safe_send__("#{method}!", *args, **options)
         | 
| 131 146 |  | 
| 132 147 | 
             
                assert_equal(expected, write(geom))
         | 
| 133 148 | 
             
              end
         | 
| 134 149 |  | 
| 135 | 
            -
              def comparison_tester(method, expected, geom_a, geom_b, *args)
         | 
| 136 | 
            -
                geom_a = geom_from_geom_or_wkt(geom_a)
         | 
| 137 | 
            -
                geom_b = geom_from_geom_or_wkt(geom_b)
         | 
| 150 | 
            +
              def comparison_tester(method, expected, geom_a, geom_b, *args, **options)
         | 
| 151 | 
            +
                geom_a = geom_from_geom_or_wkt(geom_a).normalize
         | 
| 152 | 
            +
                geom_b = geom_from_geom_or_wkt(geom_b).normalize
         | 
| 138 153 |  | 
| 139 | 
            -
                simple_tester(method, expected, geom_a, geom_b, *args)
         | 
| 154 | 
            +
                simple_tester(method, expected, geom_a, geom_b, *args, **options)
         | 
| 140 155 | 
             
              end
         | 
| 141 156 |  | 
| 142 | 
            -
              def array_tester(method, expected, geom, *args)
         | 
| 157 | 
            +
              def array_tester(method, expected, geom, *args, **options)
         | 
| 143 158 | 
             
                geom = geom_from_geom_or_wkt(geom)
         | 
| 144 | 
            -
                result = geom. | 
| 159 | 
            +
                result = geom.__safe_send__(method, *args, **options)
         | 
| 145 160 |  | 
| 146 161 | 
             
                case result
         | 
| 147 162 | 
             
                  when Geos::Geometry
         | 
| 148 | 
            -
                    result = [ | 
| 163 | 
            +
                    result = [write(result)]
         | 
| 149 164 | 
             
                  when Array
         | 
| 150 | 
            -
                    result = result.collect  | 
| 165 | 
            +
                    result = result.collect do |r|
         | 
| 151 166 | 
             
                      write(r)
         | 
| 152 | 
            -
                     | 
| 167 | 
            +
                    end
         | 
| 153 168 | 
             
                end
         | 
| 154 169 |  | 
| 155 170 | 
             
                assert_equal(expected, result)
         | 
| 156 171 | 
             
              end
         | 
| 157 172 |  | 
| 158 | 
            -
              def affine_tester(method, expected, wkt, *args)
         | 
| 173 | 
            +
              def affine_tester(method, expected, wkt, *args, **options)
         | 
| 159 174 | 
             
                writer.trim = true
         | 
| 160 175 |  | 
| 161 176 | 
             
                geom = read(wkt)
         | 
| 162 | 
            -
                geom. | 
| 177 | 
            +
                geom.__safe_send__("#{method}!", *args, **options).snap_to_grid!(0.1)
         | 
| 163 178 |  | 
| 164 179 | 
             
                assert_equal(expected, write(geom))
         | 
| 165 180 |  | 
| 166 181 | 
             
                geom = read(wkt)
         | 
| 167 | 
            -
                 | 
| 182 | 
            +
                geom_2 = geom.__safe_send__(method, *args, **options).snap_to_grid(0.1)
         | 
| 168 183 |  | 
| 169 184 | 
             
                assert_equal(wkt, write(geom))
         | 
| 170 | 
            -
                assert_equal(expected, write( | 
| 185 | 
            +
                assert_equal(expected, write(geom_2, trim: true))
         | 
| 171 186 | 
             
              end
         | 
| 172 187 | 
             
            end
         | 
| 173 188 |  | 
| 174 | 
            -
             | 
| 175 | 
            -
               | 
| 176 | 
            -
             | 
| 177 | 
            -
             | 
| 178 | 
            -
            if !Fixnum.method_defined?(:negative?)
         | 
| 179 | 
            -
              class Fixnum
         | 
| 180 | 
            -
                def negative?
         | 
| 181 | 
            -
                  self < 0
         | 
| 189 | 
            +
            class Object
         | 
| 190 | 
            +
              if RUBY_VERSION >= '2.7'
         | 
| 191 | 
            +
                def __safe_send__(method_name, *args, **kwargs)
         | 
| 192 | 
            +
                  send(method_name, *args, **kwargs)
         | 
| 182 193 | 
             
                end
         | 
| 183 | 
            -
               | 
| 184 | 
            -
             | 
| 185 | 
            -
             | 
| 186 | 
            -
             | 
| 187 | 
            -
             | 
| 188 | 
            -
             | 
| 189 | 
            -
                   | 
| 194 | 
            +
              else
         | 
| 195 | 
            +
                def __safe_send__(method_name, *args, **kwargs)
         | 
| 196 | 
            +
                  raise NoMethodError unless respond_to?(method_name)
         | 
| 197 | 
            +
             | 
| 198 | 
            +
                  arity = method(method_name).arity
         | 
| 199 | 
            +
             | 
| 200 | 
            +
                  if arity.zero?
         | 
| 201 | 
            +
                    send(method_name)
         | 
| 202 | 
            +
                  elsif arity.negative? && !kwargs.empty?
         | 
| 203 | 
            +
                    send(method_name, *args, **kwargs)
         | 
| 204 | 
            +
                  else
         | 
| 205 | 
            +
                    send(method_name, *args)
         | 
| 206 | 
            +
                  end
         | 
| 190 207 | 
             
                end
         | 
| 191 208 | 
             
              end
         | 
| 192 209 | 
             
            end
         | 
| 193 210 |  | 
| 211 | 
            +
            Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
         |