ffi-geos 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3954 -4
- data/.travis.yml +23 -11
- data/Gemfile +7 -9
- data/Guardfile +3 -4
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -20
- data/Rakefile +3 -2
- data/ffi-geos.gemspec +2 -2
- data/lib/ffi-geos.rb +93 -44
- data/lib/ffi-geos/coordinate_sequence.rb +147 -145
- data/lib/ffi-geos/geometry.rb +68 -17
- data/lib/ffi-geos/geometry_collection.rb +22 -8
- data/lib/ffi-geos/interrupt.rb +11 -14
- data/lib/ffi-geos/line_string.rb +57 -42
- data/lib/ffi-geos/point.rb +16 -16
- data/lib/ffi-geos/polygon.rb +42 -28
- data/lib/ffi-geos/strtree.rb +3 -5
- data/lib/ffi-geos/tools.rb +1 -1
- data/lib/ffi-geos/utils.rb +4 -12
- data/lib/ffi-geos/version.rb +1 -1
- data/lib/ffi-geos/wkb_writer.rb +2 -3
- data/lib/ffi-geos/wkt_writer.rb +4 -7
- data/sonar-project.properties +16 -0
- data/test/coordinate_sequence_tests.rb +144 -122
- data/test/geometry_collection_tests.rb +38 -65
- data/test/geometry_tests.rb +106 -17
- data/test/interrupt_tests.rb +7 -7
- data/test/line_string_tests.rb +10 -10
- data/test/point_tests.rb +2 -2
- data/test/polygon_tests.rb +3 -4
- data/test/prepared_geometry_tests.rb +8 -8
- data/test/strtree_tests.rb +5 -5
- data/test/test_helper.rb +20 -35
- 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 +4 -4
@@ -200,8 +200,8 @@ class GeometryCollectionTests < Minitest::Test
|
|
200
200
|
|
201
201
|
def test_snap_to_grid_with_illegal_result
|
202
202
|
assert_raises(Geos::InvalidGeometryError) do
|
203
|
-
read('GEOMETRYCOLLECTION (POINT (0 2), LINESTRING (0 1, 0 11), POLYGON ((0 1, 0 1, 0 6, 0 6, 0 1)))')
|
204
|
-
snap_to_grid(1)
|
203
|
+
read('GEOMETRYCOLLECTION (POINT (0 2), LINESTRING (0 1, 0 11), POLYGON ((0 1, 0 1, 0 6, 0 6, 0 1)))')
|
204
|
+
.snap_to_grid(1)
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
@@ -214,29 +214,25 @@ class GeometryCollectionTests < Minitest::Test
|
|
214
214
|
'GEOMETRYCOLLECTION (POINT (29 11), LINESTRING (30 10, 20 20), POLYGON ((30 10, 30 15, 25 15, 25 10, 30 10)))',
|
215
215
|
wkt,
|
216
216
|
Math::PI / 2,
|
217
|
-
[
|
218
|
-
)
|
217
|
+
[10.0, 20.0])
|
219
218
|
|
220
219
|
affine_tester(:rotate,
|
221
220
|
'GEOMETRYCOLLECTION (POINT (-2 0), LINESTRING (-3 1, 7 -9), POLYGON ((-3 1, -3 -4, 2 -4, 2 1, -3 1)))',
|
222
221
|
wkt,
|
223
222
|
-Math::PI / 2,
|
224
|
-
[
|
225
|
-
)
|
223
|
+
[-1.0, 2.0])
|
226
224
|
|
227
225
|
affine_tester(:rotate,
|
228
226
|
'GEOMETRYCOLLECTION (POINT (19 1), LINESTRING (20 0, 10 10), POLYGON ((20 0, 20 5, 15 5, 15 0, 20 0)))',
|
229
227
|
wkt,
|
230
228
|
Math::PI / 2,
|
231
|
-
read('POINT(10 10)')
|
232
|
-
)
|
229
|
+
read('POINT(10 10)'))
|
233
230
|
|
234
231
|
affine_tester(:rotate,
|
235
232
|
'GEOMETRYCOLLECTION (POINT (-0.5 0.5), LINESTRING (0.5 -0.5, -9.5 9.5), POLYGON ((0.5 -0.5, 0.5 4.5, -4.5 4.5, -4.5 -0.5, 0.5 -0.5)))',
|
236
233
|
wkt,
|
237
234
|
Math::PI / 2,
|
238
|
-
read('LINESTRING(0 0, 1 0)')
|
239
|
-
)
|
235
|
+
read('LINESTRING(0 0, 1 0)'))
|
240
236
|
end
|
241
237
|
|
242
238
|
def test_rotate_x
|
@@ -248,26 +244,22 @@ class GeometryCollectionTests < Minitest::Test
|
|
248
244
|
affine_tester(:rotate_x,
|
249
245
|
'GEOMETRYCOLLECTION Z (POINT Z (1 -1 -1), LINESTRING Z (1 -1 -1, 10 -10 -10), POLYGON Z ((0 0 0, 5 0 0, 5 -5 0, 0 -5 0, 0 0 0)))',
|
250
246
|
wkt,
|
251
|
-
Math::PI
|
252
|
-
)
|
247
|
+
Math::PI)
|
253
248
|
|
254
249
|
affine_tester(:rotate_x,
|
255
250
|
'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
251
|
wkt,
|
257
|
-
Math::PI / 2
|
258
|
-
)
|
252
|
+
Math::PI / 2)
|
259
253
|
|
260
254
|
affine_tester(:rotate_x,
|
261
255
|
'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)))',
|
262
256
|
wkt,
|
263
|
-
Math::PI + Math::PI / 2
|
264
|
-
)
|
257
|
+
Math::PI + Math::PI / 2)
|
265
258
|
|
266
259
|
affine_tester(:rotate_x,
|
267
260
|
wkt,
|
268
261
|
wkt,
|
269
|
-
Math::PI * 2
|
270
|
-
)
|
262
|
+
Math::PI * 2)
|
271
263
|
end
|
272
264
|
|
273
265
|
def test_rotate_y
|
@@ -279,26 +271,22 @@ class GeometryCollectionTests < Minitest::Test
|
|
279
271
|
affine_tester(:rotate_y,
|
280
272
|
'GEOMETRYCOLLECTION Z (POINT Z (-1 1 -1), LINESTRING Z (-1 1 -1, -10 10 -10), POLYGON Z ((0 0 0, -5 0 0, -5 5 0, 0 5 0, 0 0 0)))',
|
281
273
|
wkt,
|
282
|
-
Math::PI
|
283
|
-
)
|
274
|
+
Math::PI)
|
284
275
|
|
285
276
|
affine_tester(:rotate_y,
|
286
277
|
'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)))',
|
287
278
|
wkt,
|
288
|
-
Math::PI / 2
|
289
|
-
)
|
279
|
+
Math::PI / 2)
|
290
280
|
|
291
281
|
affine_tester(:rotate_y,
|
292
282
|
'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)))',
|
293
283
|
wkt,
|
294
|
-
Math::PI + Math::PI / 2
|
295
|
-
)
|
284
|
+
Math::PI + Math::PI / 2)
|
296
285
|
|
297
286
|
affine_tester(:rotate_y,
|
298
287
|
wkt,
|
299
288
|
wkt,
|
300
|
-
Math::PI * 2
|
301
|
-
)
|
289
|
+
Math::PI * 2)
|
302
290
|
end
|
303
291
|
|
304
292
|
def test_rotate_z
|
@@ -309,26 +297,22 @@ class GeometryCollectionTests < Minitest::Test
|
|
309
297
|
affine_tester(:rotate_z,
|
310
298
|
'GEOMETRYCOLLECTION (POINT (-1 -1), LINESTRING (0 0, -10 -10), POLYGON ((0 0, -5 0, -5 -5, 0 -5, 0 0)))',
|
311
299
|
wkt,
|
312
|
-
Math::PI
|
313
|
-
)
|
300
|
+
Math::PI)
|
314
301
|
|
315
302
|
affine_tester(:rotate_z,
|
316
303
|
'GEOMETRYCOLLECTION (POINT (-1 1), LINESTRING (0 0, -10 10), POLYGON ((0 0, 0 5, -5 5, -5 0, 0 0)))',
|
317
304
|
wkt,
|
318
|
-
Math::PI / 2
|
319
|
-
)
|
305
|
+
Math::PI / 2)
|
320
306
|
|
321
307
|
affine_tester(:rotate_z,
|
322
308
|
'GEOMETRYCOLLECTION (POINT (1 -1), LINESTRING (0 0, 10 -10), POLYGON ((0 0, 0 -5, 5 -5, 5 0, 0 0)))',
|
323
309
|
wkt,
|
324
|
-
Math::PI + Math::PI / 2
|
325
|
-
)
|
310
|
+
Math::PI + Math::PI / 2)
|
326
311
|
|
327
312
|
affine_tester(:rotate_z,
|
328
313
|
wkt,
|
329
314
|
wkt,
|
330
|
-
Math::PI * 2
|
331
|
-
)
|
315
|
+
Math::PI * 2)
|
332
316
|
end
|
333
317
|
|
334
318
|
def test_scale
|
@@ -336,15 +320,13 @@ class GeometryCollectionTests < Minitest::Test
|
|
336
320
|
'GEOMETRYCOLLECTION (POINT (5 5), LINESTRING (0 0, 50 50), POLYGON ((0 0, 25 0, 25 25, 0 25, 0 0)))',
|
337
321
|
'GEOMETRYCOLLECTION (POINT (1 1), LINESTRING (0 0, 10 10), POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0)))',
|
338
322
|
5,
|
339
|
-
5
|
340
|
-
)
|
323
|
+
5)
|
341
324
|
|
342
325
|
affine_tester(:scale,
|
343
326
|
'GEOMETRYCOLLECTION (POINT (3 2), LINESTRING (0 0, 30 20), POLYGON ((0 0, 15 0, 15 10, 0 10, 0 0)))',
|
344
327
|
'GEOMETRYCOLLECTION (POINT (1 1), LINESTRING (0 0, 10 10), POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0)))',
|
345
328
|
3,
|
346
|
-
2
|
347
|
-
)
|
329
|
+
2)
|
348
330
|
|
349
331
|
writer.output_dimensions = 3
|
350
332
|
affine_tester(:scale,
|
@@ -352,33 +334,29 @@ class GeometryCollectionTests < Minitest::Test
|
|
352
334
|
'GEOMETRYCOLLECTION Z (POINT Z (1 1 1), LINESTRING Z (1 1 1, 10 10 10), POLYGON Z ((0 0 0, 5 0 0, 5 5 0, 0 5 0, 0 0 0)))',
|
353
335
|
4,
|
354
336
|
2,
|
355
|
-
-8
|
356
|
-
)
|
337
|
+
-8)
|
357
338
|
end
|
358
339
|
|
359
340
|
def test_scale_hash
|
360
341
|
affine_tester(:scale,
|
361
342
|
'GEOMETRYCOLLECTION (POINT (5 5), LINESTRING (0 0, 50 50), POLYGON ((0 0, 25 0, 25 25, 0 25, 0 0)))',
|
362
343
|
'GEOMETRYCOLLECTION (POINT (1 1), LINESTRING (0 0, 10 10), POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0)))',
|
363
|
-
:
|
364
|
-
:
|
365
|
-
)
|
344
|
+
x: 5,
|
345
|
+
y: 5)
|
366
346
|
|
367
347
|
affine_tester(:scale,
|
368
348
|
'GEOMETRYCOLLECTION (POINT (3 2), LINESTRING (0 0, 30 20), POLYGON ((0 0, 15 0, 15 10, 0 10, 0 0)))',
|
369
349
|
'GEOMETRYCOLLECTION (POINT (1 1), LINESTRING (0 0, 10 10), POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0)))',
|
370
|
-
:
|
371
|
-
:
|
372
|
-
)
|
350
|
+
x: 3,
|
351
|
+
y: 2)
|
373
352
|
|
374
353
|
writer.output_dimensions = 3
|
375
354
|
affine_tester(:scale,
|
376
355
|
'GEOMETRYCOLLECTION Z (POINT Z (4 2 -8), LINESTRING Z (4 2 -8, 40 20 -80), POLYGON Z ((0 0 0, 20 0 0, 20 10 0, 0 10 0, 0 0 0)))',
|
377
356
|
'GEOMETRYCOLLECTION Z (POINT Z (1 1 1), LINESTRING Z (1 1 1, 10 10 10), POLYGON Z ((0 0 0, 5 0 0, 5 5 0, 0 5 0, 0 0 0)))',
|
378
|
-
:
|
379
|
-
:
|
380
|
-
:
|
381
|
-
)
|
357
|
+
x: 4,
|
358
|
+
y: 2,
|
359
|
+
z: -8)
|
382
360
|
end
|
383
361
|
|
384
362
|
def test_trans_scale
|
@@ -445,28 +423,26 @@ class GeometryCollectionTests < Minitest::Test
|
|
445
423
|
affine_tester(:trans_scale,
|
446
424
|
'GEOMETRYCOLLECTION (POINT (2 2), LINESTRING (1 1, 11 11), POLYGON ((1 1, 6 1, 6 6, 1 6, 1 1)))',
|
447
425
|
'GEOMETRYCOLLECTION (POINT (1 1), LINESTRING (0 0, 10 10), POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0)))',
|
448
|
-
:
|
426
|
+
delta_x: 1, delta_y: 1, x_factor: 1, y_factor: 1)
|
449
427
|
|
450
428
|
writer.output_dimensions = 3
|
451
429
|
affine_tester(:trans_scale,
|
452
430
|
'GEOMETRYCOLLECTION Z (POINT Z (15 28 1), LINESTRING Z (15 28 1, 60 91 10), POLYGON Z ((10 21 0, 35 21 0, 35 56 0, 10 56 0, 10 21 0)))',
|
453
431
|
'GEOMETRYCOLLECTION Z (POINT Z (1 1 1), LINESTRING Z (1 1 1, 10 10 10), POLYGON Z ((0 0 0, 5 0 0, 5 5 0, 0 5 0, 0 0 0)))',
|
454
|
-
:
|
432
|
+
delta_x: 2, delta_y: 3, x_factor: 5, y_factor: 7)
|
455
433
|
|
456
434
|
affine_tester(:trans_scale,
|
457
435
|
'GEOMETRYCOLLECTION Z (POINT Z (3 1 1), LINESTRING Z (3 1 1, 12 10 10), POLYGON Z ((2 0 0, 7 0 0, 7 5 0, 2 5 0, 2 0 0)))',
|
458
436
|
'GEOMETRYCOLLECTION Z (POINT Z (1 1 1), LINESTRING Z (1 1 1, 10 10 10), POLYGON Z ((0 0 0, 5 0 0, 5 5 0, 0 5 0, 0 0 0)))',
|
459
|
-
:
|
437
|
+
delta_x: 2, z_factor: 2)
|
460
438
|
end
|
461
439
|
|
462
|
-
|
463
440
|
def test_translate
|
464
441
|
affine_tester(:translate,
|
465
442
|
'GEOMETRYCOLLECTION (POINT (6 13), LINESTRING (5 12, 15 22), POLYGON ((5 12, 10 12, 10 17, 5 17, 5 12)))',
|
466
443
|
'GEOMETRYCOLLECTION (POINT (1 1), LINESTRING (0 0, 10 10), POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0)))',
|
467
444
|
5,
|
468
|
-
12
|
469
|
-
)
|
445
|
+
12)
|
470
446
|
|
471
447
|
writer.output_dimensions = 3
|
472
448
|
affine_tester(:translate,
|
@@ -474,25 +450,22 @@ class GeometryCollectionTests < Minitest::Test
|
|
474
450
|
'GEOMETRYCOLLECTION Z (POINT Z (1 1 1), LINESTRING Z (1 1 1, 10 10 10), POLYGON Z ((0 0 0, 5 0 0, 5 5 0, 0 5 0, 0 0 0)))',
|
475
451
|
-3,
|
476
452
|
-7,
|
477
|
-
3
|
478
|
-
)
|
453
|
+
3)
|
479
454
|
end
|
480
455
|
|
481
456
|
def test_translate_hash
|
482
457
|
affine_tester(:translate,
|
483
458
|
'GEOMETRYCOLLECTION (POINT (6 13), LINESTRING (5 12, 15 22), POLYGON ((5 12, 10 12, 10 17, 5 17, 5 12)))',
|
484
459
|
'GEOMETRYCOLLECTION (POINT (1 1), LINESTRING (0 0, 10 10), POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0)))',
|
485
|
-
:
|
486
|
-
:
|
487
|
-
)
|
460
|
+
x: 5,
|
461
|
+
y: 12)
|
488
462
|
|
489
463
|
writer.output_dimensions = 3
|
490
464
|
affine_tester(:translate,
|
491
465
|
'GEOMETRYCOLLECTION Z (POINT Z (-2 -6 4), LINESTRING Z (-2 -6 4, 7 3 13), POLYGON Z ((-3 -7 3, 2 -7 3, 2 -2 3, -3 -2 3, -3 -7 3)))',
|
492
466
|
'GEOMETRYCOLLECTION Z (POINT Z (1 1 1), LINESTRING Z (1 1 1, 10 10 10), POLYGON Z ((0 0 0, 5 0 0, 5 5 0, 0 5 0, 0 0 0)))',
|
493
|
-
:
|
494
|
-
:
|
495
|
-
:
|
496
|
-
)
|
467
|
+
x: -3,
|
468
|
+
y: -7,
|
469
|
+
z: 3)
|
497
470
|
end
|
498
471
|
end
|
data/test/geometry_tests.rb
CHANGED
@@ -133,7 +133,7 @@ class GeometryTests < Minitest::Test
|
|
133
133
|
def test_difference
|
134
134
|
comparison_tester(
|
135
135
|
:difference,
|
136
|
-
|
136
|
+
EMPTY_GEOMETRY,
|
137
137
|
'POINT(0 0)',
|
138
138
|
'POINT(0 0)'
|
139
139
|
)
|
@@ -154,7 +154,7 @@ class GeometryTests < Minitest::Test
|
|
154
154
|
|
155
155
|
comparison_tester(
|
156
156
|
:difference,
|
157
|
-
|
157
|
+
EMPTY_GEOMETRY,
|
158
158
|
'POINT(5 0)',
|
159
159
|
'LINESTRING(0 0, 10 0)'
|
160
160
|
)
|
@@ -206,7 +206,7 @@ class GeometryTests < Minitest::Test
|
|
206
206
|
%w{ sym_difference symmetric_difference }.each do |method|
|
207
207
|
comparison_tester(
|
208
208
|
method,
|
209
|
-
|
209
|
+
EMPTY_GEOMETRY,
|
210
210
|
'POINT(0 0)',
|
211
211
|
'POINT(0 0)'
|
212
212
|
)
|
@@ -383,6 +383,19 @@ class GeometryTests < Minitest::Test
|
|
383
383
|
)
|
384
384
|
end
|
385
385
|
|
386
|
+
def test_coverage_union
|
387
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:coverage_union)
|
388
|
+
|
389
|
+
simple_tester(
|
390
|
+
:union_cascaded,
|
391
|
+
'POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))',
|
392
|
+
'MULTIPOLYGON(
|
393
|
+
((0 0, 0 1, 1 1, 1 0, 0 0)),
|
394
|
+
((1 0, 1 1, 2 1, 2 0, 1 0))
|
395
|
+
))'
|
396
|
+
)
|
397
|
+
end
|
398
|
+
|
386
399
|
def test_unary_union
|
387
400
|
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:unary_union)
|
388
401
|
|
@@ -515,6 +528,17 @@ class GeometryTests < Minitest::Test
|
|
515
528
|
end
|
516
529
|
end
|
517
530
|
|
531
|
+
def test_minimum_bounding_circle
|
532
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_bounding_circle)
|
533
|
+
|
534
|
+
geom = read('LINESTRING(0 10, 0 20)')
|
535
|
+
|
536
|
+
assert_equal(
|
537
|
+
'POLYGON ((5 15, 5 14, 5 13, 4 12, 4 11, 3 11, 2 10, 1 10, 0 10, -1 10, -2 10, -3 11, -4 11, -4 12, -5 13, -5 14, -5 15, -5 16, -5 17, -4 18, -4 19, -3 19, -2 20, -1 20, 0 20, 1 20, 2 20, 3 19, 4 19, 4 18, 5 17, 5 16, 5 15))',
|
538
|
+
write(geom.minimum_bounding_circle.snap_to_grid(1))
|
539
|
+
)
|
540
|
+
end
|
541
|
+
|
518
542
|
def test_envelope
|
519
543
|
simple_tester(
|
520
544
|
:envelope,
|
@@ -649,7 +673,7 @@ class GeometryTests < Minitest::Test
|
|
649
673
|
tests.each do |test|
|
650
674
|
expected, method, args = test
|
651
675
|
if ENV['FORCE_TESTS'] || geom_a.respond_to?(method)
|
652
|
-
value = geom_a.send(method, *([
|
676
|
+
value = geom_a.send(method, *([geom_b] + Array(args)))
|
653
677
|
assert_equal(expected, value)
|
654
678
|
end
|
655
679
|
end
|
@@ -951,7 +975,7 @@ class GeometryTests < Minitest::Test
|
|
951
975
|
def test_interior_rings
|
952
976
|
array_tester(
|
953
977
|
:interior_rings,
|
954
|
-
[
|
978
|
+
['LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)'],
|
955
979
|
'POLYGON(
|
956
980
|
(10 10, 10 14, 14 14, 14 10, 10 10),
|
957
981
|
(11 11, 11 12, 12 12, 12 11, 11 11)
|
@@ -1154,12 +1178,22 @@ class GeometryTests < Minitest::Test
|
|
1154
1178
|
simple_tester(:distance, 2.0, geom, read('LINESTRING (3 0 , 10 0)'))
|
1155
1179
|
end
|
1156
1180
|
|
1181
|
+
def test_distance_indexed
|
1182
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:distance_indexed)
|
1183
|
+
|
1184
|
+
geom_a = read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
|
1185
|
+
geom_b = read('POLYGON ((20 30, 10 10, 13 14, 7 8, 20 30))')
|
1186
|
+
|
1187
|
+
assert_in_delta(9.219544457292887, geom_a.distance_indexed(geom_b), TOLERANCE)
|
1188
|
+
assert_in_delta(9.219544457292887, geom_b.distance_indexed(geom_a), TOLERANCE)
|
1189
|
+
end
|
1190
|
+
|
1157
1191
|
def test_hausdorff_distance
|
1158
1192
|
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hausdorff_distance)
|
1159
1193
|
|
1160
|
-
tester = lambda { |expected,
|
1161
|
-
geom_1 = read(
|
1162
|
-
geom_2 = read(
|
1194
|
+
tester = lambda { |expected, g_1, g_2|
|
1195
|
+
geom_1 = read(g_1)
|
1196
|
+
geom_2 = read(g_2)
|
1163
1197
|
assert_in_delta(expected, geom_1.hausdorff_distance(geom_2), TOLERANCE)
|
1164
1198
|
}
|
1165
1199
|
|
@@ -1173,9 +1207,9 @@ class GeometryTests < Minitest::Test
|
|
1173
1207
|
def test_hausdorff_distance_with_densify_fract
|
1174
1208
|
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hausdorff_distance)
|
1175
1209
|
|
1176
|
-
tester = lambda { |expected,
|
1177
|
-
geom_1 = read(
|
1178
|
-
geom_2 = read(
|
1210
|
+
tester = lambda { |expected, g_1, g_2|
|
1211
|
+
geom_1 = read(g_1)
|
1212
|
+
geom_2 = read(g_2)
|
1179
1213
|
assert_in_delta(expected, geom_1.hausdorff_distance(geom_2, 0.001), TOLERANCE)
|
1180
1214
|
}
|
1181
1215
|
|
@@ -1189,9 +1223,9 @@ class GeometryTests < Minitest::Test
|
|
1189
1223
|
def test_nearest_points
|
1190
1224
|
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:nearest_points)
|
1191
1225
|
|
1192
|
-
tester = lambda { |expected,
|
1193
|
-
geom_1 = read(
|
1194
|
-
geom_2 = read(
|
1226
|
+
tester = lambda { |expected, g_1, g_2|
|
1227
|
+
geom_1 = read(g_1)
|
1228
|
+
geom_2 = read(g_2)
|
1195
1229
|
|
1196
1230
|
cs = geom_1.nearest_points(geom_2)
|
1197
1231
|
result = cs.to_s if cs
|
@@ -1206,7 +1240,11 @@ class GeometryTests < Minitest::Test
|
|
1206
1240
|
]
|
1207
1241
|
|
1208
1242
|
tester[
|
1209
|
-
|
1243
|
+
if Geos::GEOS_VERSION > '3.8'
|
1244
|
+
'5.0 5.0, 8.0 8.0'
|
1245
|
+
else
|
1246
|
+
'5.0 5.0 NaN, 8.0 8.0 NaN'
|
1247
|
+
end,
|
1210
1248
|
'POLYGON((1 1, 1 5, 5 5, 5 1, 1 1))',
|
1211
1249
|
'POLYGON((8 8, 9 9, 9 10, 8 8))'
|
1212
1250
|
]
|
@@ -1246,6 +1284,41 @@ class GeometryTests < Minitest::Test
|
|
1246
1284
|
)
|
1247
1285
|
end
|
1248
1286
|
|
1287
|
+
def test_polygonize_with_geometry_arguments
|
1288
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize)
|
1289
|
+
|
1290
|
+
geom_a = read('LINESTRING (100 100, 100 300, 300 300, 300 100, 100 100)')
|
1291
|
+
geom_b = read('LINESTRING (150 150, 150 250, 250 250, 250 150, 150 150)')
|
1292
|
+
|
1293
|
+
polygonized = geom_a.polygonize(geom_b)
|
1294
|
+
assert_equal(2, polygonized.length)
|
1295
|
+
assert_equal(
|
1296
|
+
'POLYGON ((100 100, 100 300, 300 300, 300 100, 100 100), (150 150, 250 150, 250 250, 150 250, 150 150))',
|
1297
|
+
write(polygonized[0].snap_to_grid(0.1))
|
1298
|
+
)
|
1299
|
+
assert_equal(
|
1300
|
+
'POLYGON ((150 150, 150 250, 250 250, 250 150, 150 150))',
|
1301
|
+
write(polygonized[1].snap_to_grid(0.1))
|
1302
|
+
)
|
1303
|
+
end
|
1304
|
+
|
1305
|
+
def test_polygonize_valid
|
1306
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_valid)
|
1307
|
+
|
1308
|
+
geom_a = read(
|
1309
|
+
'GEOMETRYCOLLECTION(
|
1310
|
+
LINESTRING (100 100, 100 300, 300 300, 300 100, 100 100),
|
1311
|
+
LINESTRING (150 150, 150 250, 250 250, 250 150, 150 150)
|
1312
|
+
)'
|
1313
|
+
)
|
1314
|
+
|
1315
|
+
polygonized = geom_a.polygonize_valid
|
1316
|
+
assert_equal(
|
1317
|
+
'POLYGON ((100 100, 100 300, 300 300, 300 100, 100 100), (150 150, 250 150, 250 250, 150 250, 150 150))',
|
1318
|
+
write(polygonized.snap_to_grid(0.1))
|
1319
|
+
)
|
1320
|
+
end
|
1321
|
+
|
1249
1322
|
def test_polygonize_cut_edges
|
1250
1323
|
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_cut_edges)
|
1251
1324
|
|
@@ -1338,6 +1411,22 @@ class GeometryTests < Minitest::Test
|
|
1338
1411
|
end
|
1339
1412
|
end
|
1340
1413
|
|
1414
|
+
def test_build_area
|
1415
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:build_area)
|
1416
|
+
|
1417
|
+
geom = read('GEOMETRYCOLLECTION (LINESTRING(0 0, 0 1, 1 1), LINESTRING (1 1, 1 0, 0 0))')
|
1418
|
+
|
1419
|
+
assert_equal('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))', write(geom.build_area))
|
1420
|
+
end
|
1421
|
+
|
1422
|
+
def test_make_valid
|
1423
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:make_valid)
|
1424
|
+
|
1425
|
+
geom = read('POLYGON((0 0, 1 1, 0 1, 1 0, 0 0))')
|
1426
|
+
|
1427
|
+
assert_equal('MULTIPOLYGON (((0 0, 0.5 0.5, 1 0, 0 0)), ((0.5 0.5, 0 1, 1 1, 0.5 0.5)))', write(geom.make_valid))
|
1428
|
+
end
|
1429
|
+
|
1341
1430
|
def test_shared_paths
|
1342
1431
|
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:shared_paths)
|
1343
1432
|
|
@@ -1507,7 +1596,7 @@ class GeometryTests < Minitest::Test
|
|
1507
1596
|
assert_raises(Geos::MixedSRIDsError) do
|
1508
1597
|
Geos.srid_copy_policy = :strict
|
1509
1598
|
geom_c = geom.intersection(geom_b)
|
1510
|
-
assert_equal(
|
1599
|
+
assert_equal(231_231, geom_c.srid)
|
1511
1600
|
end
|
1512
1601
|
ensure
|
1513
1602
|
Geos.srid_copy_policy = :default
|
@@ -1623,7 +1712,7 @@ class GeometryTests < Minitest::Test
|
|
1623
1712
|
|
1624
1713
|
# Allows a tolerance for the first argument
|
1625
1714
|
@writer.rounding_precision = 3
|
1626
|
-
tester['GEOMETRYCOLLECTION (POLYGON ((290 252, 290 140, 185 140, 185 215, 188 235, 290 252)), POLYGON ((80 215, 80 340, 101 340, 188 235, 185 215, 80 215)), POLYGON ((185 140, 80 140, 80 215, 185 215, 185 140)), POLYGON ((101 340, 290 340, 290 252, 188 235, 101 340)))',
|
1715
|
+
tester['GEOMETRYCOLLECTION (POLYGON ((290 252, 290 140, 185 140, 185 215, 188 235, 290 252)), POLYGON ((80 215, 80 340, 101 340, 188 235, 185 215, 80 215)), POLYGON ((185 140, 80 140, 80 215, 185 215, 185 140)), POLYGON ((101 340, 290 340, 290 252, 188 235, 101 340)))', 'MULTIPOINT ((150 210), (210 270), (150 220), (220 210), (215 269))', 10]
|
1627
1716
|
end
|
1628
1717
|
|
1629
1718
|
def test_precision
|