ffi-geos 2.3.1 → 2.5.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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +2 -2
  3. data/.rbenv-vars +1 -0
  4. data/.rubocop-minitest.yml +40 -17
  5. data/.rubocop.yml +664 -120
  6. data/.rubocop_todo.yml +30 -19
  7. data/MIT-LICENSE +1 -1
  8. data/README.rdoc +2 -0
  9. data/ffi-geos.gemspec +2 -2
  10. data/lib/ffi-geos/coordinate_sequence.rb +2 -1
  11. data/lib/ffi-geos/geojson_reader.rb +35 -0
  12. data/lib/ffi-geos/geojson_writer.rb +49 -0
  13. data/lib/ffi-geos/geometry.rb +101 -1
  14. data/lib/ffi-geos/geometry_collection.rb +1 -1
  15. data/lib/ffi-geos/line_string.rb +1 -1
  16. data/lib/ffi-geos/point.rb +9 -0
  17. data/lib/ffi-geos/polygon.rb +1 -1
  18. data/lib/ffi-geos/prepared_geometry.rb +20 -0
  19. data/lib/ffi-geos/version.rb +1 -1
  20. data/lib/ffi-geos/wkb_writer.rb +12 -0
  21. data/lib/ffi-geos.rb +156 -3
  22. data/test/coordinate_sequence_tests.rb +22 -4
  23. data/test/geojson_reader_tests.rb +174 -0
  24. data/test/geojson_writer_tests.rb +103 -0
  25. data/test/geometry/area_tests.rb +18 -0
  26. data/test/geometry/boundary_tests.rb +36 -0
  27. data/test/geometry/buffer_tests.rb +116 -0
  28. data/test/geometry/build_area_tests.rb +20 -0
  29. data/test/geometry/centroid_tests.rb +37 -0
  30. data/test/geometry/clip_by_rect_tests.rb +56 -0
  31. data/test/geometry/clone_tests.rb +29 -0
  32. data/test/geometry/concave_hull_of_polygons_tests.rb +28 -0
  33. data/test/geometry/concave_hull_tests.rb +38 -0
  34. data/test/geometry/convex_hull_tests.rb +26 -0
  35. data/test/geometry/coord_seq_tests.rb +27 -0
  36. data/test/geometry/delaunay_triangulation_tests.rb +82 -0
  37. data/test/geometry/densify_tests.rb +95 -0
  38. data/test/geometry/difference_tests.rb +108 -0
  39. data/test/geometry/dimensions_tests.rb +46 -0
  40. data/test/geometry/distance_tests.rb +29 -0
  41. data/test/geometry/dump_points_tests.rb +60 -0
  42. data/test/geometry/dup_tests.rb +29 -0
  43. data/test/geometry/empty_tests.rb +23 -0
  44. data/test/geometry/envelope_tests.rb +26 -0
  45. data/test/geometry/equal_identical_tests.rb +78 -0
  46. data/test/geometry/equal_tests.rb +62 -0
  47. data/test/geometry/exterior_ring_tests.rb +27 -0
  48. data/test/geometry/extract_unique_points_tests.rb +41 -0
  49. data/test/geometry/frecet_distance_tests.rb +24 -0
  50. data/test/geometry/get_geometry_n_tests.rb +21 -0
  51. data/test/geometry/hausdorff_distance_tests.rb +46 -0
  52. data/test/geometry/hilbert_code_tests.rb +45 -0
  53. data/test/geometry/interior_ring_n_tests.rb +64 -0
  54. data/test/geometry/interior_rings_tests.rb +36 -0
  55. data/test/geometry/interpolate_tests.rb +49 -0
  56. data/test/geometry/intersection_tests.rb +49 -0
  57. data/test/geometry/largest_empty_circle_tests.rb +26 -0
  58. data/test/geometry/length_tests.rb +18 -0
  59. data/test/geometry/line_merge_directed_tests.rb +28 -0
  60. data/test/geometry/line_merge_tests.rb +25 -0
  61. data/test/geometry/line_string_enumerator_tests.rb +20 -0
  62. data/test/geometry/line_substring_tests.rb +76 -0
  63. data/test/geometry/make_valid_tests.rb +27 -0
  64. data/test/geometry/maximum_inscribed_circle_tests.rb +21 -0
  65. data/test/geometry/minimum_bounding_circle_tests.rb +23 -0
  66. data/test/geometry/minimum_clearance_tests.rb +58 -0
  67. data/test/geometry/minimum_rotated_rectangle_tests.rb +28 -0
  68. data/test/geometry/minimum_width_tests.rb +26 -0
  69. data/test/geometry/misc_tests.rb +24 -0
  70. data/test/geometry/nearest_points_tests.rb +46 -0
  71. data/test/geometry/node_tests.rb +22 -0
  72. data/test/geometry/normalize_tests.rb +34 -0
  73. data/test/geometry/num_coordinates_tests.rb +39 -0
  74. data/test/geometry/num_goemetries_tests.rb +35 -0
  75. data/test/geometry/num_interior_rings_tests.rb +28 -0
  76. data/test/geometry/orient_polygons_tests.rb +101 -0
  77. data/test/geometry/point_on_surface_tests.rb +37 -0
  78. data/test/geometry/polygon_hull_simplify_tests.rb +55 -0
  79. data/test/geometry/polygonize_tests.rb +173 -0
  80. data/test/geometry/precision_tests.rb +42 -0
  81. data/test/geometry/project_tests.rb +56 -0
  82. data/test/geometry/relate_tests.rb +73 -0
  83. data/test/geometry/relationships_tests.rb +138 -0
  84. data/test/geometry/reverse_tests.rb +44 -0
  85. data/test/geometry/ring_tests.rb +18 -0
  86. data/test/geometry/shared_path_tests.rb +31 -0
  87. data/test/geometry/simple_tests.rb +18 -0
  88. data/test/geometry/simplify_tests.rb +21 -0
  89. data/test/geometry/snap_tests.rb +20 -0
  90. data/test/geometry/srid_copy_policy_tests.rb +94 -0
  91. data/test/geometry/start_and_end_point_tests.rb +24 -0
  92. data/test/geometry/sym_difference_tests.rb +114 -0
  93. data/test/geometry/topology_preserve_simplify_tests.rb +21 -0
  94. data/test/geometry/union_tests.rb +216 -0
  95. data/test/geometry/valid_tests.rb +56 -0
  96. data/test/geometry/voronoi_diagram_tests.rb +62 -0
  97. data/test/geometry_collection_tests.rb +14 -2
  98. data/test/interrupt_tests.rb +1 -1
  99. data/test/line_string_tests.rb +24 -3
  100. data/test/misc_tests.rb +1 -1
  101. data/test/point/has_m_tests.rb +43 -0
  102. data/test/point/x_y_z_m_tests.rb +51 -0
  103. data/test/point_tests.rb +25 -3
  104. data/test/polygon_tests.rb +14 -1
  105. data/test/prepared_geometry_tests.rb +31 -0
  106. data/test/strtree_tests.rb +11 -18
  107. data/test/test_helper.rb +2 -0
  108. data/test/tools_tests.rb +7 -0
  109. data/test/utils_tests.rb +14 -3
  110. data/test/wkb_reader_tests.rb +1 -0
  111. data/test/wkb_writer_tests.rb +46 -5
  112. data/test/wkt_reader_tests.rb +2 -0
  113. data/test/wkt_writer_tests.rb +20 -2
  114. metadata +160 -7
  115. data/test/geometry_tests.rb +0 -2096
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometryRelationshipsTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_relationships
14
+ tester = lambda { |geom_a, geom_b, tests|
15
+ tests.each do |test|
16
+ expected, method, args = test
17
+
18
+ next unless ENV['FORCE_TESTS'] || geom_a.respond_to?(method)
19
+
20
+ value = geom_a.send(method, *([geom_b] + Array(args)))
21
+
22
+ assert_equal(expected, value)
23
+ end
24
+ }
25
+
26
+ tester[read('POINT(0 0)'), read('POINT(0 0)'), [
27
+ [false, :disjoint?],
28
+ [false, :touches?],
29
+ [true, :intersects?],
30
+ [false, :crosses?],
31
+ [true, :within?],
32
+ [true, :contains?],
33
+ [false, :overlaps?],
34
+ [true, :eql?],
35
+ [true, :eql_exact?, TOLERANCE],
36
+ [true, :covers?],
37
+ [true, :covered_by?]
38
+ ]]
39
+
40
+ tester[read('POINT(0 0)'), read('LINESTRING(0 0, 10 0)'), [
41
+ [false, :disjoint?],
42
+ [true, :touches?],
43
+ [true, :intersects?],
44
+ [false, :crosses?],
45
+ [false, :within?],
46
+ [false, :contains?],
47
+ [false, :overlaps?],
48
+ [false, :eql?],
49
+ [false, :eql_exact?, TOLERANCE],
50
+ [false, :covers?],
51
+ [true, :covered_by?]
52
+ ]]
53
+
54
+ tester[read('POINT(5 0)'), read('LINESTRING(0 0, 10 0)'), [
55
+ [false, :disjoint?],
56
+ [false, :touches?],
57
+ [true, :intersects?],
58
+ [false, :crosses?],
59
+ [true, :within?],
60
+ [false, :contains?],
61
+ [false, :overlaps?],
62
+ [false, :eql?],
63
+ [false, :eql_exact?, TOLERANCE],
64
+ [false, :covers?],
65
+ [true, :covered_by?]
66
+ ]]
67
+
68
+ tester[read('LINESTRING(5 -5, 5 5)'), read('LINESTRING(0 0, 10 0)'), [
69
+ [false, :disjoint?],
70
+ [false, :touches?],
71
+ [true, :intersects?],
72
+ [true, :crosses?],
73
+ [false, :within?],
74
+ [false, :contains?],
75
+ [false, :overlaps?],
76
+ [false, :eql?],
77
+ [false, :eql_exact?, TOLERANCE],
78
+ [false, :covers?],
79
+ [false, :covered_by?]
80
+ ]]
81
+
82
+ tester[read('LINESTRING(5 0, 15 0)'), read('LINESTRING(0 0, 10 0)'), [
83
+ [false, :disjoint?],
84
+ [false, :touches?],
85
+ [true, :intersects?],
86
+ [false, :crosses?],
87
+ [false, :within?],
88
+ [false, :contains?],
89
+ [true, :overlaps?],
90
+ [false, :eql?],
91
+ [false, :eql_exact?, TOLERANCE],
92
+ [false, :covers?],
93
+ [false, :covered_by?]
94
+ ]]
95
+
96
+ tester[read('LINESTRING(0 0, 5 0, 10 0)'), read('LINESTRING(0 0, 10 0)'), [
97
+ [false, :disjoint?],
98
+ [false, :touches?],
99
+ [true, :intersects?],
100
+ [false, :crosses?],
101
+ [true, :within?],
102
+ [true, :contains?],
103
+ [false, :overlaps?],
104
+ [true, :eql?],
105
+ [false, :eql_exact?, TOLERANCE],
106
+ [true, :covers?],
107
+ [true, :covered_by?]
108
+ ]]
109
+
110
+ tester[read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'), read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'), [
111
+ [false, :disjoint?],
112
+ [false, :touches?],
113
+ [true, :intersects?],
114
+ [false, :crosses?],
115
+ [false, :within?],
116
+ [false, :contains?],
117
+ [true, :overlaps?],
118
+ [false, :eql?],
119
+ [false, :eql_exact?, TOLERANCE],
120
+ [false, :covers?],
121
+ [false, :covered_by?]
122
+ ]]
123
+
124
+ tester[read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'), read('POINT(15 15)'), [
125
+ [true, :disjoint?],
126
+ [false, :touches?],
127
+ [false, :intersects?],
128
+ [false, :crosses?],
129
+ [false, :within?],
130
+ [false, :contains?],
131
+ [false, :overlaps?],
132
+ [false, :eql?],
133
+ [false, :eql_exact?, TOLERANCE],
134
+ [false, :covers?],
135
+ [false, :covered_by?]
136
+ ]]
137
+ end
138
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometryReverseTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_reverse
14
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:reverse)
15
+
16
+ simple_tester(:reverse, 'POINT (3 5)', 'POINT (3 5)')
17
+
18
+ if Geos::GEOS_NICE_VERSION >= '031200'
19
+ simple_tester(:reverse, 'MULTIPOINT ((100 100), (10 100), (30 100))', 'MULTIPOINT (100 100, 10 100, 30 100)')
20
+ else
21
+ simple_tester(:reverse, 'MULTIPOINT (100 100, 10 100, 30 100)', 'MULTIPOINT (100 100, 10 100, 30 100)')
22
+ end
23
+
24
+ simple_tester(:reverse, 'LINESTRING (200 200, 200 100)', 'LINESTRING (200 100, 200 200)')
25
+
26
+ if Geos::GEOS_NICE_VERSION >= '030801'
27
+ simple_tester(:reverse, 'MULTILINESTRING ((3 3, 4 4), (1 1, 2 2))', 'MULTILINESTRING ((4 4, 3 3), (2 2, 1 1))')
28
+ else
29
+ simple_tester(:reverse, 'MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))', 'MULTILINESTRING ((4 4, 3 3), (2 2, 1 1))')
30
+ end
31
+
32
+ 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))')
33
+ 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)))')
34
+ 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)))')
35
+ simple_tester(:reverse, 'POINT EMPTY', 'POINT EMPTY')
36
+ simple_tester(:reverse, 'LINESTRING EMPTY', 'LINESTRING EMPTY')
37
+ simple_tester(:reverse, 'LINEARRING EMPTY', 'LINEARRING EMPTY')
38
+ simple_tester(:reverse, 'POLYGON EMPTY', 'POLYGON EMPTY')
39
+ simple_tester(:reverse, 'MULTIPOINT EMPTY', 'MULTIPOINT EMPTY')
40
+ simple_tester(:reverse, 'MULTILINESTRING EMPTY', 'MULTILINESTRING EMPTY')
41
+ simple_tester(:reverse, 'MULTIPOLYGON EMPTY', 'MULTIPOLYGON EMPTY')
42
+ simple_tester(:reverse, 'GEOMETRYCOLLECTION EMPTY', 'GEOMETRYCOLLECTION EMPTY')
43
+ end
44
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometryRingTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_ring
14
+ refute_geom_ring(read('POINT(0 0)'))
15
+ refute_geom_ring(read('LINESTRING(0 0, 10 0, 5 5, 5 -5)'))
16
+ assert_geom_ring(read('LINESTRING(0 0, 10 0, 5 5, 0 0)'))
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometrySharedPathTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_shared_paths
14
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:shared_paths)
15
+
16
+ geom_a = read('LINESTRING(0 0, 50 0)')
17
+ geom_b = read('MULTILINESTRING((5 0, 15 0),(40 0, 30 0))')
18
+
19
+ paths = geom_a.shared_paths(geom_b)
20
+
21
+ assert_equal(2, paths.length)
22
+ assert_equal(
23
+ 'MULTILINESTRING ((5 0, 15 0))',
24
+ write(paths[0])
25
+ )
26
+ assert_equal(
27
+ 'MULTILINESTRING ((30 0, 40 0))',
28
+ write(paths[1])
29
+ )
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometrySimpleTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_simple
14
+ assert_geom_simple(read('POINT(0 0)'))
15
+ assert_geom_simple(read('LINESTRING(0 0, 10 0)'))
16
+ refute_geom_simple(read('LINESTRING(0 0, 10 0, 5 5, 5 -5)'))
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometrySimplifyTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_simplify
14
+ simple_tester(
15
+ :simplify,
16
+ 'LINESTRING (0 0, 5 10, 10 0, 10 9, 0 9)',
17
+ 'LINESTRING(0 0, 3 4, 5 10, 10 0, 10 9, 5 11, 0 9)',
18
+ 2
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometrySnapTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_snap
14
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:snap)
15
+
16
+ geom = read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
17
+ simple_tester(:snap, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', geom, read('POINT(0.1 0)'), 0)
18
+ simple_tester(:snap, 'POLYGON ((0.1 0, 1 0, 1 1, 0 1, 0.1 0))', geom, read('POINT(0.1 0)'), 0.5)
19
+ end
20
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometrySridCopyPolicyTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_srid_copy_policy
14
+ geom = read('POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))')
15
+ geom.srid = 4326
16
+
17
+ Geos.srid_copy_policy = :zero
18
+ cloned = geom.clone
19
+
20
+ assert_equal(4326, cloned.srid)
21
+
22
+ Geos.srid_copy_policy = :lenient
23
+ cloned = geom.clone
24
+
25
+ assert_equal(4326, cloned.srid)
26
+
27
+ Geos.srid_copy_policy = :strict
28
+ cloned = geom.clone
29
+
30
+ assert_equal(4326, cloned.srid)
31
+
32
+ Geos.srid_copy_policy = :zero
33
+ geom_b = geom.convex_hull
34
+
35
+ assert_equal(0, geom_b.srid)
36
+
37
+ Geos.srid_copy_policy = :lenient
38
+ geom_b = geom.convex_hull
39
+
40
+ assert_equal(4326, geom_b.srid)
41
+
42
+ Geos.srid_copy_policy = :strict
43
+ geom_b = geom.convex_hull
44
+
45
+ assert_equal(4326, geom_b.srid)
46
+
47
+ geom_b = read('POLYGON ((3 3, 3 8, 8 8, 8 3, 3 3))')
48
+ geom_b.srid = 3875
49
+
50
+ Geos.srid_copy_policy = :zero
51
+ geom_c = geom.intersection(geom_b)
52
+
53
+ assert_equal(0, geom_c.srid)
54
+
55
+ Geos.srid_copy_policy = :lenient
56
+ geom_c = geom.intersection(geom_b)
57
+
58
+ assert_equal(4326, geom_c.srid)
59
+
60
+ Geos.srid_copy_policy = :strict
61
+
62
+ assert_raises(Geos::MixedSRIDsError) do
63
+ geom.intersection(geom_b)
64
+ end
65
+ ensure
66
+ Geos.srid_copy_policy = :default
67
+ end
68
+
69
+ def test_bad_srid_copy_policy
70
+ assert_raises(ArgumentError) do
71
+ Geos.srid_copy_policy = :blart
72
+ end
73
+ end
74
+
75
+ def test_srid_copy_policy_default
76
+ Geos.srid_copy_policy_default = :default
77
+
78
+ assert_equal(:zero, Geos.srid_copy_policy_default)
79
+
80
+ Geos.srid_copy_policy_default = :lenient
81
+
82
+ assert_equal(:lenient, Geos.srid_copy_policy_default)
83
+
84
+ Geos.srid_copy_policy_default = :strict
85
+
86
+ assert_equal(:strict, Geos.srid_copy_policy_default)
87
+
88
+ assert_raises(ArgumentError) do
89
+ Geos.srid_copy_policy_default = :blart
90
+ end
91
+ ensure
92
+ Geos.srid_copy_policy_default = :default
93
+ end
94
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometryStartAndEndPointTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_start_and_end_points
14
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:start_point)
15
+
16
+ geom = read('LINESTRING (10 10, 10 14, 14 14, 14 10)')
17
+ simple_tester(:start_point, 'POINT (10 10)', geom)
18
+ simple_tester(:end_point, 'POINT (14 10)', geom)
19
+
20
+ geom = read('LINEARRING (11 11, 11 12, 12 11, 11 11)')
21
+ simple_tester(:start_point, 'POINT (11 11)', geom)
22
+ simple_tester(:start_point, 'POINT (11 11)', geom)
23
+ end
24
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometrySymDifferenceTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_sym_difference
14
+ %w{ sym_difference symmetric_difference }.each do |method|
15
+ comparison_tester(
16
+ method,
17
+ EMPTY_GEOMETRY,
18
+ 'POINT(0 0)',
19
+ 'POINT(0 0)'
20
+ )
21
+
22
+ comparison_tester(
23
+ method,
24
+ if Geos::GEOS_NICE_VERSION >= '031200'
25
+ 'MULTIPOINT ((0 0), (1 0))'
26
+ else
27
+ 'MULTIPOINT (0 0, 1 0)'
28
+ end,
29
+ 'POINT(0 0)',
30
+ 'POINT(1 0)'
31
+ )
32
+
33
+ comparison_tester(
34
+ method,
35
+ 'LINESTRING (0 0, 10 0)',
36
+ 'LINESTRING(0 0, 10 0)',
37
+ 'POINT(5 0)'
38
+ )
39
+
40
+ comparison_tester(
41
+ method,
42
+ 'LINESTRING (0 0, 10 0)',
43
+ 'POINT(5 0)',
44
+ 'LINESTRING(0 0, 10 0)'
45
+ )
46
+
47
+ comparison_tester(
48
+ method,
49
+ 'GEOMETRYCOLLECTION (POINT (5 0), LINESTRING (0 1, 10 1))',
50
+ 'POINT(5 0)',
51
+ 'LINESTRING(0 1, 10 1)'
52
+ )
53
+
54
+ comparison_tester(
55
+ method,
56
+ 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))',
57
+ 'LINESTRING(0 0, 10 0)',
58
+ 'LINESTRING(5 -10, 5 10)'
59
+ )
60
+
61
+ comparison_tester(
62
+ method,
63
+ 'MULTILINESTRING ((0 0, 5 0), (10 0, 20 0))',
64
+ 'LINESTRING(0 0, 10 0)',
65
+ 'LINESTRING(5 0, 20 0)'
66
+ )
67
+
68
+ comparison_tester(
69
+ method,
70
+ if Geos::GEOS_NICE_VERSION > '030900'
71
+ 'GEOMETRYCOLLECTION (POLYGON ((0 10, 5 10, 10 10, 10 0, 5 0, 0 0, 0 10)), LINESTRING (5 -10, 5 0))'
72
+ else
73
+ 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)))'
74
+ end,
75
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
76
+ 'LINESTRING(5 -10, 5 10)'
77
+ )
78
+
79
+ comparison_tester(
80
+ method,
81
+ if Geos::GEOS_NICE_VERSION > '030900'
82
+ 'GEOMETRYCOLLECTION (POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10)), LINESTRING (10 0, 20 0))'
83
+ else
84
+ 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)))'
85
+ end,
86
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
87
+ 'LINESTRING(10 0, 20 0)'
88
+ )
89
+
90
+ comparison_tester(
91
+ method,
92
+ if Geos::GEOS_NICE_VERSION > '030900'
93
+ '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)))'
94
+ else
95
+ '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)))'
96
+ end,
97
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
98
+ 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
99
+ )
100
+ end
101
+ end
102
+
103
+ def test_sym_difference_with_precision
104
+ skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSSymDifferencePrec_r)
105
+
106
+ comparison_tester(
107
+ :sym_difference,
108
+ 'GEOMETRYCOLLECTION (POLYGON ((0 10, 6 10, 10 10, 10 0, 6 0, 0 0, 0 10)), LINESTRING (6 -10, 6 0))',
109
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
110
+ 'LINESTRING(5 -10, 5 10)',
111
+ precision: 2
112
+ )
113
+ end
114
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class GeometryTests < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ super
10
+ writer.trim = true
11
+ end
12
+
13
+ def test_topology_preserve_simplify
14
+ simple_tester(
15
+ :topology_preserve_simplify,
16
+ 'LINESTRING (0 0, 5 10, 10 0, 10 9, 5 11, 0 9)',
17
+ 'LINESTRING(0 0, 3 4, 5 10, 10 0, 10 9, 5 11, 0 9)',
18
+ 2
19
+ )
20
+ end
21
+ end