ffi-geos 2.1.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,12 +13,40 @@ class GeometryTests < Minitest::Test
13
13
  def test_intersection
14
14
  comparison_tester(
15
15
  :intersection,
16
- 'POLYGON ((5 10, 10 10, 10 5, 5 5, 5 10))',
16
+ if Geos::GEOS_NICE_VERSION > '030900'
17
+ 'POLYGON ((10 10, 10 5, 5 5, 5 10, 10 10))'
18
+ else
19
+ 'POLYGON ((5 10, 10 10, 10 5, 5 5, 5 10))'
20
+ end,
17
21
  'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))',
18
22
  'POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'
19
23
  )
20
24
  end
21
25
 
26
+ def test_intersection_with_precision
27
+ skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSIntersectionPrec_r)
28
+
29
+ comparison_tester(
30
+ :intersection,
31
+ 'GEOMETRYCOLLECTION (POLYGON ((1 2, 1 1, 0.5 1, 1 2)), POLYGON ((9.5 1, 2 1, 2 2, 9 2, 9.5 1)), LINESTRING (1 1, 2 1), LINESTRING (2 2, 1 2))',
32
+ 'MULTIPOLYGON(((0 0,5 10,10 0,0 0),(1 1,1 2,2 2,2 1,1 1),(100 100,100 102,102 102,102 100,100 100)))',
33
+ 'POLYGON((0 1,0 2,10 2,10 1,0 1))',
34
+ precision: 0
35
+ )
36
+
37
+ comparison_tester(
38
+ :intersection,
39
+ if Geos::GEOS_NICE_VERSION >= '031000'
40
+ 'GEOMETRYCOLLECTION (LINESTRING (2 0, 4 0), POINT (10 0), POINT (0 0))'
41
+ else
42
+ 'GEOMETRYCOLLECTION (LINESTRING (2 0, 4 0), POINT (0 0), POINT (10 0))'
43
+ end,
44
+ 'LINESTRING(0 0, 10 0)',
45
+ 'LINESTRING(9 0, 12 0, 12 20, 4 0, 2 0, 2 10, 0 10, 0 -10)',
46
+ precision: 2
47
+ )
48
+ end
49
+
22
50
  def test_buffer
23
51
  simple_tester(
24
52
  :buffer,
@@ -95,7 +123,11 @@ class GeometryTests < Minitest::Test
95
123
 
96
124
  snapped_tester(
97
125
  :buffer,
98
- 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 109 -5, 105 -9, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))',
126
+ if Geos::GEOS_NICE_VERSION >= '031100'
127
+ 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 -4, 104 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))'
128
+ else
129
+ 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 109 -5, 105 -9, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))'
130
+ end,
99
131
  'LINESTRING(0 0, 100 0, 100 100)',
100
132
  10,
101
133
  quad_segs: 2, join: :mitre, mitre_limit: 1.0
@@ -182,26 +214,50 @@ class GeometryTests < Minitest::Test
182
214
 
183
215
  comparison_tester(
184
216
  :difference,
185
- 'POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0))',
217
+ if Geos::GEOS_NICE_VERSION > '030900'
218
+ 'POLYGON ((0 10, 5 10, 10 10, 10 0, 5 0, 0 0, 0 10))'
219
+ else
220
+ 'POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0))'
221
+ end,
186
222
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
187
223
  'LINESTRING(5 -10, 5 10)'
188
224
  )
189
225
 
190
226
  comparison_tester(
191
227
  :difference,
192
- 'POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0))',
228
+ if Geos::GEOS_NICE_VERSION > '030900'
229
+ 'POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10))'
230
+ else
231
+ 'POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))'
232
+ end,
193
233
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
194
234
  'LINESTRING(10 0, 20 0)'
195
235
  )
196
236
 
197
237
  comparison_tester(
198
238
  :difference,
199
- 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0))',
239
+ if Geos::GEOS_NICE_VERSION > '030900'
240
+ 'POLYGON ((0 10, 10 10, 10 5, 5 5, 5 0, 0 0, 0 10))'
241
+ else
242
+ 'POLYGON ((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0))'
243
+ end,
200
244
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
201
245
  'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
