ffi-geos 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +2 -2
  3. data/.rbenv-vars +1 -0
  4. data/.rubocop.yml +538 -92
  5. data/.rubocop_todo.yml +28 -18
  6. data/ffi-geos.gemspec +2 -2
  7. data/lib/ffi-geos/coordinate_sequence.rb +2 -1
  8. data/lib/ffi-geos/geometry.rb +95 -1
  9. data/lib/ffi-geos/point.rb +9 -0
  10. data/lib/ffi-geos/version.rb +1 -1
  11. data/lib/ffi-geos.rb +78 -3
  12. data/test/coordinate_sequence_tests.rb +22 -4
  13. data/test/geojson_reader_tests.rb +6 -2
  14. data/test/geometry/area_tests.rb +18 -0
  15. data/test/geometry/boundary_tests.rb +36 -0
  16. data/test/geometry/buffer_tests.rb +116 -0
  17. data/test/geometry/build_area_tests.rb +20 -0
  18. data/test/geometry/centroid_tests.rb +37 -0
  19. data/test/geometry/clip_by_rect_tests.rb +56 -0
  20. data/test/geometry/clone_tests.rb +29 -0
  21. data/test/geometry/concave_hull_of_polygons_tests.rb +28 -0
  22. data/test/geometry/concave_hull_tests.rb +38 -0
  23. data/test/geometry/convex_hull_tests.rb +26 -0
  24. data/test/geometry/coord_seq_tests.rb +27 -0
  25. data/test/geometry/delaunay_triangulation_tests.rb +82 -0
  26. data/test/geometry/densify_tests.rb +95 -0
  27. data/test/geometry/difference_tests.rb +108 -0
  28. data/test/geometry/dimensions_tests.rb +46 -0
  29. data/test/geometry/distance_tests.rb +29 -0
  30. data/test/geometry/dump_points_tests.rb +60 -0
  31. data/test/geometry/dup_tests.rb +29 -0
  32. data/test/geometry/empty_tests.rb +23 -0
  33. data/test/geometry/envelope_tests.rb +26 -0
  34. data/test/geometry/equal_identical_tests.rb +78 -0
  35. data/test/geometry/equal_tests.rb +62 -0
  36. data/test/geometry/exterior_ring_tests.rb +27 -0
  37. data/test/geometry/extract_unique_points_tests.rb +41 -0
  38. data/test/geometry/frecet_distance_tests.rb +24 -0
  39. data/test/geometry/get_geometry_n_tests.rb +21 -0
  40. data/test/geometry/hausdorff_distance_tests.rb +46 -0
  41. data/test/geometry/hilbert_code_tests.rb +45 -0
  42. data/test/geometry/interior_ring_n_tests.rb +64 -0
  43. data/test/geometry/interior_rings_tests.rb +36 -0
  44. data/test/geometry/interpolate_tests.rb +49 -0
  45. data/test/geometry/intersection_tests.rb +49 -0
  46. data/test/geometry/largest_empty_circle_tests.rb +26 -0
  47. data/test/geometry/length_tests.rb +18 -0
  48. data/test/geometry/line_merge_directed_tests.rb +28 -0
  49. data/test/geometry/line_merge_tests.rb +25 -0
  50. data/test/geometry/line_string_enumerator_tests.rb +20 -0
  51. data/test/geometry/line_substring_tests.rb +76 -0
  52. data/test/geometry/make_valid_tests.rb +27 -0
  53. data/test/geometry/maximum_inscribed_circle_tests.rb +21 -0
  54. data/test/geometry/minimum_bounding_circle_tests.rb +23 -0
  55. data/test/geometry/minimum_clearance_tests.rb +58 -0
  56. data/test/geometry/minimum_rotated_rectangle_tests.rb +28 -0
  57. data/test/geometry/minimum_width_tests.rb +26 -0
  58. data/test/geometry/misc_tests.rb +24 -0
  59. data/test/geometry/nearest_points_tests.rb +46 -0
  60. data/test/geometry/node_tests.rb +22 -0
  61. data/test/geometry/normalize_tests.rb +34 -0
  62. data/test/geometry/num_coordinates_tests.rb +39 -0
  63. data/test/geometry/num_goemetries_tests.rb +35 -0
  64. data/test/geometry/num_interior_rings_tests.rb +28 -0
  65. data/test/geometry/orient_polygons_tests.rb +101 -0
  66. data/test/geometry/point_on_surface_tests.rb +37 -0
  67. data/test/geometry/polygon_hull_simplify_tests.rb +55 -0
  68. data/test/geometry/polygonize_tests.rb +173 -0
  69. data/test/geometry/precision_tests.rb +42 -0
  70. data/test/geometry/project_tests.rb +56 -0
  71. data/test/geometry/relate_tests.rb +73 -0
  72. data/test/geometry/relationships_tests.rb +138 -0
  73. data/test/geometry/reverse_tests.rb +44 -0
  74. data/test/geometry/ring_tests.rb +18 -0
  75. data/test/geometry/shared_path_tests.rb +31 -0
  76. data/test/geometry/simple_tests.rb +18 -0
  77. data/test/geometry/simplify_tests.rb +21 -0
  78. data/test/geometry/snap_tests.rb +20 -0
  79. data/test/geometry/srid_copy_policy_tests.rb +94 -0
  80. data/test/geometry/start_and_end_point_tests.rb +24 -0
  81. data/test/geometry/sym_difference_tests.rb +114 -0
  82. data/test/geometry/topology_preserve_simplify_tests.rb +21 -0
  83. data/test/geometry/union_tests.rb +216 -0
  84. data/test/geometry/valid_tests.rb +56 -0
  85. data/test/geometry/voronoi_diagram_tests.rb +62 -0
  86. data/test/geometry_collection_tests.rb +14 -2
  87. data/test/interrupt_tests.rb +1 -1
  88. data/test/line_string_tests.rb +24 -3
  89. data/test/misc_tests.rb +1 -1
  90. data/test/point/has_m_tests.rb +43 -0
  91. data/test/point/x_y_z_m_tests.rb +51 -0
  92. data/test/point_tests.rb +25 -3
  93. data/test/polygon_tests.rb +14 -1
  94. data/test/prepared_geometry_tests.rb +6 -5
  95. data/test/strtree_tests.rb +11 -18
  96. data/test/test_helper.rb +2 -0
  97. data/test/tools_tests.rb +7 -0
  98. data/test/utils_tests.rb +14 -3
  99. data/test/wkb_reader_tests.rb +1 -0
  100. data/test/wkb_writer_tests.rb +26 -5
  101. data/test/wkt_reader_tests.rb +2 -0
  102. data/test/wkt_writer_tests.rb +20 -2
  103. metadata +154 -7
  104. data/test/geometry_tests.rb +0 -2114