202
246
  )
203
247
  end
204
248
 
249
+ def test_difference_with_precision
250
+ skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSDifferencePrec_r)
251
+
252
+ comparison_tester(
253
+ :difference,
254
+ 'MULTILINESTRING ((2 8, 4 8), (6 8, 10 8))',
255
+ 'LINESTRING (2 8, 10 8)',
256
+ 'LINESTRING (3.9 8.1, 6.1 7.9)',
257
+ precision: 2
258
+ )
259
+ end
260
+
205
261
  def test_sym_difference
206
262
  %w{ sym_difference symmetric_difference }.each do |method|
207
263
  comparison_tester(
@@ -255,27 +311,51 @@ class GeometryTests < Minitest::Test
255
311
 
256
312
  comparison_tester(
257
313
  method,
258
- 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))',
314
+ if Geos::GEOS_NICE_VERSION > '030900'
315
+ 'GEOMETRYCOLLECTION (POLYGON ((0 10, 5 10, 10 10, 10 0, 5 0, 0 0, 0 10)), LINESTRING (5 -10, 5 0))'
316
+ else
317
+ 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)))'
318
+ end,
259
319
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
260
320
  'LINESTRING(5 -10, 5 10)'
261
321
  )
262
322
 
263
323
  comparison_tester(
264
324
  method,
265
- 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))',
325
+ if Geos::GEOS_NICE_VERSION > '030900'
326
+ 'GEOMETRYCOLLECTION (POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10)), LINESTRING (10 0, 20 0))'
327
+ else
328
+ 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)))'
329
+ end,
266
330
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
267
331
  'LINESTRING(10 0, 20 0)'
268
332
  )
269
333
 
270
334
  comparison_tester(
271
335
  method,
272
- 'MULTIPOLYGON (((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0)), ((5 0, 10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0)))',
336
+ if Geos::GEOS_NICE_VERSION > '030900'
337
+ 'MULTIPOLYGON (((0 10, 10 10, 10 5, 5 5, 5 0, 0 0, 0 10)), ((10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0, 10 0)))'
338
+ else
339
+ 'MULTIPOLYGON (((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0)), ((5 0, 10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0)))'
340
+ end,
273
341
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
274
342
  'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
275
343
  )
276
344
  end
277
345
  end
278
346
 
347
+ def test_sym_difference_with_precision
348
+ skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSSymDifferencePrec_r)
349
+
350
+ comparison_tester(
351
+ :sym_difference,
352
+ 'GEOMETRYCOLLECTION (POLYGON ((0 10, 6 10, 10 10, 10 0, 6 0, 0 0, 0 10)), LINESTRING (6 -10, 6 0))',
353
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
354
+ 'LINESTRING(5 -10, 5 10)',
355
+ precision: 2
356
+ )
357
+ end
358
+
279
359
  def test_boundary
280
360
  simple_tester(
281
361
  :boundary,
@@ -348,32 +428,59 @@ class GeometryTests < Minitest::Test
348
428
 
349
429
  comparison_tester(
350
430
  :union,
351
- 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))',
431
+ if Geos::GEOS_NICE_VERSION > '030900'
432
+ 'GEOMETRYCOLLECTION (POLYGON ((0 10, 5 10, 10 10, 10 0, 5 0, 0 0, 0 10)), LINESTRING (5 -10, 5 0))'
433
+ else
434
+ 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)))'
435
+ end,
352
436
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
353
437
  'LINESTRING(5 -10, 5 10)'
354
438
  )
355
439
 
356
440
  comparison_tester(
357
441
  :union,
358
- 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))',
442
+ if Geos::GEOS_NICE_VERSION > '030900'
443
+ 'GEOMETRYCOLLECTION (POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10)), LINESTRING (10 0, 20 0))'
444
+ else
445
+ 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)))'
446
+ end,
359
447
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
360
448
  'LINESTRING(10 0, 20 0)'
361
449
  )
362
450
 
363
451
  comparison_tester(
364
452
  :union,
365
- 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0))',
453
+ if Geos::GEOS_NICE_VERSION > '030900'
454
+ 'POLYGON ((0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0, 0 10))'
455
+ else
456
+ 'POLYGON ((0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0))'
457
+ end,
366
458
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
367
459
  'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
368
460
  )
369
461
  end
370
462
 
463
+ def test_union_with_precision
464
+ skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSUnionPrec_r)
465
+
466
+ geom_a = read('POINT (1.9 8.2)')
467
+ geom_b = read('POINT (4.1 9.8)')
468
+
469
+ result = geom_a.union(geom_b, precision: 2)
470
+
471
+ assert_equal('MULTIPOINT (2 8, 4 10)', write(result))
472
+ end
473
+
371
474
  def test_union_cascaded
372
475
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:union_cascaded)
373
476
 
374
477
  simple_tester(
375
478
  :union_cascaded,
376
- 'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))',
479
+ if Geos::GEOS_NICE_VERSION > '030900'
480
+ 'POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))'
481
+ else
482
+ 'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))'
483
+ end,
377
484
  'MULTIPOLYGON(
378
485
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
379
486
  ((10 10, 10 14, 14 14, 14 10, 10 10),
@@ -388,7 +495,11 @@ class GeometryTests < Minitest::Test
388
495
 
389
496
  simple_tester(
390
497
  :union_cascaded,
391
- 'POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))',
498
+ if Geos::GEOS_NICE_VERSION > '030900'
499
+ 'POLYGON ((0 1, 1 1, 2 1, 2 0, 1 0, 0 0, 0 1))'
500
+ else
501
+ 'POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))'
502
+ end,
392
503
  'MULTIPOLYGON(
393
504
  ((0 0, 0 1, 1 1, 1 0, 0 0)),
394
505
  ((1 0, 1 1, 2 1, 2 0, 1 0))
@@ -401,7 +512,11 @@ class GeometryTests < Minitest::Test
401
512
 
402
513
  simple_tester(
403
514
  :unary_union,
404
- 'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))',
515
+ if Geos::GEOS_NICE_VERSION > '030900'
516
+ 'POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))'
517
+ else
518
+ 'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))'
519
+ end,
405
520
  'MULTIPOLYGON(
406
521
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
407
522
  ((10 10, 10 14, 14 14, 14 10, 10 10),
@@ -411,6 +526,22 @@ class GeometryTests < Minitest::Test
411
526
  )
412
527
  end
413
528
 
529
+ def test_unary_union_with_precision
530
+ skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSUnaryUnionPrec_r)
531
+
532
+ simple_tester(
533
+ :unary_union,
534
+ 'POLYGON ((0 0, 0 12, 9 12, 9 15, 15 15, 15 9, 12 9, 12 0, 0 0))',
535
+ 'MULTIPOLYGON(
536
+ ((0 0, 1 0, 1 1, 0 1, 0 0)),
537
+ ((10 10, 10 14, 14 14, 14 10, 10 10),
538
+ (11 11, 11 12, 12 12, 12 11, 11 11)),
539
+ ((0 0, 11 0, 11 11, 0 11, 0 0))
540
+ ))',
541
+ 3
542
+ )
543
+ end
544
+
414
545
  def test_node
415
546
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:node)
416
547
 
@@ -424,7 +555,11 @@ class GeometryTests < Minitest::Test
424
555
  def test_union_without_arguments
425
556
  simple_tester(
426
557
  :union,
427
- 'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))',
558
+ if Geos::GEOS_NICE_VERSION > '030900'
559
+ 'POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))'
560
+ else
561
+ 'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))'
562
+ end,
428
563
  'MULTIPOLYGON(
429
564
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
430
565
  ((10 10, 10 14, 14 14, 14 10, 10 10),
@@ -828,7 +963,13 @@ class GeometryTests < Minitest::Test
828
963
  }
829
964
 
830
965
  assert_nil(read('POINT(0 0)').valid_detail)
831
- tester['Invalid Coordinate', 'POINT (0 nan)', 'POINT(0 NaN)', 0]
966
+
967
+ if Geos::GEOS_NICE_VERSION >= '031000'
968
+ tester['Invalid Coordinate', 'POINT (0 NaN)', 'POINT(0 NaN)', 0]
969
+ else
970
+ tester['Invalid Coordinate', 'POINT (0 nan)', 'POINT(0 NaN)', 0]
971
+ end
972
+
832
973
  tester['Self-intersection', 'POINT (2.5 5)', 'POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))', 0]
833
974
 
834
975
  tester['Ring Self-intersection', 'POINT (0 0)', 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))', 0]