@@ -1,2114 +0,0 @@
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_intersection
14
- comparison_tester(
15
- :intersection,
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,
21
- 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))',
22
- 'POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'
23
- )
24
- end
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
-
50
- def test_buffer
51
- simple_tester(
52
- :buffer,
53
- 'POLYGON EMPTY',
54
- 'POINT(0 0)',
55
- 0
56
- )
57
-
58
- snapped_tester(
59
- :buffer,
60
- 'POLYGON ((10 0, 10 -2, 9 -4, 8 -6, 7 -7, 6 -8, 4 -9, 2 -10, 0 -10, -2 -10, -4 -9, -6 -8, -7 -7, -8 -6, -9 -4, -10 -2, -10 0, -10 2, -9 4, -8 6, -7 7, -6 8, -4 9, -2 10, 0 10, 2 10, 4 9, 6 8, 7 7, 8 6, 9 4, 10 2, 10 0))',
61
- 'POINT(0 0)',
62
- 10
63
- )
64
-
65
- # One segment per quadrant
66
- snapped_tester(
67
- :buffer,
68
- 'POLYGON ((10 0, 0 -10, -10 0, 0 10, 10 0))',
69
- 'POINT(0 0)',
70
- 10,
71
- quad_segs: 1
72
- )
73
-
74
- # End cap styles
75
- snapped_tester(
76
- :buffer,
77
- 'POLYGON ((100 10, 110 0, 100 -10, 0 -10, -10 0, 0 10, 100 10))',
78
- 'LINESTRING(0 0, 100 0)',
79
- 10,
80
- quad_segs: 1, endcap: :round
81
- )
82
-
83
- snapped_tester(
84
- :buffer,
85
- 'POLYGON ((100 10, 100 -10, 0 -10, 0 10, 100 10))',
86
- 'LINESTRING(0 0, 100 0)',
87
- 10,
88
- quad_segs: 1, endcap: :flat
89
- )
90
-
91
- snapped_tester(
92
- :buffer,
93
- 'POLYGON ((100 10, 110 10, 110 -10, 0 -10, -10 -10, -10 10, 100 10))',
94
- 'LINESTRING(0 0, 100 0)',
95
- 10,
96
- quad_segs: 1, endcap: :square
97
- )
98
-
99
- # Join styles
100
- snapped_tester(
101
- :buffer,
102
- 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 0, 107 -7, 100 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))',
103
- 'LINESTRING(0 0, 100 0, 100 100)',
104
- 10,
105
- quad_segs: 2, join: :round
106
- )
107
-
108
- snapped_tester(
109
- :buffer,
110
- 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 0, 100 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))',
111
- 'LINESTRING(0 0, 100 0, 100 100)',
112
- 10,
113
- quad_segs: 2, join: :bevel
114
- )
115
-
116
- snapped_tester(
117
- :buffer,
118
- 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))',
119
- 'LINESTRING(0 0, 100 0, 100 100)',
120
- 10,
121
- quad_segs: 2, join: :mitre
122
- )
123
-
124
- snapped_tester(
125
- :buffer,
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,
131
- 'LINESTRING(0 0, 100 0, 100 100)',
132
- 10,
133
- quad_segs: 2, join: :mitre, mitre_limit: 1.0
134
- )
135
-
136
- # Single-sided buffering
137
- snapped_tester(
138
- :buffer,
139
- 'POLYGON ((100 0, 0 0, 0 10, 100 10, 100 0))',
140
- 'LINESTRING(0 0, 100 0)',
141
- 10,
142
- single_sided: true
143
- )
144
-
145
- snapped_tester(
146
- :buffer,
147
- 'POLYGON ((0 0, 100 0, 100 -10, 0 -10, 0 0))',
148
- 'LINESTRING(0 0, 100 0)',
149
- -10,
150
- single_sided: true
151
- )
152
- end
153
-
154
- def test_convex_hull
155
- geom = read('POINT(0 0)')
156
- assert_geom_eql_exact(read('POINT(0 0)'), geom.convex_hull)
157
-
158
- geom = read('LINESTRING(0 0, 10 10)')
159
- assert_geom_eql_exact(read('LINESTRING(0 0, 10 10)'), geom.convex_hull)
160
-
161
- geom = read('POLYGON((0 0, 0 10, 5 5, 10 10, 10 0, 0 0))')
162
- assert_geom_eql_exact(read('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'), geom.convex_hull)
163
- end
164
-
165
- def test_difference
166
- comparison_tester(
167
- :difference,
168
- EMPTY_GEOMETRY,
169
- 'POINT(0 0)',
170
- 'POINT(0 0)'
171
- )
172
-
173
- comparison_tester(
174
- :difference,
175
- 'POINT (0 0)',
176
- 'POINT(0 0)',
177
- 'POINT(1 0)'
178
- )
179
-
180
- comparison_tester(
181
- :difference,
182
- 'LINESTRING (0 0, 10 0)',
183
- 'LINESTRING(0 0, 10 0)',
184
- 'POINT(5 0)'
185
- )
186
-
187
- comparison_tester(
188
- :difference,
189
- EMPTY_GEOMETRY,
190
- 'POINT(5 0)',
191
- 'LINESTRING(0 0, 10 0)'
192
- )
193
-
194
- comparison_tester(
195
- :difference,
196
- 'POINT (5 0)',
197
- 'POINT(5 0)',
198
- 'LINESTRING(0 1, 10 1)'
199
- )
200
-
201
- comparison_tester(
202
- :difference,
203
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0))',
204
- 'LINESTRING(0 0, 10 0)',
205
- 'LINESTRING(5 -10, 5 10)'
206
- )
207
-
208
- comparison_tester(
209
- :difference,
210
- 'LINESTRING (0 0, 5 0)',
211
- 'LINESTRING(0 0, 10 0)',
212
- 'LINESTRING(5 0, 20 0)'
213
- )
214
-
215
- comparison_tester(
216
- :difference,
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,
222
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
223
- 'LINESTRING(5 -10, 5 10)'
224
- )
225
-
226
- comparison_tester(
227
- :difference,
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,
233
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
234
- 'LINESTRING(10 0, 20 0)'
235
- )
236
-
237
- comparison_tester(
238
- :difference,
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,
244
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
245
- 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
246
- )
247
- end
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
-
261
- def test_sym_difference
262
- %w{ sym_difference symmetric_difference }.each do |method|
263
- comparison_tester(
264
- method,
265
- EMPTY_GEOMETRY,
266
- 'POINT(0 0)',
267
- 'POINT(0 0)'
268
- )
269
-
270
- comparison_tester(
271
- method,
272
- 'MULTIPOINT (0 0, 1 0)',
273
- 'POINT(0 0)',
274
- 'POINT(1 0)'
275
- )
276
-
277
- comparison_tester(
278
- method,
279
- 'LINESTRING (0 0, 10 0)',
280
- 'LINESTRING(0 0, 10 0)',
281
- 'POINT(5 0)'
282
- )
283
-
284
- comparison_tester(
285
- method,
286
- 'LINESTRING (0 0, 10 0)',
287
- 'POINT(5 0)',
288
- 'LINESTRING(0 0, 10 0)'
289
- )
290
-
291
- comparison_tester(
292
- method,
293
- 'GEOMETRYCOLLECTION (POINT (5 0), LINESTRING (0 1, 10 1))',
294
- 'POINT(5 0)',
295
- 'LINESTRING(0 1, 10 1)'
296
- )
297
-
298
- comparison_tester(
299
- method,
300
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))',
301
- 'LINESTRING(0 0, 10 0)',
302
- 'LINESTRING(5 -10, 5 10)'
303
- )
304
-
305
- comparison_tester(
306
- method,
307
- 'MULTILINESTRING ((0 0, 5 0), (10 0, 20 0))',
308
- 'LINESTRING(0 0, 10 0)',
309
- 'LINESTRING(5 0, 20 0)'
310
- )
311
-
312
- comparison_tester(
313
- method,
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,
319
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
320
- 'LINESTRING(5 -10, 5 10)'
321
- )
322
-
323
- comparison_tester(
324
- method,
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,
330
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
331
- 'LINESTRING(10 0, 20 0)'
332
- )
333
-
334
- comparison_tester(
335
- method,
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,
341
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
342
- 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
343
- )
344
- end
345
- end
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
-
359
- def test_boundary
360
- simple_tester(
361
- :boundary,
362
- 'GEOMETRYCOLLECTION EMPTY',
363
- 'POINT(0 0)'
364
- )
365
-
366
- simple_tester(
367
- :boundary,
368
- 'MULTIPOINT (0 0, 10 10)',
369
- 'LINESTRING(0 0, 10 10)'
370
- )
371
-
372
- simple_tester(
373
- :boundary,
374
- 'MULTILINESTRING ((0 0, 10 0, 10 10, 0 10, 0 0), (5 5, 5 6, 6 6, 6 5, 5 5))',
375
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),( 5 5, 5 6, 6 6, 6 5, 5 5))'
376
- )
377
- end
378
-
379
- def test_union
380
- comparison_tester(
381
- :union,
382
- 'POINT (0 0)',
383
- 'POINT(0 0)',
384
- 'POINT(0 0)'
385
- )
386
-
387
- comparison_tester(
388
- :union,
389
- 'MULTIPOINT (0 0, 1 0)',
390
- 'POINT(0 0)',
391
- 'POINT(1 0)'
392
- )
393
-
394
- comparison_tester(
395
- :union,
396
- 'LINESTRING (0 0, 10 0)',
397
- 'LINESTRING(0 0, 10 0)',
398
- 'POINT(5 0)'
399
- )
400
-
401
- comparison_tester(
402
- :union,
403
- 'LINESTRING (0 0, 10 0)',
404
- 'POINT(5 0)',
405
- 'LINESTRING(0 0, 10 0)'
406
- )
407
-
408
- comparison_tester(
409
- :union,
410
- 'GEOMETRYCOLLECTION (POINT (5 0), LINESTRING (0 1, 10 1))',
411
- 'POINT(5 0)',
412
- 'LINESTRING(0 1, 10 1)'
413
- )
414
-
415
- comparison_tester(
416
- :union,
417
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))',
418
- 'LINESTRING(0 0, 10 0)',
419
- 'LINESTRING(5 -10, 5 10)'
420
- )
421
-
422
- comparison_tester(
423
- :union,
424
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (10 0, 20 0))',
425
- 'LINESTRING(0 0, 10 0)',
426
- 'LINESTRING(5 0, 20 0)'
427
- )
428
-
429
- comparison_tester(
430
- :union,
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,
436
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
437
- 'LINESTRING(5 -10, 5 10)'
438
- )
439
-
440
- comparison_tester(
441
- :union,
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,
447
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
448
- 'LINESTRING(10 0, 20 0)'
449
- )
450
-
451
- comparison_tester(
452
- :union,
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,
458
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
459
- 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
460
- )
461
- end
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
-
474
- def test_union_cascaded
475
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:union_cascaded)
476
-
477
- simple_tester(
478
- :union_cascaded,
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,
484
- 'MULTIPOLYGON(
485
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
486
- ((10 10, 10 14, 14 14, 14 10, 10 10),
487
- (11 11, 11 12, 12 12, 12 11, 11 11)),
488
- ((0 0, 11 0, 11 11, 0 11, 0 0))
489
- ))'
490
- )
491
- end
492
-
493
- def test_coverage_union
494
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:coverage_union)
495
-
496
- simple_tester(
497
- :union_cascaded,
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,
503
- 'MULTIPOLYGON(
504
- ((0 0, 0 1, 1 1, 1 0, 0 0)),
505
- ((1 0, 1 1, 2 1, 2 0, 1 0))
506
- ))'
507
- )
508
- end
509
-
510
- def test_unary_union
511
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:unary_union)
512
-
513
- simple_tester(
514
- :unary_union,
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,
520
- 'MULTIPOLYGON(
521
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
522
- ((10 10, 10 14, 14 14, 14 10, 10 10),
523
- (11 11, 11 12, 12 12, 12 11, 11 11)),
524
- ((0 0, 11 0, 11 11, 0 11, 0 0))
525
- ))'
526
- )
527
- end
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
-
545
- def test_node
546
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:node)
547
-
548
- simple_tester(
549
- :node,
550
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0, 5 -5, 5 0), (5 0, 5 5))',
551
- 'LINESTRING(0 0, 10 0, 5 -5, 5 5)'
552
- )
553
- end
554
-
555
- def test_union_without_arguments
556
- simple_tester(
557
- :union,
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,
563
- 'MULTIPOLYGON(
564
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
565
- ((10 10, 10 14, 14 14, 14 10, 10 10),
566
- (11 11, 11 12, 12 12, 12 11, 11 11)),
567
- ((0 0, 11 0, 11 11, 0 11, 0 0))
568
- ))'
569
- )
570
- end
571
-
572
- def test_point_on_surface_and_representative_point
573
- %w{
574
- point_on_surface
575
- representative_point
576
- }.each do |method|
577
- simple_tester(
578
- method,
579
- 'POINT (0 0)',
580
- 'POINT (0 0)'
581
- )
582
-
583
- simple_tester(
584
- method,
585
- 'POINT (5 0)',
586
- 'LINESTRING(0 0, 5 0, 10 0)'
587
- )
588
-
589
- simple_tester(
590
- method,
591
- 'POINT (5 5)',
592
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'
593
- )
594
- end
595
- end
596
-
597
- def test_clip_by_rect
598
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:clip_by_rect)
599
-
600
- %w{
601
- clip_by_rect
602
- clip_by_rectangle
603
- }.each do |method|
604
- simple_tester(
605
- method,
606
- 'POINT (0 0)',
607
- 'POINT (0 0)',
608
- -1, -1, 1, 1
609
- )
610
-
611
- simple_tester(
612
- method,
613
- 'GEOMETRYCOLLECTION EMPTY',
614
- 'POINT (0 0)',
615
- 0, 0, 2, 2
616
- )
617
-
618
- simple_tester(
619
- method,
620
- 'LINESTRING (1 0, 2 0)',
621
- 'LINESTRING (0 0, 10 0)',
622
- 1, -1, 2, 1
623
- )
624
-
625
- simple_tester(
626
- method,
627
- 'POLYGON ((1 1, 1 5, 5 5, 5 1, 1 1))',
628
- 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))',
629
- 1, 1, 5, 5
630
- )
631
-
632
- simple_tester(
633
- method,
634
- 'POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))',
635
- 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))',
636
- -1, -1, 5, 5
637
- )
638
- end
639
- end
640
-
641
- def test_centroid_and_center
642
- %w{
643
- centroid
644
- center
645
- }.each do |method|
646
- simple_tester(
647
- method,
648
- 'POINT (0 0)',
649
- 'POINT(0 0)'
650
- )
651
-
652
- simple_tester(
653
- method,
654
- 'POINT (5 5)',
655
- 'LINESTRING(0 0, 10 10)'
656
- )
657
-
658
- snapped_tester(
659
- method,
660
- 'POINT (5 4)',
661
- 'POLYGON((0 0, 0 10, 5 5, 10 10, 10 0, 0 0))'
662
- )
663
- end
664
- end
665
-
666
- def test_minimum_bounding_circle
667
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_bounding_circle)
668
-
669
- geom = read('LINESTRING(0 10, 0 20)')
670
-
671
- assert_equal(
672
- '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))',
673
- write(geom.minimum_bounding_circle.snap_to_grid(1))
674
- )
675
- end
676
-
677
- def test_envelope
678
- simple_tester(
679
- :envelope,
680
- 'POINT (0 0)',
681
- 'POINT(0 0)'
682
- )
683
-
684
- simple_tester(
685
- :envelope,
686
- 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))',
687
- 'LINESTRING(0 0, 10 10)'
688
- )
689
- end
690
-
691
- def test_relate
692
- tester = lambda { |expected, geom_a, geom_b|
693
- assert_equal(expected, geom_a.relate(geom_b))
694
- }
695
-
696
- geom_a = read('POINT(0 0)')
697
- geom_b = read('POINT(0 0)')
698
- tester['0FFFFFFF2', geom_a, geom_b]
699
-
700
- geom_a = read('POINT(0 0)')
701
- geom_b = read('POINT(1 0)')
702
- tester['FF0FFF0F2', geom_a, geom_b]
703
-
704
- geom_a = read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))')
705
- geom_b = read('POINT(1 0)')
706
- tester['FF20F1FF2', geom_a, geom_b]
707
- end
708
-
709
- def test_relate_pattern
710
- tester = lambda { |pattern, geom_a, geom_b, expected|
711
- assert_equal(expected, geom_a.relate_pattern(geom_b, pattern))
712
- }
713
-
714
- geom_a = read('POINT(0 0)')
715
- geom_b = read('POINT(0 0)')
716
- tester['0FFFFFFF2', geom_a, geom_b, true]
717
- tester['0*******T', geom_a, geom_b, true]
718
- tester['0*******1', geom_a, geom_b, false]
719
-
720
- geom_a = read('POINT(0 0)')
721
- geom_b = read('POINT(1 0)')
722
- tester['FF0FFF0F2', geom_a, geom_b, true]
723
- tester['F*******2', geom_a, geom_b, true]
724
- tester['T*******2', geom_a, geom_b, false]
725
-
726
- geom_a = read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))')
727
- geom_b = read('POINT(1 0)')
728
- tester['FF20F1FF2', geom_a, geom_b, true]
729
- tester['F****T**T', geom_a, geom_b, true]
730
- tester['T*******2', geom_a, geom_b, false]
731
- end
732
-
733
- def test_relate_boundary_node_rule
734
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:relate_boundary_node_rule)
735
-
736
- geom_a = read('LINESTRING(0 0, 2 4, 5 5, 0 0)')
737
- geom_b = read('POINT(0 0)')
738
-
739
- ret = geom_a.relate_boundary_node_rule(geom_b, :ogc)
740
- assert_equal('0F1FFFFF2', ret)
741
-
742
- ret = geom_a.relate_boundary_node_rule(geom_b, :endpoint)
743
- assert_equal('FF10FFFF2', ret)
744
-
745
- assert_raises(TypeError) do
746
- geom_a.relate_boundary_node_rule(geom_b, :gibberish)
747
- end
748
- end
749
-
750
- def test_line_merge
751
- simple_tester(
752
- :line_merge,
753
- 'LINESTRING (0 0, 10 10, 10 0, 5 0, 5 -5)',
754
- 'MULTILINESTRING(
755
- (0 0, 10 10),
756
- (10 10, 10 0),
757
- (5 0, 10 0),
758
- (5 -5, 5 0)
759
- )'
760
- )
761
- end
762
-
763
- def test_simplify
764
- simple_tester(
765
- :simplify,
766
- 'LINESTRING (0 0, 5 10, 10 0, 10 9, 0 9)',
767
- 'LINESTRING(0 0, 3 4, 5 10, 10 0, 10 9, 5 11, 0 9)',
768
- 2
769
- )
770
- end
771
-
772
- def test_topology_preserve_simplify
773
- simple_tester(
774
- :topology_preserve_simplify,
775
- 'LINESTRING (0 0, 5 10, 10 0, 10 9, 5 11, 0 9)',
776
- 'LINESTRING(0 0, 3 4, 5 10, 10 0, 10 9, 5 11, 0 9)',
777
- 2
778
- )
779
- end
780
-
781
- def test_extract_unique_points
782
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:extract_unique_points)
783
-
784
- geom = read('GEOMETRYCOLLECTION (
785
- MULTIPOLYGON (
786
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
787
- ((10 10, 10 14, 14 14, 14 10, 10 10),
788
- (11 11, 11 12, 12 12, 12 11, 11 11))
789
- ),
790
- POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
791
- MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
792
- LINESTRING (0 0, 2 3),
793
- MULTIPOINT (0 0, 2 3),
794
- POINT (9 0),
795
- POINT(1 0)),
796
- LINESTRING EMPTY
797
- ')
798
-
799
- simple_tester(
800
- :extract_unique_points,
801
- 'MULTIPOINT (0 0, 1 0, 1 1, 0 1, 10 10, 10 14, 14 14, 14 10, 11 11, 11 12, 12 12, 12 11, 2 3, 3 4, 9 0)',
802
- geom.extract_unique_points
803
- )
804
- end
805
-
806
- def test_relationships
807
- tester = lambda { |geom_a, geom_b, tests|
808
- tests.each do |test|
809
- expected, method, args = test
810
- if ENV['FORCE_TESTS'] || geom_a.respond_to?(method)
811
- value = geom_a.send(method, *([geom_b] + Array(args)))
812
- assert_equal(expected, value)
813
- end
814
- end
815
- }
816
-
817
- tester[read('POINT(0 0)'), read('POINT(0 0)'), [
818
- [false, :disjoint?],
819
- [false, :touches?],
820
- [true, :intersects?],
821
- [false, :crosses?],
822
- [true, :within?],
823
- [true, :contains?],
824
- [false, :overlaps?],
825
- [true, :eql?],
826
- [true, :eql_exact?, TOLERANCE],
827
- [true, :covers?],
828
- [true, :covered_by?]
829
- ]]
830
-
831
- tester[read('POINT(0 0)'), read('LINESTRING(0 0, 10 0)'), [
832
- [false, :disjoint?],
833
- [true, :touches?],
834
- [true, :intersects?],
835
- [false, :crosses?],
836
- [false, :within?],
837
- [false, :contains?],
838
- [false, :overlaps?],
839
- [false, :eql?],
840
- [false, :eql_exact?, TOLERANCE],
841
- [false, :covers?],
842
- [true, :covered_by?]
843
- ]]
844
-
845
- tester[read('POINT(5 0)'), read('LINESTRING(0 0, 10 0)'), [
846
- [false, :disjoint?],
847
- [false, :touches?],
848
- [true, :intersects?],
849
- [false, :crosses?],
850
- [true, :within?],
851
- [false, :contains?],
852
- [false, :overlaps?],
853
- [false, :eql?],
854
- [false, :eql_exact?, TOLERANCE],
855
- [false, :covers?],
856
- [true, :covered_by?]
857
- ]]
858
-
859
- tester[read('LINESTRING(5 -5, 5 5)'), read('LINESTRING(0 0, 10 0)'), [
860
- [false, :disjoint?],
861
- [false, :touches?],
862
- [true, :intersects?],
863
- [true, :crosses?],
864
- [false, :within?],
865
- [false, :contains?],
866
- [false, :overlaps?],
867
- [false, :eql?],
868
- [false, :eql_exact?, TOLERANCE],
869
- [false, :covers?],
870
- [false, :covered_by?]
871
- ]]
872
-
873
- tester[read('LINESTRING(5 0, 15 0)'), read('LINESTRING(0 0, 10 0)'), [
874
- [false, :disjoint?],
875
- [false, :touches?],
876
- [true, :intersects?],
877
- [false, :crosses?],
878
- [false, :within?],
879
- [false, :contains?],
880
- [true, :overlaps?],
881
- [false, :eql?],
882
- [false, :eql_exact?, TOLERANCE],
883
- [false, :covers?],
884
- [false, :covered_by?]
885
- ]]
886
-
887
- tester[read('LINESTRING(0 0, 5 0, 10 0)'), read('LINESTRING(0 0, 10 0)'), [
888
- [false, :disjoint?],
889
- [false, :touches?],
890
- [true, :intersects?],
891
- [false, :crosses?],
892
- [true, :within?],
893
- [true, :contains?],
894
- [false, :overlaps?],
895
- [true, :eql?],
896
- [false, :eql_exact?, TOLERANCE],
897
- [true, :covers?],
898
- [true, :covered_by?]
899
- ]]
900
-
901
- 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))'), [
902
- [false, :disjoint?],
903
- [false, :touches?],
904
- [true, :intersects?],
905
- [false, :crosses?],
906
- [false, :within?],
907
- [false, :contains?],
908
- [true, :overlaps?],
909
- [false, :eql?],
910
- [false, :eql_exact?, TOLERANCE],
911
- [false, :covers?],
912
- [false, :covered_by?]
913
- ]]
914
-
915
- tester[read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'), read('POINT(15 15)'), [
916
- [true, :disjoint?],
917
- [false, :touches?],
918
- [false, :intersects?],
919
- [false, :crosses?],
920
- [false, :within?],
921
- [false, :contains?],
922
- [false, :overlaps?],
923
- [false, :eql?],
924
- [false, :eql_exact?, TOLERANCE],
925
- [false, :covers?],
926
- [false, :covered_by?]
927
- ]]
928
- end
929
-
930
- def test_empty
931
- refute_geom_empty(read('POINT(0 0)'))
932
- assert_geom_empty(read('POINT EMPTY'))
933
- refute_geom_empty(read('LINESTRING(0 0, 10 0)'))
934
- assert_geom_empty(read('LINESTRING EMPTY'))
935
- refute_geom_empty(read('POLYGON((0 0, 10 0, 10 10, 0 0))'))
936
- assert_geom_empty(read('POLYGON EMPTY'))
937
- refute_geom_empty(read('GEOMETRYCOLLECTION(POINT(0 0))'))
938
- assert_geom_empty(read('GEOMETRYCOLLECTION EMPTY'))
939
- end
940
-
941
- def test_valid
942
- assert_geom_valid(read('POINT(0 0)'))
943
- refute_geom_valid(read('POINT(0 NaN)'))
944
- refute_geom_valid(read('POINT(0 nan)'))
945
- end
946
-
947
- def test_valid_reason
948
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:valid_reason)
949
-
950
- assert_equal('Valid Geometry', read('POINT(0 0)').valid_reason)
951
- assert_equal('Invalid Coordinate[0 nan]', read('POINT(0 NaN)').valid_reason)
952
- assert_equal('Invalid Coordinate[0 nan]', read('POINT(0 nan)').valid_reason)
953
- assert_equal('Self-intersection[2.5 5]', read('POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))').valid_reason)
954
- end
955
-
956
- def test_valid_detail
957
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:valid_detail)
958
-
959
- tester = lambda { |detail, location, geom, flags|
960
- ret = read(geom).valid_detail(flags)
961
- assert_equal(detail, ret[:detail])
962
- assert_equal(location, write(ret[:location]))
963
- }
964
-
965
- assert_nil(read('POINT(0 0)').valid_detail)
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
-
973
- tester['Self-intersection', 'POINT (2.5 5)', 'POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))', 0]
974
-
975
- tester['Ring Self-intersection', 'POINT (0 0)', 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))', 0]
976
-
977
- assert_nil(
978
- read('POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))').valid_detail(
979
- :allow_selftouching_ring_forming_hole
980
- )
981
- )
982
- end
983
-
984
- def test_simple
985
- assert_geom_simple(read('POINT(0 0)'))
986
- assert_geom_simple(read('LINESTRING(0 0, 10 0)'))
987
- refute_geom_simple(read('LINESTRING(0 0, 10 0, 5 5, 5 -5)'))
988
- end
989
-
990
- def test_ring
991
- refute_geom_ring(read('POINT(0 0)'))
992
- refute_geom_ring(read('LINESTRING(0 0, 10 0, 5 5, 5 -5)'))
993
- assert_geom_ring(read('LINESTRING(0 0, 10 0, 5 5, 0 0)'))
994
- end
995
-
996
- def test_has_z
997
- refute_geom_has_z(read('POINT(0 0)'))
998
- assert_geom_has_z(read('POINT(0 0 0)'))
999
- end
1000
-
1001
- def test_num_geometries
1002
- simple_tester(:num_geometries, 1, 'POINT(0 0)')
1003
- simple_tester(:num_geometries, 2, 'MULTIPOINT (0 1, 2 3)')
1004
- simple_tester(:num_geometries, 1, 'LINESTRING (0 0, 2 3)')
1005
- simple_tester(:num_geometries, 2, 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))')
1006
- simple_tester(:num_geometries, 1, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1007
- simple_tester(:num_geometries, 2, 'MULTIPOLYGON(
1008
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
1009
- ((10 10, 10 14, 14 14, 14 10, 10 10),
1010
- (11 11, 11 12, 12 12, 12 11, 11 11)))')
1011
- simple_tester(:num_geometries, 6, 'GEOMETRYCOLLECTION (
1012
- MULTIPOLYGON (
1013
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
1014
- ((10 10, 10 14, 14 14, 14 10, 10 10),
1015
- (11 11, 11 12, 12 12, 12 11, 11 11))
1016
- ),
1017
- POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
1018
- MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
1019
- LINESTRING (0 0, 2 3),
1020
- MULTIPOINT (0 0, 2 3),
1021
- POINT (9 0))')
1022
- end
1023
-
1024
- # get_geometry_n is segfaulting in the binary GEOS build
1025
- def test_get_geometry_n
1026
- skip unless defined?(Geos::FFIGeos)
1027
-
1028
- simple_tester(:get_geometry_n, 'POINT (0 1)', 'MULTIPOINT (0 1, 2 3)', 0)
1029
- simple_tester(:get_geometry_n, 'POINT (2 3)', 'MULTIPOINT (0 1, 2 3)', 1)
1030
- simple_tester(:get_geometry_n, nil, 'MULTIPOINT (0 1, 2 3)', 2)
1031
- end
1032
-
1033
- def test_num_interior_rings
1034
- simple_tester(:num_interior_rings, 0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1035
- simple_tester(:num_interior_rings, 1, 'POLYGON (
1036
- (10 10, 10 14, 14 14, 14 10, 10 10),
1037
- (11 11, 11 12, 12 12, 12 11, 11 11)
1038
- )')
1039
- simple_tester(:num_interior_rings, 2, 'POLYGON (
1040
- (10 10, 10 14, 14 14, 14 10, 10 10),
1041
- (11 11, 11 12, 12 12, 12 11, 11 11),
1042
- (13 11, 13 12, 13.5 12, 13.5 11, 13 11))')
1043
-
1044
- assert_raises(NoMethodError) do
1045
- read('POINT (0 0)').num_interior_rings
1046
- end
1047
- end
1048
-
1049
- def test_interior_ring_n
1050
- simple_tester(
1051
- :interior_ring_n,
1052
- 'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
1053
- 'POLYGON(
1054
- (10 10, 10 14, 14 14, 14 10, 10 10),
1055
- (11 11, 11 12, 12 12, 12 11, 11 11)
1056
- )',
1057
- 0
1058
- )
1059
-
1060
- simple_tester(
1061
- :interior_ring_n,
1062
- 'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
1063
- 'POLYGON (
1064
- (10 10, 10 14, 14 14, 14 10, 10 10),
1065
- (11 11, 11 12, 12 12, 12 11, 11 11),
1066
- (13 11, 13 12, 13.5 12, 13.5 11, 13 11)
1067
- )',
1068
- 0
1069
- )
1070
-
1071
- simple_tester(
1072
- :interior_ring_n,
1073
- 'LINEARRING (13 11, 13 12, 13.5 12, 13.5 11, 13 11)',
1074
- 'POLYGON (
1075
- (10 10, 10 14, 14 14, 14 10, 10 10),
1076
- (11 11, 11 12, 12 12, 12 11, 11 11),
1077
- (13 11, 13 12, 13.5 12, 13.5 11, 13 11)
1078
- )',
1079
- 1
1080
- )
1081
-
1082
- assert_raises(Geos::IndexBoundsError) do
1083
- simple_tester(
1084
- :interior_ring_n,
1085
- nil,
1086
- 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))',
1087
- 0
1088
- )
1089
- end
1090
-
1091
- assert_raises(NoMethodError) do
1092
- simple_tester(
1093
- :interior_ring_n,
1094
- nil,
1095
- 'POINT (0 0)',
1096
- 0
1097
- )
1098
- end
1099
- end
1100
-
1101
- def test_exterior_ring
1102
- simple_tester(
1103
- :exterior_ring,
1104
- 'LINEARRING (10 10, 10 14, 14 14, 14 10, 10 10)',
1105
- 'POLYGON (
1106
- (10 10, 10 14, 14 14, 14 10, 10 10),
1107
- (11 11, 11 12, 12 12, 12 11, 11 11)
1108
- )'
1109
- )
1110
-
1111
- assert_raises(NoMethodError) do
1112
- read('POINT (0 0)').exterior_ring
1113
- end
1114
- end
1115
-
1116
- def test_interior_rings
1117
- array_tester(
1118
- :interior_rings,
1119
- ['LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)'],
1120
- 'POLYGON(
1121
- (10 10, 10 14, 14 14, 14 10, 10 10),
1122
- (11 11, 11 12, 12 12, 12 11, 11 11)
1123
- )'
1124
- )
1125
-
1126
- array_tester(
1127
- :interior_rings,
1128
- [
1129
- 'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
1130
- 'LINEARRING (13 11, 13 12, 13.5 12, 13.5 11, 13 11)'
1131
- ],
1132
- 'POLYGON (
1133
- (10 10, 10 14, 14 14, 14 10, 10 10),
1134
- (11 11, 11 12, 12 12, 12 11, 11 11),
1135
- (13 11, 13 12, 13.5 12, 13.5 11, 13 11)
1136
- )'
1137
- )
1138
- end
1139
-
1140
- def test_num_coordinates
1141
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:num_coordinates)
1142
-
1143
- simple_tester(:num_coordinates, 1, 'POINT(0 0)')
1144
- simple_tester(:num_coordinates, 2, 'MULTIPOINT (0 1, 2 3)')
1145
- simple_tester(:num_coordinates, 2, 'LINESTRING (0 0, 2 3)')
1146
- simple_tester(:num_coordinates, 4, 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))')
1147
- simple_tester(:num_coordinates, 5, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1148
- simple_tester(:num_coordinates, 15, 'MULTIPOLYGON (
1149
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
1150
- ((10 10, 10 14, 14 14, 14 10, 10 10),
1151
- (11 11, 11 12, 12 12, 12 11, 11 11))
1152
- )')
1153
- simple_tester(:num_coordinates, 29, 'GEOMETRYCOLLECTION (
1154
- MULTIPOLYGON (
1155
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
1156
- ((10 10, 10 14, 14 14, 14 10, 10 10),
1157
- (11 11, 11 12, 12 12, 12 11, 11 11))
1158
- ),
1159
- POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
1160
- MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
1161
- LINESTRING (0 0, 2 3),
1162
- MULTIPOINT ((0 0), (2 3)),
1163
- POINT (9 0)
1164
- )')
1165
- end
1166
-
1167
- def test_coord_seq
1168
- tester = lambda { |expected, g|
1169
- geom = read(g)
1170
- cs = geom.coord_seq
1171
- expected.each_with_index do |c, i|
1172
- assert_equal(c[0], cs.get_x(i))
1173
- assert_equal(c[1], cs.get_y(i))
1174
- end
1175
- }
1176
-
1177
- tester[[[0, 0]], 'POINT(0 0)']
1178
- tester[[[0, 0], [2, 3]], 'LINESTRING (0 0, 2 3)']
1179
- tester[[[0, 0], [0, 5], [5, 5], [5, 0], [0, 0]], 'LINEARRING(0 0, 0 5, 5 5, 5 0, 0 0)']
1180
- end
1181
-
1182
- def test_dimensions
1183
- types = {
1184
- dontcare: -3,
1185
- non_empty: -2,
1186
- empty: -1,
1187
- point: 0,
1188
- curve: 1,
1189
- surface: 2
1190
- }
1191
-
1192
- simple_tester(:dimensions, types[:point], 'POINT(0 0)')
1193
- simple_tester(:dimensions, types[:point], 'MULTIPOINT (0 1, 2 3)')
1194
- simple_tester(:dimensions, types[:curve], 'LINESTRING (0 0, 2 3)')
1195
- simple_tester(:dimensions, types[:curve], 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))')
1196
- simple_tester(:dimensions, types[:surface], 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1197
- simple_tester(:dimensions, types[:surface], 'MULTIPOLYGON (
1198
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
1199
- ((10 10, 10 14, 14 14, 14 10, 10 10),
1200
- (11 11, 11 12, 12 12, 12 11, 11 11))
1201
- )')
1202
- simple_tester(:dimensions, types[:surface], 'GEOMETRYCOLLECTION (
1203
- MULTIPOLYGON (
1204
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
1205
- ((10 10, 10 14, 14 14, 14 10, 10 10),
1206
- (11 11, 11 12, 12 12, 12 11, 11 11))
1207
- ),
1208
- POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
1209
- MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
1210
- LINESTRING (0 0, 2 3),
1211
- MULTIPOINT (0 0, 2 3),
1212
- POINT (9 0)
1213
- )')
1214
- end
1215
-
1216
- def test_project_and_project_normalized
1217
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:project)
1218
-
1219
- geom_a = read('POINT(1 2)')
1220
- geom_b = read('POINT(3 4)')
1221
-
1222
- # The method only accept lineal geometries
1223
- assert_raises(Geos::GEOSException) do
1224
- geom_a.project(geom_b)
1225
- end
1226
-
1227
- geom_a = read('LINESTRING(0 0, 10 0)')
1228
- geom_b = read('POINT(0 0)')
1229
- assert_equal(0, geom_a.project(geom_b))
1230
- assert_equal(0, geom_a.project(geom_b, true))
1231
- assert_equal(0, geom_a.project_normalized(geom_b))
1232
-
1233
- geom_b = read('POINT(10 0)')
1234
- assert_equal(10, geom_a.project(geom_b))
1235
- assert_equal(1, geom_a.project(geom_b, true))
1236
- assert_equal(1, geom_a.project_normalized(geom_b))
1237
-
1238
- geom_b = read('POINT(5 0)')
1239
- assert_equal(5, geom_a.project(geom_b))
1240
- assert_equal(0.5, geom_a.project(geom_b, true))
1241
- assert_equal(0.5, geom_a.project_normalized(geom_b))
1242
-
1243
- geom_a = read('MULTILINESTRING((0 0, 10 0),(20 10, 20 20))')
1244
- geom_b = read('POINT(20 0)')
1245
- assert_equal(10, geom_a.project(geom_b))
1246
- assert_equal(0.5, geom_a.project(geom_b, true))
1247
- assert_equal(0.5, geom_a.project_normalized(geom_b))
1248
-
1249
- geom_b = read('POINT(20 5)')
1250
- assert_equal(10, geom_a.project(geom_b))
1251
- assert_equal(0.5, geom_a.project(geom_b, true))
1252
- assert_equal(0.5, geom_a.project_normalized(geom_b))
1253
- end
1254
-
1255
- def test_interpolate
1256
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:interpolate)
1257
-
1258
- simple_tester(:interpolate, 'POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, false)
1259
- simple_tester(:interpolate, 'POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, true)
1260
-
1261
- simple_tester(:interpolate, 'POINT (5 0)', 'LINESTRING(0 0, 10 0)', 5, false)
1262
- simple_tester(:interpolate, 'POINT (5 0)', 'LINESTRING(0 0, 10 0)', 0.5, true)
1263
-
1264
- simple_tester(:interpolate, 'POINT (10 0)', 'LINESTRING(0 0, 10 0)', 20, false)
1265
- simple_tester(:interpolate, 'POINT (10 0)', 'LINESTRING(0 0, 10 0)', 2, true)
1266
-
1267
- assert_raises(Geos::GEOSException) do
1268
- read('POINT(1 2)').interpolate(0)
1269
- end
1270
- end
1271
-
1272
- def test_interpolate_normalized
1273
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:interpolate_normalized)
1274
-
1275
- tester = lambda { |expected, g, d|
1276
- geom = read(g)
1277
- assert_equal(expected, write(geom.interpolate_normalized(d)))
1278
- }
1279
-
1280
- writer.trim = true
1281
-
1282
- tester['POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0]
1283
- tester['POINT (5 0)', 'LINESTRING(0 0, 10 0)', 0.5]
1284
- tester['POINT (10 0)', 'LINESTRING(0 0, 10 0)', 2]
1285
-
1286
- assert_raises(Geos::GEOSException) do
1287
- read('POINT(1 2)').interpolate_normalized(0)
1288
- end
1289
- end
1290
-
1291
- def test_start_and_end_points
1292
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:start_point)
1293
-
1294
- geom = read('LINESTRING (10 10, 10 14, 14 14, 14 10)')
1295
- simple_tester(:start_point, 'POINT (10 10)', geom)
1296
- simple_tester(:end_point, 'POINT (14 10)', geom)
1297
-
1298
- geom = read('LINEARRING (11 11, 11 12, 12 11, 11 11)')
1299
- simple_tester(:start_point, 'POINT (11 11)', geom)
1300
- simple_tester(:start_point, 'POINT (11 11)', geom)
1301
- end
1302
-
1303
- def test_area
1304
- simple_tester(:area, 1.0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1305
- simple_tester(:area, 0.0, 'POINT (0 0)')
1306
- simple_tester(:area, 0.0, 'LINESTRING (0 0 , 10 0)')
1307
- end
1308
-
1309
- def test_length
1310
- simple_tester(:length, 4.0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1311
- simple_tester(:length, 0.0, 'POINT (0 0)')
1312
- simple_tester(:length, 10.0, 'LINESTRING (0 0 , 10 0)')
1313
- end
1314
-
1315
- def test_distance
1316
- geom = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1317
- simple_tester(:distance, 0.0, geom, read('POINT(0.5 0.5)'))
1318
- simple_tester(:distance, 1.0, geom, read('POINT (-1 0)'))
1319
- simple_tester(:distance, 2.0, geom, read('LINESTRING (3 0 , 10 0)'))
1320
- end
1321
-
1322
- def test_distance_indexed
1323
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:distance_indexed)
1324
-
1325
- geom_a = read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1326
- geom_b = read('POLYGON ((20 30, 10 10, 13 14, 7 8, 20 30))')
1327
-
1328
- assert_in_delta(9.219544457292887, geom_a.distance_indexed(geom_b), TOLERANCE)
1329
- assert_in_delta(9.219544457292887, geom_b.distance_indexed(geom_a), TOLERANCE)
1330
- end
1331
-
1332
- def test_hausdorff_distance
1333
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hausdorff_distance)
1334
-
1335
- tester = lambda { |expected, g_1, g_2|
1336
- geom_1 = read(g_1)
1337
- geom_2 = read(g_2)
1338
- assert_in_delta(expected, geom_1.hausdorff_distance(geom_2), TOLERANCE)
1339
- }
1340
-
1341
- geom_a = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1342
-
1343
- tester[10.0498756211209, geom_a, 'POINT(0 10)']
1344
- tester[2.23606797749979, geom_a, 'POINT(-1 0)']
1345
- tester[9.0, geom_a, 'LINESTRING (3 0 , 10 0)']
1346
- end
1347
-
1348
- def test_hausdorff_distance_with_densify_fract
1349
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hausdorff_distance)
1350
-
1351
- tester = lambda { |expected, g_1, g_2|
1352
- geom_1 = read(g_1)
1353
- geom_2 = read(g_2)
1354
- assert_in_delta(expected, geom_1.hausdorff_distance(geom_2, 0.001), TOLERANCE)
1355
- }
1356
-
1357
- geom_a = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1358
-
1359
- tester[10.0498756211209, geom_a, 'POINT(0 10)']
1360
- tester[2.23606797749979, geom_a, 'POINT(-1 0)']
1361
- tester[9.0, geom_a, 'LINESTRING (3 0 , 10 0)']
1362
- end
1363
-
1364
- def test_nearest_points
1365
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:nearest_points)
1366
-
1367
- tester = lambda { |expected, g_1, g_2|
1368
- geom_1 = read(g_1)
1369
- geom_2 = read(g_2)
1370
-
1371
- cs = geom_1.nearest_points(geom_2)
1372
- result = cs.to_s if cs
1373
-
1374
- if expected.nil?
1375
- assert_nil(result)
1376
- else
1377
- assert_equal(expected, result)
1378
- end
1379
- }
1380
-
1381
- tester[
1382
- nil,
1383
- 'POINT EMPTY',
1384
- 'POINT EMPTY'
1385
- ]
1386
-
1387
- tester[
1388
- if Geos::GEOS_NICE_VERSION >= '030800'
1389
- '5.0 5.0, 8.0 8.0'
1390
- else
1391
- '5.0 5.0 NaN, 8.0 8.0 NaN'
1392
- end,
1393
- 'POLYGON((1 1, 1 5, 5 5, 5 1, 1 1))',
1394
- 'POLYGON((8 8, 9 9, 9 10, 8 8))'
1395
- ]
1396
- end
1397
-
1398
- def test_snap
1399
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:snap)
1400
-
1401
- geom = read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1402
- simple_tester(:snap, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', geom, read('POINT(0.1 0)'), 0)
1403
- simple_tester(:snap, 'POLYGON ((0.1 0, 1 0, 1 1, 0 1, 0.1 0))', geom, read('POINT(0.1 0)'), 0.5)
1404
- end
1405
-
1406
- def test_polygonize
1407
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize)
1408
-
1409
- geom_a = read(
1410
- 'GEOMETRYCOLLECTION(
1411
- LINESTRING(0 0, 10 10),
1412
- LINESTRING(185 221, 100 100),
1413
- LINESTRING(185 221, 88 275, 180 316),
1414
- LINESTRING(185 221, 292 281, 180 316),
1415
- LINESTRING(189 98, 83 187, 185 221),
1416
- LINESTRING(189 98, 325 168, 185 221)
1417
- )'
1418
- )
1419
-
1420
- polygonized = geom_a.polygonize
1421
- assert_equal(2, polygonized.length)
1422
- assert_equal(
1423
- 'POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))',
1424
- write(polygonized[0].snap_to_grid(0.1))
1425
- )
1426
- assert_equal(
1427
- 'POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98))',
1428
- write(polygonized[1].snap_to_grid(0.1))
1429
- )
1430
- end
1431
-
1432
- def test_polygonize_with_geometry_arguments
1433
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize)
1434
-
1435
- geom_a = read('LINESTRING (100 100, 100 300, 300 300, 300 100, 100 100)')
1436
- geom_b = read('LINESTRING (150 150, 150 250, 250 250, 250 150, 150 150)')
1437
-
1438
- polygonized = geom_a.polygonize(geom_b)
1439
- assert_equal(2, polygonized.length)
1440
- assert_equal(
1441
- 'POLYGON ((100 100, 100 300, 300 300, 300 100, 100 100), (150 150, 250 150, 250 250, 150 250, 150 150))',
1442
- write(polygonized[0].snap_to_grid(0.1))
1443
- )
1444
- assert_equal(
1445
- 'POLYGON ((150 150, 150 250, 250 250, 250 150, 150 150))',
1446
- write(polygonized[1].snap_to_grid(0.1))
1447
- )
1448
- end
1449
-
1450
- def test_polygonize_valid
1451
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_valid)
1452
-
1453
- geom_a = read(
1454
- 'GEOMETRYCOLLECTION(
1455
- LINESTRING (100 100, 100 300, 300 300, 300 100, 100 100),
1456
- LINESTRING (150 150, 150 250, 250 250, 250 150, 150 150)
1457
- )'
1458
- )
1459
-
1460
- polygonized = geom_a.polygonize_valid
1461
- assert_equal(
1462
- 'POLYGON ((100 100, 100 300, 300 300, 300 100, 100 100), (150 150, 250 150, 250 250, 150 250, 150 150))',
1463
- write(polygonized.snap_to_grid(0.1))
1464
- )
1465
- end
1466
-
1467
- def test_polygonize_cut_edges
1468
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_cut_edges)
1469
-
1470
- geom_a = read(
1471
- 'GEOMETRYCOLLECTION(
1472
- LINESTRING(0 0, 10 10),
1473
- LINESTRING(185 221, 100 100),
1474
- LINESTRING(185 221, 88 275, 180 316),
1475
- LINESTRING(185 221, 292 281, 180 316),
1476
- LINESTRING(189 98, 83 187, 185 221),
1477
- LINESTRING(189 98, 325 168, 185 221)
1478
- )'
1479
- )
1480
-
1481
- cut_edges = geom_a.polygonize_cut_edges
1482
- assert_equal(0, cut_edges.length)
1483
- end
1484
-
1485
- def test_polygonize_full
1486
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_full)
1487
-
1488
- writer.rounding_precision = if Geos::GEOS_NICE_VERSION >= '031000'
1489
- 0
1490
- else
1491
- 3
1492
- end
1493
-
1494
- geom_a = read(
1495
- 'GEOMETRYCOLLECTION(
1496
- LINESTRING(0 0, 10 10),
1497
- LINESTRING(185 221, 100 100),
1498
- LINESTRING(185 221, 88 275, 180 316),
1499
- LINESTRING(185 221, 292 281, 180 316),
1500
- LINESTRING(189 98, 83 187, 185 221),
1501
- LINESTRING(189 98, 325 168, 185 221)
1502
- )'
1503
- )
1504
-
1505
- polygonized = geom_a.polygonize_full
1506
-
1507
- assert_kind_of(Array, polygonized[:rings])
1508
- assert_kind_of(Array, polygonized[:cuts])
1509
- assert_kind_of(Array, polygonized[:dangles])
1510
- assert_kind_of(Array, polygonized[:invalid_rings])
1511
-
1512
- assert_equal(2, polygonized[:rings].length)
1513
- assert_equal(0, polygonized[:cuts].length)
1514
- assert_equal(2, polygonized[:dangles].length)
1515
- assert_equal(0, polygonized[:invalid_rings].length)
1516
-
1517
- assert_equal(
1518
- 'POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))',
1519
- write(polygonized[:rings][0])
1520
- )
1521
-
1522
- assert_equal(
1523
- 'POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98))',
1524
- write(polygonized[:rings][1])
1525
- )
1526
-
1527
- assert_equal(
1528
- 'LINESTRING (185 221, 100 100)',
1529
- write(polygonized[:dangles][0])
1530
- )
1531
-
1532
- assert_equal(
1533
- 'LINESTRING (0 0, 10 10)',
1534
- write(polygonized[:dangles][1])
1535
- )
1536
-
1537
- geom_b = geom_a.union(read('POINT(0 0)'))
1538
- polygonized = geom_b.polygonize_full
1539
-
1540
- assert_equal(2, polygonized[:dangles].length)
1541
- assert_equal(0, polygonized[:invalid_rings].length)
1542
-
1543
- assert_equal(
1544
- 'LINESTRING (132 146, 100 100)',
1545
- write(polygonized[:dangles][0])
1546
- )
1547
-
1548
- assert_equal(
1549
- 'LINESTRING (0 0, 10 10)',
1550
- write(polygonized[:dangles][1])
1551
- )
1552
- end
1553
-
1554
- def test_polygonize_with_bad_arguments
1555
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_full)
1556
-
1557
- assert_raises(ArgumentError) do
1558
- geom = read('POINT(0 0)')
1559
- geom.polygonize(geom, 'gibberish')
1560
- end
1561
- end
1562
-
1563
- def test_build_area
1564
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:build_area)
1565
-
1566
- geom = read('GEOMETRYCOLLECTION (LINESTRING(0 0, 0 1, 1 1), LINESTRING (1 1, 1 0, 0 0))')
1567
-
1568
- assert_equal('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))', write(geom.build_area))
1569
- end
1570
-
1571
- def test_make_valid
1572
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:make_valid)
1573
-
1574
- geom = read('POLYGON((0 0, 1 1, 0 1, 1 0, 0 0))')
1575
-
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
- )
1584
- end
1585
-
1586
- def test_shared_paths
1587
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:shared_paths)
1588
-
1589
- geom_a = read('LINESTRING(0 0, 50 0)')
1590
- geom_b = read('MULTILINESTRING((5 0, 15 0),(40 0, 30 0))')
1591
-
1592
- paths = geom_a.shared_paths(geom_b)
1593
- assert_equal(2, paths.length)
1594
- assert_equal(
1595
- 'MULTILINESTRING ((5 0, 15 0))',
1596
- write(paths[0])
1597
- )
1598
- assert_equal(
1599
- 'MULTILINESTRING ((30 0, 40 0))',
1600
- write(paths[1])
1601
- )
1602
- end
1603
-
1604
- def test_clone
1605
- geom_a = read('POINT(0 0)')
1606
- geom_b = geom_a.clone
1607
-
1608
- assert_equal(geom_a, geom_b)
1609
- end
1610
-
1611
- def test_clone_srid
1612
- srid = 4326
1613
- geom_a = read('POINT(0 0)')
1614
- geom_a.srid = srid
1615
- geom_b = geom_a.clone
1616
-
1617
- assert_equal(geom_a, geom_b)
1618
- assert_equal(srid, geom_b.srid)
1619
- end
1620
-
1621
- def test_dup
1622
- geom_a = read('POINT(0 0)')
1623
- geom_b = geom_a.dup
1624
-
1625
- assert_equal(geom_a, geom_b)
1626
- end
1627
-
1628
- def test_dup_srid
1629
- srid = 4326
1630
- geom_a = read('POINT(0 0)')
1631
- geom_a.srid = srid
1632
- geom_b = geom_a.dup
1633
- assert_equal(geom_a, geom_b)
1634
- assert_equal(srid, geom_b.srid)
1635
- end
1636
-
1637
- def test_line_string_enumerator
1638
- geom = read('LINESTRING(0 0, 10 10))')
1639
- assert_kind_of(Enumerable, geom.each)
1640
- assert_kind_of(Enumerable, geom.to_enum)
1641
- assert_equal(geom, geom.each(&EMPTY_BLOCK))
1642
- end
1643
-
1644
- def test_normalize
1645
- geom = read('POLYGON((0 0, 5 0, 5 5, 0 5, 0 0))')
1646
- geom.normalize
1647
- assert_equal('POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))', write(geom))
1648
-
1649
- geom = read('POLYGON((0 0, 5 0, 5 5, 0 5, 0 0))').normalize
1650
- assert_equal('POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))', write(geom))
1651
- end
1652
-
1653
- def test_normalize_bang
1654
- geom = read('POLYGON((0 0, 5 0, 5 5, 0 5, 0 0))')
1655
- geom.normalize!
1656
- assert_equal('POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))', write(geom))
1657
-
1658
- geom = read('POLYGON((0 0, 5 0, 5 5, 0 5, 0 0))').normalize!
1659
- assert_equal('POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))', write(geom))
1660
- end
1661
-
1662
- def test_eql
1663
- geom_a = read('POINT(1.0 1.0)')
1664
- geom_b = read('POINT(2.0 2.0)')
1665
-
1666
- %w{ eql? equals? }.each do |method|
1667
- assert(geom_a.send(method, geom_a), "Expected geoms to be equal using #{method}")
1668
- refute(geom_a.send(method, geom_b), "Expected geoms to not be equal using #{method}")
1669
- end
1670
- end
1671
-
1672
- def test_equals_operator
1673
- geom_a = read('POINT(1.0 1.0)')
1674
- geom_b = read('POINT(2.0 2.0)')
1675
-
1676
- assert(geom_a == geom_a, 'Expected geoms to be equal using ==')
1677
- refute(geom_a == geom_b, 'Expected geoms to not be equal using ==')
1678
- refute(geom_a == 'test', 'Expected geoms to not be equal using ==')
1679
- end
1680
-
1681
- def test_eql_exact
1682
- geom_a = read('POINT(1.0 1.0)')
1683
- geom_b = read('POINT(2.0 2.0)')
1684
-
1685
- %w{ eql_exact? equals_exact? exactly_equals? }.each do |method|
1686
- refute(geom_a.send(method, geom_b, 0.001), "Expected geoms to not be equal using #{method}")
1687
- end
1688
- end
1689
-
1690
- def test_eql_almost_default
1691
- geom = read('POINT (1 1)')
1692
- geom_a = read('POINT (1.0000001 1.0000001)')
1693
- geom_b = read('POINT (1.000001 1.000001)')
1694
-
1695
- %w{ eql_almost? equals_almost? almost_equals? }.each do |method|
1696
- assert(geom.send(method, geom_a), "Expected geoms to be equal using #{method}")
1697
- refute(geom.send(method, geom_b), "Expected geoms to not be equal using #{method}")
1698
- end
1699
- end
1700
-
1701
- def test_eql_almost
1702
- geom_a = read('POINT(1.0 1.0)')
1703
- geom_b = read('POINT(1.1 1.1)')
1704
-
1705
- refute_equal(geom_a, geom_b)
1706
-
1707
- %w{ eql_almost? equals_almost? almost_equals? }.each do |method|
1708
- assert(geom_a.send(method, geom_b, 0), "Expected geoms to be equal using #{method}")
1709
- refute(geom_a.send(method, geom_b, 1), "Expected geoms to not be equal using #{method}")
1710
- end
1711
- end
1712
-
1713
- def test_srid_copy_policy
1714
- geom = read('POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))')
1715
- geom.srid = 4326
1716
-
1717
- Geos.srid_copy_policy = :zero
1718
- cloned = geom.clone
1719
- assert_equal(4326, cloned.srid)
1720
-
1721
- Geos.srid_copy_policy = :lenient
1722
- cloned = geom.clone
1723
- assert_equal(4326, cloned.srid)
1724
-
1725
- Geos.srid_copy_policy = :strict
1726
- cloned = geom.clone
1727
- assert_equal(4326, cloned.srid)
1728
-
1729
- Geos.srid_copy_policy = :zero
1730
- geom_b = geom.convex_hull
1731
- assert_equal(0, geom_b.srid)
1732
-
1733
- Geos.srid_copy_policy = :lenient
1734
- geom_b = geom.convex_hull
1735
- assert_equal(4326, geom_b.srid)
1736
-
1737
- Geos.srid_copy_policy = :strict
1738
- geom_b = geom.convex_hull
1739
- assert_equal(4326, geom_b.srid)
1740
-
1741
- geom_b = read('POLYGON ((3 3, 3 8, 8 8, 8 3, 3 3))')
1742
- geom_b.srid = 3875
1743
-
1744
- Geos.srid_copy_policy = :zero
1745
- geom_c = geom.intersection(geom_b)
1746
- assert_equal(0, geom_c.srid)
1747
-
1748
- Geos.srid_copy_policy = :lenient
1749
- geom_c = geom.intersection(geom_b)
1750
- assert_equal(4326, geom_c.srid)
1751
-
1752
- assert_raises(Geos::MixedSRIDsError) do
1753
- Geos.srid_copy_policy = :strict
1754
- geom_c = geom.intersection(geom_b)
1755
- assert_equal(231_231, geom_c.srid)
1756
- end
1757
- ensure
1758
- Geos.srid_copy_policy = :default
1759
- end
1760
-
1761
- def test_bad_srid_copy_policy
1762
- assert_raises(ArgumentError) do
1763
- Geos.srid_copy_policy = :blart
1764
- end
1765
- end
1766
-
1767
- def test_srid_copy_policy_default
1768
- Geos.srid_copy_policy_default = :default
1769
- assert_equal(:zero, Geos.srid_copy_policy_default)
1770
-
1771
- Geos.srid_copy_policy_default = :lenient
1772
- assert_equal(:lenient, Geos.srid_copy_policy_default)
1773
-
1774
- Geos.srid_copy_policy_default = :strict
1775
- assert_equal(:strict, Geos.srid_copy_policy_default)
1776
-
1777
- assert_raises(ArgumentError) do
1778
- Geos.srid_copy_policy_default = :blart
1779
- end
1780
- ensure
1781
- Geos.srid_copy_policy_default = :default
1782
- end
1783
-
1784
- def test_empty_geometry_has_0_area
1785
- assert_equal(0, read('POLYGON EMPTY').area)
1786
- end
1787
-
1788
- def test_empty_geometry_has_0_length
1789
- assert_equal(0, read('POLYGON EMPTY').length)
1790
- end
1791
-
1792
- def test_to_s
1793
- assert_match(/^\#<Geos::Point: .+>$/, read('POINT(0 0)').to_s)
1794
- end
1795
-
1796
- def test_delaunay_triangulation
1797
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:delaunay_triangulation)
1798
-
1799
- tester = lambda { |expected, geom, *args|
1800
- geom = read(geom)
1801
- geom_tri = geom.delaunay_triangulation(*args)
1802
- geom_tri.normalize!
1803
-
1804
- assert_equal(expected, write(geom_tri))
1805
- }
1806
-
1807
- writer.trim = true
1808
-
1809
- # empty polygon
1810
- tester['GEOMETRYCOLLECTION EMPTY', 'POLYGON EMPTY', 0]
1811
- tester['MULTILINESTRING EMPTY', 'POLYGON EMPTY', 0, only_edges: true]
1812
-
1813
- # single point
1814
- tester['GEOMETRYCOLLECTION EMPTY', 'POINT (0 0)', 0]
1815
- tester['MULTILINESTRING EMPTY', 'POINT (0 0)', 0, only_edges: true]
1816
-
1817
- # three collinear points
1818
- tester['GEOMETRYCOLLECTION EMPTY', 'MULTIPOINT(0 0, 5 0, 10 0)', 0]
1819
- tester['MULTILINESTRING ((5 0, 10 0), (0 0, 5 0))', 'MULTIPOINT(0 0, 5 0, 10 0)', 0, only_edges: true]
1820
-
1821
- # three points
1822
- tester['GEOMETRYCOLLECTION (POLYGON ((0 0, 10 10, 5 0, 0 0)))', 'MULTIPOINT(0 0, 5 0, 10 10)', 0]
1823
- tester['MULTILINESTRING ((5 0, 10 10), (0 0, 10 10), (0 0, 5 0))', 'MULTIPOINT(0 0, 5 0, 10 10)', 0, only_edges: true]
1824
-
1825
- # polygon with a hole
1826
- tester[
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)))',
1830
- 'POLYGON((0 0, 8.5 1, 10 10, 0.5 9, 0 0),(2 2, 3 8, 7 8, 8 2, 2 2)))',
1831
- 0
1832
- ]
1833
-
1834
- tester[
1835
- 'MULTILINESTRING ((8.5 1, 10 10), (8 2, 10 10), (8 2, 8.5 1), (7 8, 10 10), (7 8, 8 2), (3 8, 10 10), (3 8, 7 8), (2 2, 8.5 1), (2 2, 8 2), (2 2, 7 8), (2 2, 3 8), (0.5 9, 10 10), (0.5 9, 3 8), (0.5 9, 2 2), (0 0, 8.5 1), (0 0, 2 2), (0 0, 0.5 9))',
1836
- 'POLYGON((0 0, 8.5 1, 10 10, 0.5 9, 0 0),(2 2, 3 8, 7 8, 8 2, 2 2)))',
1837
- 0,
1838
- only_edges: true
1839
- ]
1840
-
1841
- # four points with a tolerance making one collapse
1842
- tester['MULTILINESTRING ((10 0, 10 10), (0 0, 10 10), (0 0, 10 0))', 'MULTIPOINT(0 0, 10 0, 10 10, 11 10)', 2.0, only_edges: true]
1843
-
1844
- # tolerance as an option
1845
- tester['MULTILINESTRING ((10 0, 10 10), (0 0, 10 10), (0 0, 10 0))', 'MULTIPOINT(0 0, 10 0, 10 10, 11 10)', tolerance: 2.0, only_edges: true]
1846
- end
1847
-
1848
- def test_constrained_delaunay_triangulation
1849
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:constrained_delaunay_triangulation)
1850
-
1851
- tester = lambda { |expected, geom|
1852
- geom = read(geom)
1853
- geom_tri = geom.constrained_delaunay_triangulation
1854
- geom_tri.normalize!
1855
-
1856
- assert_equal(write(read(expected).normalize), write(geom_tri))
1857
- }
1858
-
1859
- writer.trim = true
1860
-
1861
- tester['GEOMETRYCOLLECTION EMPTY', 'POLYGON EMPTY']
1862
- tester['GEOMETRYCOLLECTION EMPTY', 'POINT(0 0)']
1863
- tester['GEOMETRYCOLLECTION (POLYGON ((10 10, 20 40, 90 10, 10 10)), POLYGON ((90 90, 20 40, 90 10, 90 90)))', 'POLYGON ((10 10, 20 40, 90 90, 90 10, 10 10))']
1864
- end
1865
-
1866
- def test_voronoi_diagram
1867
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:voronoi_diagram)
1868
-
1869
- tester = lambda { |expected, geom, *args|
1870
- geom = read(geom)
1871
- voronoi_diagram = geom.voronoi_diagram(*args)
1872
-
1873
- assert_equal(expected, write(voronoi_diagram))
1874
- }
1875
-
1876
- writer.trim = true
1877
-
1878
- geom = 'MULTIPOINT(0 0, 100 0, 100 100, 0 100)'
1879
-
1880
- tester[
1881
- if Geos::GEOS_NICE_VERSION > '030900'
1882
- '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)))'
1883
- else
1884
- '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)))'
1885
- end,
1886
- geom
1887
- ]
1888
-
1889
- tester['MULTILINESTRING ((50 50, 50 200), (200 50, 50 50), (50 50, -100 50), (50 50, 50 -100))', geom, tolerance: 0, only_edges: true]
1890
-
1891
- tester['MULTILINESTRING ((50 50, 50 1100), (1100 50, 50 50), (50 50, -1000 50), (50 50, 50 -1000))', geom,
1892
- only_edges: true,
1893
- envelope: read(geom).buffer(1000)
1894
- ]
1895
-
1896
- # Allows a tolerance for the first argument
1897
- writer.rounding_precision = if Geos::GEOS_NICE_VERSION >= '031000'
1898
- 0
1899
- else
1900
- 3
1901
- end
1902
-
1903
- writer.trim = true
1904
-
1905
- tester[
1906
- if Geos::GEOS_NICE_VERSION > '030900'
1907
- '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)))'
1908
- else
1909
- '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)))'
1910
- end,
1911
- 'MULTIPOINT ((150 210), (210 270), (150 220), (220 210), (215 269))',
1912
- 10
1913
- ]
1914
- end
1915
-
1916
- def test_precision
1917
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:precision)
1918
-
1919
- geom = read('POLYGON EMPTY')
1920
- scale = geom.precision
1921
- assert_equal(0.0, scale)
1922
-
1923
- geom_with_precision = geom.with_precision(2.0)
1924
-
1925
- assert_equal('POLYGON EMPTY', write(geom_with_precision))
1926
- scale = geom_with_precision.precision
1927
- assert_equal(2.0, scale)
1928
- end
1929
-
1930
- def test_with_precision
1931
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:with_precision)
1932
-
1933
- geom = read('LINESTRING(1 0, 2 0)')
1934
-
1935
- geom_with_precision = geom.with_precision(5.0)
1936
- assert_equal('LINESTRING EMPTY', write(geom_with_precision))
1937
-
1938
- geom_with_precision = geom.with_precision(5.0, keep_collapsed: true)
1939
- assert_equal('LINESTRING (0 0, 0 0)', write(geom_with_precision))
1940
- end
1941
-
1942
- def test_minimum_rotated_rectangle
1943
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_rotated_rectangle)
1944
-
1945
- geom = read('POLYGON ((1 6, 6 11, 11 6, 6 1, 1 6))')
1946
- minimum_rotated_rectangle = geom.minimum_rotated_rectangle
1947
-
1948
- assert_equal('POLYGON ((6 1, 11 6, 6 11, 1 6, 6 1))', write(minimum_rotated_rectangle))
1949
- end
1950
-
1951
- def test_minimum_clearance
1952
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_clearance)
1953
-
1954
- tester = lambda { |expected_clearance, geom|
1955
- geom = read(geom)
1956
- clearance = geom.minimum_clearance
1957
-
1958
- if expected_clearance.eql?(Float::INFINITY)
1959
- assert(clearance.infinite?)
1960
- else
1961
- assert_in_delta(expected_clearance, clearance, TOLERANCE)
1962
- end
1963
- }
1964
-
1965
- tester[Float::INFINITY, 'LINESTRING EMPTY']
1966
- tester[20, 'LINESTRING (30 100, 10 100)']
1967
- tester[100, 'LINESTRING (200 200, 200 100)']
1968
- tester[3.49284983912134e-05, 'LINESTRING (-112.712119 33.575919, -112.712127 33.575885)']
1969
- end
1970
-
1971
- def test_minimum_clearance_line
1972
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_clearance_line)
1973
-
1974
- tester = lambda { |expected_geom, geom|
1975
- geom = read(geom)
1976
- clearance_geom = geom.minimum_clearance_line
1977
-
1978
- assert_equal(expected_geom, write(clearance_geom))
1979
- }
1980
-
1981
- tester['LINESTRING EMPTY', 'MULTIPOINT ((100 100), (100 100))']
1982
- tester['LINESTRING (30 100, 10 100)', 'MULTIPOINT ((100 100), (10 100), (30 100))']
1983
- tester['LINESTRING (200 200, 200 100)', 'POLYGON ((100 100, 300 100, 200 200, 100 100))']
1984
- tester[
1985
- 'LINESTRING (-112.712119 33.575919, -112.712127 33.575885)',
1986
- '0106000000010000000103000000010000001a00000035d42824992d5cc01b834e081dca404073b9c150872d5cc03465a71fd4c940400ec00644882d5cc03b8a' \
1987
- '73d4d1c94040376dc669882d5cc0bf9cd9aed0c940401363997e892d5cc002f4fbfecdc94040ca4e3fa88b2d5cc0a487a1d5c9c940408f1ce90c8c2d5cc06989' \
1988
- '95d1c8c94040fab836548c2d5cc0bd175fb4c7c940409f1f46088f2d5cc0962023a0c2c940407b15191d902d5cc068041bd7bfc940400397c79a912d5cc0287d' \
1989
- '21e4bcc940403201bf46922d5cc065e3c116bbc940409d9d0c8e922d5cc0060fd3beb9c940400ef7915b932d5cc09012bbb6b7c940404fe61f7d932d5cc0e4a0' \
1990
- '8499b6c94040fc71fbe5932d5cc0ea9106b7b5c94040eaec6470942d5cc0c2323674b3c94040601dc70f952d5cc043588d25acc94040aea06989952d5cc03ecf' \
1991
- '9f36aac94040307f85cc952d5cc0e5eb32fca7c94040dd0a6135962d5cc01b615111a7c9404048a7ae7c962d5cc00a2aaa7ea5c94040f4328ae5962d5cc05eb8' \
1992
- '7361a4c94040c49448a2972d5cc04d81cccea2c940407c80eecb992d5cc06745d4449fc9404035d42824992d5cc01b834e081dca4040'
1993
- ]
1994
- tester['LINESTRING EMPTY', 'POLYGON EMPTY']
1995
- end
1996
-
1997
- def test_maximum_inscribed_circle
1998
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:maximum_inscribed_circle)
1999
-
2000
- geom = read('POLYGON ((100 200, 200 200, 200 100, 100 100, 100 200))')
2001
- output = geom.maximum_inscribed_circle(0.001)
2002
- assert_equal('LINESTRING (150 150, 150 200)', write(output))
2003
- end
2004
-
2005
- def test_largest_empty_circle
2006
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:largest_empty_circle)
2007
-
2008
- geom = read('MULTIPOINT ((100 100), (100 200), (200 200), (200 100))')
2009
- output = geom.largest_empty_circle(0.001)
2010
- assert_equal('LINESTRING (150 150, 100 100)', write(output))
2011
-
2012
- geom = read('MULTIPOINT ((100 100), (100 200), (200 200), (200 100))')
2013
- output = geom.largest_empty_circle(0.001, boundary: read('MULTIPOINT ((100 100), (100 200), (200 200), (200 100))'))
2014
- assert_equal('LINESTRING (100 100, 100 100)', write(output))
2015
- end
2016
-
2017
- def test_minimum_width
2018
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_width)
2019
-
2020
- geom = read('POLYGON ((0 0, 0 15, 5 10, 5 0, 0 0))')
2021
- output = geom.minimum_width
2022
- assert_equal('LINESTRING (0 0, 5 0)', write(output))
2023
-
2024
- geom = read('LINESTRING (0 0,0 10, 10 10)')
2025
- output = geom.minimum_width
2026
- assert_equal('LINESTRING (5 5, 0 10)', write(output))
2027
- end
2028
-
2029
- def test_dump_points
2030
- geom = read('GEOMETRYCOLLECTION(
2031
- MULTILINESTRING((0 0, 10 10, 20 20), (100 100, 200 200, 300 300)),
2032
-
2033
- POINT(10 10),
2034
-
2035
- POLYGON((0 0, 5 0, 5 5, 0 5, 0 0), (1 1, 4 1, 4 4, 1 4, 1 1))
2036
- )')
2037
-
2038
- assert_equal([
2039
- [
2040
- [
2041
- Geos.create_point(0, 0),
2042
- Geos.create_point(10, 10),
2043
- Geos.create_point(20, 20)
2044
- ],
2045
-
2046
- [
2047
- Geos.create_point(100, 100),
2048
- Geos.create_point(200, 200),
2049
- Geos.create_point(300, 300)
2050
- ]
2051
- ],
2052
-
2053
- [
2054
- Geos.create_point(10, 10)
2055
- ],
2056
-
2057
- [
2058
- [
2059
- Geos.create_point(0, 0),
2060
- Geos.create_point(5, 0),
2061
- Geos.create_point(5, 5),
2062
- Geos.create_point(0, 5),
2063
- Geos.create_point(0, 0)
2064
- ],
2065
-
2066
- [
2067
- Geos.create_point(1, 1),
2068
- Geos.create_point(4, 1),
2069
- Geos.create_point(4, 4),
2070
- Geos.create_point(1, 4),
2071
- Geos.create_point(1, 1)
2072
- ]
2073
- ]
2074
- ], geom.dump_points)
2075
- end
2076
-
2077
- def test_reverse
2078
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:reverse)
2079
-
2080
- simple_tester(:reverse, 'POINT (3 5)', 'POINT (3 5)')
2081
- simple_tester(:reverse, 'MULTIPOINT (100 100, 10 100, 30 100)', 'MULTIPOINT (100 100, 10 100, 30 100)')
2082
- simple_tester(:reverse, 'LINESTRING (200 200, 200 100)', 'LINESTRING (200 100, 200 200)')
2083
-
2084
- if Geos::GEOS_NICE_VERSION >= '030801'
2085
- simple_tester(:reverse, 'MULTILINESTRING ((3 3, 4 4), (1 1, 2 2))', 'MULTILINESTRING ((4 4, 3 3), (2 2, 1 1))')
2086
- else
2087
- simple_tester(:reverse, 'MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))', 'MULTILINESTRING ((4 4, 3 3), (2 2, 1 1))')
2088
- end
2089
-
2090
- 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))')
2091
- 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)))')
2092
- 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)))')
2093
- simple_tester(:reverse, 'POINT EMPTY', 'POINT EMPTY')
2094
- simple_tester(:reverse, 'LINESTRING EMPTY', 'LINESTRING EMPTY')
2095
- simple_tester(:reverse, 'LINEARRING EMPTY', 'LINEARRING EMPTY')
2096
- simple_tester(:reverse, 'POLYGON EMPTY', 'POLYGON EMPTY')
2097
- simple_tester(:reverse, 'MULTIPOINT EMPTY', 'MULTIPOINT EMPTY')
2098
- simple_tester(:reverse, 'MULTILINESTRING EMPTY', 'MULTILINESTRING EMPTY')
2099
- simple_tester(:reverse, 'MULTIPOLYGON EMPTY', 'MULTIPOLYGON EMPTY')
2100
- simple_tester(:reverse, 'GEOMETRYCOLLECTION EMPTY', 'GEOMETRYCOLLECTION EMPTY')
2101
- end
2102
-
2103
- def test_frechet_distance
2104
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:frechet_distance)
2105
-
2106
- assert_in_delta(read('LINESTRING (0 0, 100 0)').frechet_distance(read('LINESTRING (0 0, 50 50, 100 0)')), 70.7106781186548, TOLERANCE)
2107
- end
2108
-
2109
- def test_frechet_distance_with_densify
2110
- skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:frechet_distance)
2111
-
2112
- assert_in_delta(read('LINESTRING (0 0, 100 0)').frechet_distance(read('LINESTRING (0 0, 50 50, 100 0)'), 0.5), 50.0, TOLERANCE)
2113
- end
2114
- end