@@ -1230,7 +1371,11 @@ class GeometryTests < Minitest::Test
1230
1371
  cs = geom_1.nearest_points(geom_2)
1231
1372
  result = cs.to_s if cs
1232
1373
 
1233
- assert_equal(expected, result)
1374
+ if expected.nil?
1375
+ assert_nil(result)
1376
+ else
1377
+ assert_equal(expected, result)
1378
+ end
1234
1379
  }
1235
1380
 
1236
1381
  tester[
@@ -1240,7 +1385,7 @@ class GeometryTests < Minitest::Test
1240
1385
  ]
1241
1386
 
1242
1387
  tester[
1243
- if Geos::GEOS_VERSION > '3.8'
1388
+ if Geos::GEOS_NICE_VERSION >= '030800'
1244
1389
  '5.0 5.0, 8.0 8.0'
1245
1390
  else
1246
1391
  '5.0 5.0 NaN, 8.0 8.0 NaN'
@@ -1340,7 +1485,11 @@ class GeometryTests < Minitest::Test
1340
1485
  def test_polygonize_full
1341
1486
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_full)
1342
1487
 
1343
- writer.rounding_precision = 3
1488
+ writer.rounding_precision = if Geos::GEOS_NICE_VERSION >= '031000'
1489
+ 0
1490
+ else
1491
+ 3
1492
+ end
1344
1493
 
1345
1494
  geom_a = read(
1346
1495
  'GEOMETRYCOLLECTION(
@@ -1424,7 +1573,14 @@ class GeometryTests < Minitest::Test
1424
1573
 
1425
1574
  geom = read('POLYGON((0 0, 1 1, 0 1, 1 0, 0 0))')
1426
1575
 
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))
1576
+ assert_equal(
1577
+ if Geos::GEOS_NICE_VERSION > '030900'
1578
+ 'MULTIPOLYGON (((1 0, 0 0, 0.5 0.5, 1 0)), ((1 1, 0.5 0.5, 0 1, 1 1)))'
1579
+ else
1580
+ 'MULTIPOLYGON (((0 0, 0.5 0.5, 1 0, 0 0)), ((0.5 0.5, 0 1, 1 1, 0.5 0.5)))'
1581
+ end,
1582
+ write(geom.make_valid)
1583
+ )
1428
1584
  end
1429
1585
 
1430
1586
  def test_shared_paths
@@ -1482,7 +1638,7 @@ class GeometryTests < Minitest::Test
1482
1638
  geom = read('LINESTRING(0 0, 10 10))')
1483
1639
  assert_kind_of(Enumerable, geom.each)
1484
1640
  assert_kind_of(Enumerable, geom.to_enum)
1485
- assert_equal(geom, geom.each {})
1641
+ assert_equal(geom, geom.each(&EMPTY_BLOCK))
1486
1642
  end
1487
1643
 
1488
1644
  def test_normalize
@@ -1668,7 +1824,9 @@ class GeometryTests < Minitest::Test
1668
1824
 
1669
1825
  # polygon with a hole
1670
1826
  tester[
1671
- 'GEOMETRYCOLLECTION (POLYGON ((8 2, 10 10, 8.5 1, 8 2)), POLYGON ((7 8, 10 10, 8 2, 7 8)), POLYGON ((3 8, 10 10, 7 8, 3 8)), POLYGON ((2 2, 8 2, 8.5 1, 2 2)), POLYGON ((2 2, 7 8, 8 2, 2 2)), POLYGON ((2 2, 3 8, 7 8, 2 2)), POLYGON ((0.5 9, 10 10, 3 8, 0.5 9)), POLYGON ((0.5 9, 3 8, 2 2, 0.5 9)), POLYGON ((0 0, 2 2, 8.5 1, 0 0)), POLYGON ((0 0, 0.5 9, 2 2, 0 0)))',
1827
+ 'GEOMETRYCOLLECTION (POLYGON ((8 2, 10 10, 8.5 1, 8 2)), POLYGON ((7 8, 10 10, 8 2, 7 8)), POLYGON ((3 8, 10 10, 7 8, 3 8)), ' \
1828
+ 'POLYGON ((2 2, 8 2, 8.5 1, 2 2)), POLYGON ((2 2, 7 8, 8 2, 2 2)), POLYGON ((2 2, 3 8, 7 8, 2 2)), POLYGON ((0.5 9, 10 10, 3 8, 0.5 9)), ' \
1829
+ 'POLYGON ((0.5 9, 3 8, 2 2, 0.5 9)), POLYGON ((0 0, 2 2, 8.5 1, 0 0)), POLYGON ((0 0, 0.5 9, 2 2, 0 0)))',
1672
1830
  'POLYGON((0 0, 8.5 1, 10 10, 0.5 9, 0 0),(2 2, 3 8, 7 8, 8 2, 2 2)))',
1673
1831
  0
1674
1832
  ]
@@ -1701,7 +1859,14 @@ class GeometryTests < Minitest::Test
1701
1859
 
1702
1860
  geom = 'MULTIPOINT(0 0, 100 0, 100 100, 0 100)'
1703
1861
 
1704
- tester['GEOMETRYCOLLECTION (POLYGON ((50 200, 200 200, 200 50, 50 50, 50 200)), POLYGON ((-100 50, -100 200, 50 200, 50 50, -100 50)), POLYGON ((50 -100, -100 -100, -100 50, 50 50, 50 -100)), POLYGON ((200 50, 200 -100, 50 -100, 50 50, 200 50)))', geom]
1862
+ tester[
1863
+ if Geos::GEOS_NICE_VERSION > '030900'
1864
+ 'GEOMETRYCOLLECTION (POLYGON ((200 200, 200 50, 50 50, 50 200, 200 200)), POLYGON ((-100 200, 50 200, 50 50, -100 50, -100 200)), POLYGON ((-100 -100, -100 50, 50 50, 50 -100, -100 -100)), POLYGON ((200 -100, 50 -100, 50 50, 200 50, 200 -100)))'
1865
+ else
1866
+ 'GEOMETRYCOLLECTION (POLYGON ((50 200, 200 200, 200 50, 50 50, 50 200)), POLYGON ((-100 50, -100 200, 50 200, 50 50, -100 50)), POLYGON ((50 -100, -100 -100, -100 50, 50 50, 50 -100)), POLYGON ((200 50, 200 -100, 50 -100, 50 50, 200 50)))'
1867
+ end,
1868
+ geom
1869
+ ]
1705
1870
 
1706
1871
  tester['MULTILINESTRING ((50 50, 50 200), (200 50, 50 50), (50 50, -100 50), (50 50, 50 -100))', geom, tolerance: 0, only_edges: true]
1707
1872
 
@@ -1711,8 +1876,23 @@ class GeometryTests < Minitest::Test
1711
1876
  ]
1712
1877
 
1713
1878
  # Allows a tolerance for the first argument
1714
- @writer.rounding_precision = 3
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]
1879
+ writer.rounding_precision = if Geos::GEOS_NICE_VERSION >= '031000'
1880
+ 0
1881
+ else
1882
+ 3
1883
+ end
1884
+
1885
+ writer.trim = true
1886
+
1887
+ tester[
1888
+ if Geos::GEOS_NICE_VERSION > '030900'
1889
+ 'GEOMETRYCOLLECTION (POLYGON ((290 140, 185 140, 185 215, 188 235, 290 252, 290 140)), POLYGON ((80 340, 101 340, 188 235, 185 215, 80 215, 80 340)), POLYGON ((80 140, 80 215, 185 215, 185 140, 80 140)), POLYGON ((290 340, 290 252, 188 235, 101 340, 290 340)))'
1890
+ else
1891
+ '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)))'
1892
+ end,
1893
+ 'MULTIPOINT ((150 210), (210 270), (150 220), (220 210), (215 269))',
1894
+ 10
1895
+ ]
1716
1896
  end
1717
1897
 
1718
1898
  def test_precision
@@ -1785,11 +1965,37 @@ class GeometryTests < Minitest::Test
1785
1965
  tester['LINESTRING (200 200, 200 100)', 'POLYGON ((100 100, 300 100, 200 200, 100 100))']
1786
1966
  tester[
1787
1967
  'LINESTRING (-112.712119 33.575919, -112.712127 33.575885)',
1788
- '0106000000010000000103000000010000001a00000035d42824992d5cc01b834e081dca404073b9c150872d5cc03465a71fd4c940400ec00644882d5cc03b8a73d4d1c94040376dc669882d5cc0bf9cd9aed0c940401363997e892d5cc002f4fbfecdc94040ca4e3fa88b2d5cc0a487a1d5c9c940408f1ce90c8c2d5cc0698995d1c8c94040fab836548c2d5cc0bd175fb4c7c940409f1f46088f2d5cc0962023a0c2c940407b15191d902d5cc068041bd7bfc940400397c79a912d5cc0287d21e4bcc940403201bf46922d5cc065e3c116bbc940409d9d0c8e922d5cc0060fd3beb9c940400ef7915b932d5cc09012bbb6b7c940404fe61f7d932d5cc0e4a08499b6c94040fc71fbe5932d5cc0ea9106b7b5c94040eaec6470942d5cc0c2323674b3c94040601dc70f952d5cc043588d25acc94040aea06989952d5cc03ecf9f36aac94040307f85cc952d5cc0e5eb32fca7c94040dd0a6135962d5cc01b615111a7c9404048a7ae7c962d5cc00a2aaa7ea5c94040f4328ae5962d5cc05eb87361a4c94040c49448a2972d5cc04d81cccea2c940407c80eecb992d5cc06745d4449fc9404035d42824992d5cc01b834e081dca4040'
1968
+ '0106000000010000000103000000010000001a00000035d42824992d5cc01b834e081dca404073b9c150872d5cc03465a71fd4c940400ec00644882d5cc03b8a' \
1969
+ '73d4d1c94040376dc669882d5cc0bf9cd9aed0c940401363997e892d5cc002f4fbfecdc94040ca4e3fa88b2d5cc0a487a1d5c9c940408f1ce90c8c2d5cc06989' \
1970
+ '95d1c8c94040fab836548c2d5cc0bd175fb4c7c940409f1f46088f2d5cc0962023a0c2c940407b15191d902d5cc068041bd7bfc940400397c79a912d5cc0287d' \
1971
+ '21e4bcc940403201bf46922d5cc065e3c116bbc940409d9d0c8e922d5cc0060fd3beb9c940400ef7915b932d5cc09012bbb6b7c940404fe61f7d932d5cc0e4a0' \
1972
+ '8499b6c94040fc71fbe5932d5cc0ea9106b7b5c94040eaec6470942d5cc0c2323674b3c94040601dc70f952d5cc043588d25acc94040aea06989952d5cc03ecf' \
1973
+ '9f36aac94040307f85cc952d5cc0e5eb32fca7c94040dd0a6135962d5cc01b615111a7c9404048a7ae7c962d5cc00a2aaa7ea5c94040f4328ae5962d5cc05eb8' \
1974
+ '7361a4c94040c49448a2972d5cc04d81cccea2c940407c80eecb992d5cc06745d4449fc9404035d42824992d5cc01b834e081dca4040'
1789
1975
  ]
1790
1976
  tester['LINESTRING EMPTY', 'POLYGON EMPTY']
1791
1977
  end
1792
1978
 
1979
+ def test_maximum_inscribed_circle
1980
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:maximum_inscribed_circle)
1981
+
1982
+ geom = read('POLYGON ((100 200, 200 200, 200 100, 100 100, 100 200))')
1983
+ output = geom.maximum_inscribed_circle(0.001)
1984
+ assert_equal('LINESTRING (150 150, 150 200)', write(output))
1985
+ end
1986
+
1987
+ def test_largest_empty_circle
1988
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:largest_empty_circle)
1989
+
1990
+ geom = read('MULTIPOINT ((100 100), (100 200), (200 200), (200 100))')
1991
+ output = geom.largest_empty_circle(0.001)
1992
+ assert_equal('LINESTRING (150 150, 100 100)', write(output))
1993
+
1994
+ geom = read('MULTIPOINT ((100 100), (100 200), (200 200), (200 100))')
1995
+ output = geom.largest_empty_circle(0.001, boundary: read('MULTIPOINT ((100 100), (100 200), (200 200), (200 100))'))
1996
+ assert_equal('LINESTRING (100 100, 100 100)', write(output))
1997
+ end
1998
+
1793
1999
  def test_minimum_width
1794
2000
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_width)
1795
2001
 
@@ -1856,7 +2062,13 @@ class GeometryTests < Minitest::Test
1856
2062
  simple_tester(:reverse, 'POINT (3 5)', 'POINT (3 5)')
1857
2063
  simple_tester(:reverse, 'MULTIPOINT (100 100, 10 100, 30 100)', 'MULTIPOINT (100 100, 10 100, 30 100)')
1858
2064
  simple_tester(:reverse, 'LINESTRING (200 200, 200 100)', 'LINESTRING (200 100, 200 200)')
1859
- simple_tester(:reverse, 'MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))', 'MULTILINESTRING ((4 4, 3 3), (2 2, 1 1))')
2065
+
2066
+ if Geos::GEOS_NICE_VERSION >= '030801'
2067
+ simple_tester(:reverse, 'MULTILINESTRING ((3 3, 4 4), (1 1, 2 2))', 'MULTILINESTRING ((4 4, 3 3), (2 2, 1 1))')
2068
+ else
2069
+ simple_tester(:reverse, 'MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))', 'MULTILINESTRING ((4 4, 3 3), (2 2, 1 1))')
2070
+ end
2071
+
1860
2072
  simple_tester(:reverse, 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))', 'POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))')
1861
2073
  simple_tester(:reverse, 'MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1)), ((100 100, 100 200, 200 200, 100 100)))', 'MULTIPOLYGON (((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)), ((100 100, 200 200, 100 200, 100 100)))')
1862
2074
  simple_tester(:reverse, 'GEOMETRYCOLLECTION (LINESTRING (1 1, 2 2), GEOMETRYCOLLECTION (LINESTRING (3 5, 2 9)))', 'GEOMETRYCOLLECTION (LINESTRING (2 2, 1 1), GEOMETRYCOLLECTION(LINESTRING (2 9, 3 5)))')
@@ -80,7 +80,11 @@ class LineStringTests < Minitest::Test
80
80
  # straight right
81
81
  simple_tester(
82
82
  :offset_curve,
83
- 'LINESTRING (10 -2, 0 -2)',
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
- 'LINESTRING (12 10, 12 0, 10 -2, 0 -2)',
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,
@@ -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
 
data/test/point_tests.rb CHANGED
@@ -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
 
@@ -147,7 +147,7 @@ class PolygonTests < Minitest::Test
147
147
  affine_tester(:rotate_x,
148
148
  'POLYGON Z ((0 0 0, 5 0 0, 5 0 -5, 0 0 -5, 0 0 0))',
149
149
  wkt,
150
- Math::PI + Math::PI / 2)
150
+ Math::PI + (Math::PI / 2))
151
151
 
152
152
  affine_tester(:rotate_x,
153
153
  wkt,
@@ -173,7 +173,7 @@ class PolygonTests < Minitest::Test
173
173
  affine_tester(:rotate_y,
174
174
  'POLYGON Z ((0 0 0, 0 0 5, 0 5 5, 0 5 0, 0 0 0))',
175
175
  wkt,
176
- Math::PI + Math::PI / 2)
176
+ Math::PI + (Math::PI / 2))
177
177
 
178
178
  affine_tester(:rotate_y,
179
179
  wkt,
@@ -195,7 +195,7 @@ class PolygonTests < Minitest::Test
195
195
  affine_tester(:rotate_z,
196
196
  'POLYGON ((0 0, 0 -5, 5 -5, 5 0, 0 0))',
197
197
  'POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))',
198
- Math::PI + Math::PI / 2)
198
+ Math::PI + (Math::PI / 2))
199
199
 
200
200
  affine_tester(:rotate_z,
201
201
  'POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))',
@@ -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)')