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.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +2 -2
- data/.rbenv-vars +1 -0
- data/.rubocop-minitest.yml +40 -17
- data/.rubocop.yml +664 -120
- data/.rubocop_todo.yml +30 -19
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -0
- data/ffi-geos.gemspec +2 -2
- data/lib/ffi-geos/coordinate_sequence.rb +2 -1
- data/lib/ffi-geos/geojson_reader.rb +35 -0
- data/lib/ffi-geos/geojson_writer.rb +49 -0
- data/lib/ffi-geos/geometry.rb +101 -1
- data/lib/ffi-geos/geometry_collection.rb +1 -1
- data/lib/ffi-geos/line_string.rb +1 -1
- data/lib/ffi-geos/point.rb +9 -0
- data/lib/ffi-geos/polygon.rb +1 -1
- data/lib/ffi-geos/prepared_geometry.rb +20 -0
- data/lib/ffi-geos/version.rb +1 -1
- data/lib/ffi-geos/wkb_writer.rb +12 -0
- data/lib/ffi-geos.rb +156 -3
- data/test/coordinate_sequence_tests.rb +22 -4
- data/test/geojson_reader_tests.rb +174 -0
- data/test/geojson_writer_tests.rb +103 -0
- data/test/geometry/area_tests.rb +18 -0
- data/test/geometry/boundary_tests.rb +36 -0
- data/test/geometry/buffer_tests.rb +116 -0
- data/test/geometry/build_area_tests.rb +20 -0
- data/test/geometry/centroid_tests.rb +37 -0
- data/test/geometry/clip_by_rect_tests.rb +56 -0
- data/test/geometry/clone_tests.rb +29 -0
- data/test/geometry/concave_hull_of_polygons_tests.rb +28 -0
- data/test/geometry/concave_hull_tests.rb +38 -0
- data/test/geometry/convex_hull_tests.rb +26 -0
- data/test/geometry/coord_seq_tests.rb +27 -0
- data/test/geometry/delaunay_triangulation_tests.rb +82 -0
- data/test/geometry/densify_tests.rb +95 -0
- data/test/geometry/difference_tests.rb +108 -0
- data/test/geometry/dimensions_tests.rb +46 -0
- data/test/geometry/distance_tests.rb +29 -0
- data/test/geometry/dump_points_tests.rb +60 -0
- data/test/geometry/dup_tests.rb +29 -0
- data/test/geometry/empty_tests.rb +23 -0
- data/test/geometry/envelope_tests.rb +26 -0
- data/test/geometry/equal_identical_tests.rb +78 -0
- data/test/geometry/equal_tests.rb +62 -0
- data/test/geometry/exterior_ring_tests.rb +27 -0
- data/test/geometry/extract_unique_points_tests.rb +41 -0
- data/test/geometry/frecet_distance_tests.rb +24 -0
- data/test/geometry/get_geometry_n_tests.rb +21 -0
- data/test/geometry/hausdorff_distance_tests.rb +46 -0
- data/test/geometry/hilbert_code_tests.rb +45 -0
- data/test/geometry/interior_ring_n_tests.rb +64 -0
- data/test/geometry/interior_rings_tests.rb +36 -0
- data/test/geometry/interpolate_tests.rb +49 -0
- data/test/geometry/intersection_tests.rb +49 -0
- data/test/geometry/largest_empty_circle_tests.rb +26 -0
- data/test/geometry/length_tests.rb +18 -0
- data/test/geometry/line_merge_directed_tests.rb +28 -0
- data/test/geometry/line_merge_tests.rb +25 -0
- data/test/geometry/line_string_enumerator_tests.rb +20 -0
- data/test/geometry/line_substring_tests.rb +76 -0
- data/test/geometry/make_valid_tests.rb +27 -0
- data/test/geometry/maximum_inscribed_circle_tests.rb +21 -0
- data/test/geometry/minimum_bounding_circle_tests.rb +23 -0
- data/test/geometry/minimum_clearance_tests.rb +58 -0
- data/test/geometry/minimum_rotated_rectangle_tests.rb +28 -0
- data/test/geometry/minimum_width_tests.rb +26 -0
- data/test/geometry/misc_tests.rb +24 -0
- data/test/geometry/nearest_points_tests.rb +46 -0
- data/test/geometry/node_tests.rb +22 -0
- data/test/geometry/normalize_tests.rb +34 -0
- data/test/geometry/num_coordinates_tests.rb +39 -0
- data/test/geometry/num_goemetries_tests.rb +35 -0
- data/test/geometry/num_interior_rings_tests.rb +28 -0
- data/test/geometry/orient_polygons_tests.rb +101 -0
- data/test/geometry/point_on_surface_tests.rb +37 -0
- data/test/geometry/polygon_hull_simplify_tests.rb +55 -0
- data/test/geometry/polygonize_tests.rb +173 -0
- data/test/geometry/precision_tests.rb +42 -0
- data/test/geometry/project_tests.rb +56 -0
- data/test/geometry/relate_tests.rb +73 -0
- data/test/geometry/relationships_tests.rb +138 -0
- data/test/geometry/reverse_tests.rb +44 -0
- data/test/geometry/ring_tests.rb +18 -0
- data/test/geometry/shared_path_tests.rb +31 -0
- data/test/geometry/simple_tests.rb +18 -0
- data/test/geometry/simplify_tests.rb +21 -0
- data/test/geometry/snap_tests.rb +20 -0
- data/test/geometry/srid_copy_policy_tests.rb +94 -0
- data/test/geometry/start_and_end_point_tests.rb +24 -0
- data/test/geometry/sym_difference_tests.rb +114 -0
- data/test/geometry/topology_preserve_simplify_tests.rb +21 -0
- data/test/geometry/union_tests.rb +216 -0
- data/test/geometry/valid_tests.rb +56 -0
- data/test/geometry/voronoi_diagram_tests.rb +62 -0
- data/test/geometry_collection_tests.rb +14 -2
- data/test/interrupt_tests.rb +1 -1
- data/test/line_string_tests.rb +24 -3
- data/test/misc_tests.rb +1 -1
- data/test/point/has_m_tests.rb +43 -0
- data/test/point/x_y_z_m_tests.rb +51 -0
- data/test/point_tests.rb +25 -3
- data/test/polygon_tests.rb +14 -1
- data/test/prepared_geometry_tests.rb +31 -0
- data/test/strtree_tests.rb +11 -18
- data/test/test_helper.rb +2 -0
- data/test/tools_tests.rb +7 -0
- data/test/utils_tests.rb +14 -3
- data/test/wkb_reader_tests.rb +1 -0
- data/test/wkb_writer_tests.rb +46 -5
- data/test/wkt_reader_tests.rb +2 -0
- data/test/wkt_writer_tests.rb +20 -2
- metadata +160 -7
- data/test/geometry_tests.rb +0 -2096
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryDifferenceTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_difference
|
14
|
+
comparison_tester(
|
15
|
+
:difference,
|
16
|
+
EMPTY_GEOMETRY,
|
17
|
+
'POINT(0 0)',
|
18
|
+
'POINT(0 0)'
|
19
|
+
)
|
20
|
+
|
21
|
+
comparison_tester(
|
22
|
+
:difference,
|
23
|
+
'POINT (0 0)',
|
24
|
+
'POINT(0 0)',
|
25
|
+
'POINT(1 0)'
|
26
|
+
)
|
27
|
+
|
28
|
+
comparison_tester(
|
29
|
+
:difference,
|
30
|
+
'LINESTRING (0 0, 10 0)',
|
31
|
+
'LINESTRING(0 0, 10 0)',
|
32
|
+
'POINT(5 0)'
|
33
|
+
)
|
34
|
+
|
35
|
+
comparison_tester(
|
36
|
+
:difference,
|
37
|
+
EMPTY_GEOMETRY,
|
38
|
+
'POINT(5 0)',
|
39
|
+
'LINESTRING(0 0, 10 0)'
|
40
|
+
)
|
41
|
+
|
42
|
+
comparison_tester(
|
43
|
+
:difference,
|
44
|
+
'POINT (5 0)',
|
45
|
+
'POINT(5 0)',
|
46
|
+
'LINESTRING(0 1, 10 1)'
|
47
|
+
)
|
48
|
+
|
49
|
+
comparison_tester(
|
50
|
+
:difference,
|
51
|
+
'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0))',
|
52
|
+
'LINESTRING(0 0, 10 0)',
|
53
|
+
'LINESTRING(5 -10, 5 10)'
|
54
|
+
)
|
55
|
+
|
56
|
+
comparison_tester(
|
57
|
+
:difference,
|
58
|
+
'LINESTRING (0 0, 5 0)',
|
59
|
+
'LINESTRING(0 0, 10 0)',
|
60
|
+
'LINESTRING(5 0, 20 0)'
|
61
|
+
)
|
62
|
+
|
63
|
+
comparison_tester(
|
64
|
+
:difference,
|
65
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
66
|
+
'POLYGON ((0 10, 5 10, 10 10, 10 0, 5 0, 0 0, 0 10))'
|
67
|
+
else
|
68
|
+
'POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0))'
|
69
|
+
end,
|
70
|
+
'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
|
71
|
+
'LINESTRING(5 -10, 5 10)'
|
72
|
+
)
|
73
|
+
|
74
|
+
comparison_tester(
|
75
|
+
:difference,
|
76
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
77
|
+
'POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10))'
|
78
|
+
else
|
79
|
+
'POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))'
|
80
|
+
end,
|
81
|
+
'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
|
82
|
+
'LINESTRING(10 0, 20 0)'
|
83
|
+
)
|
84
|
+
|
85
|
+
comparison_tester(
|
86
|
+
:difference,
|
87
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
88
|
+
'POLYGON ((0 10, 10 10, 10 5, 5 5, 5 0, 0 0, 0 10))'
|
89
|
+
else
|
90
|
+
'POLYGON ((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0))'
|
91
|
+
end,
|
92
|
+
'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
|
93
|
+
'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_difference_with_precision
|
98
|
+
skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSDifferencePrec_r)
|
99
|
+
|
100
|
+
comparison_tester(
|
101
|
+
:difference,
|
102
|
+
'MULTILINESTRING ((2 8, 4 8), (6 8, 10 8))',
|
103
|
+
'LINESTRING (2 8, 10 8)',
|
104
|
+
'LINESTRING (3.9 8.1, 6.1 7.9)',
|
105
|
+
precision: 2
|
106
|
+
)
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryDimensionsTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_dimensions
|
14
|
+
types = {
|
15
|
+
dontcare: -3,
|
16
|
+
non_empty: -2,
|
17
|
+
empty: -1,
|
18
|
+
point: 0,
|
19
|
+
curve: 1,
|
20
|
+
surface: 2
|
21
|
+
}
|
22
|
+
|
23
|
+
simple_tester(:dimensions, types[:point], 'POINT(0 0)')
|
24
|
+
simple_tester(:dimensions, types[:point], 'MULTIPOINT (0 1, 2 3)')
|
25
|
+
simple_tester(:dimensions, types[:curve], 'LINESTRING (0 0, 2 3)')
|
26
|
+
simple_tester(:dimensions, types[:curve], 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))')
|
27
|
+
simple_tester(:dimensions, types[:surface], 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
|
28
|
+
simple_tester(:dimensions, types[:surface], 'MULTIPOLYGON (
|
29
|
+
((0 0, 1 0, 1 1, 0 1, 0 0)),
|
30
|
+
((10 10, 10 14, 14 14, 14 10, 10 10),
|
31
|
+
(11 11, 11 12, 12 12, 12 11, 11 11))
|
32
|
+
)')
|
33
|
+
simple_tester(:dimensions, types[:surface], 'GEOMETRYCOLLECTION (
|
34
|
+
MULTIPOLYGON (
|
35
|
+
((0 0, 1 0, 1 1, 0 1, 0 0)),
|
36
|
+
((10 10, 10 14, 14 14, 14 10, 10 10),
|
37
|
+
(11 11, 11 12, 12 12, 12 11, 11 11))
|
38
|
+
),
|
39
|
+
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
|
40
|
+
MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
|
41
|
+
LINESTRING (0 0, 2 3),
|
42
|
+
MULTIPOINT (0 0, 2 3),
|
43
|
+
POINT (9 0)
|
44
|
+
)')
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryDistanceTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_distance
|
14
|
+
geom = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
|
15
|
+
simple_tester(:distance, 0.0, geom, read('POINT(0.5 0.5)'))
|
16
|
+
simple_tester(:distance, 1.0, geom, read('POINT (-1 0)'))
|
17
|
+
simple_tester(:distance, 2.0, geom, read('LINESTRING (3 0 , 10 0)'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_distance_indexed
|
21
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:distance_indexed)
|
22
|
+
|
23
|
+
geom_a = read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
|
24
|
+
geom_b = read('POLYGON ((20 30, 10 10, 13 14, 7 8, 20 30))')
|
25
|
+
|
26
|
+
assert_in_delta(9.219544457292887, geom_a.distance_indexed(geom_b), TOLERANCE)
|
27
|
+
assert_in_delta(9.219544457292887, geom_b.distance_indexed(geom_a), TOLERANCE)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryDumpPointsTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_dump_points
|
14
|
+
geom = read('GEOMETRYCOLLECTION(
|
15
|
+
MULTILINESTRING((0 0, 10 10, 20 20), (100 100, 200 200, 300 300)),
|
16
|
+
|
17
|
+
POINT(10 10),
|
18
|
+
|
19
|
+
POLYGON((0 0, 5 0, 5 5, 0 5, 0 0), (1 1, 4 1, 4 4, 1 4, 1 1))
|
20
|
+
)')
|
21
|
+
|
22
|
+
assert_equal([
|
23
|
+
[
|
24
|
+
[
|
25
|
+
Geos.create_point(0, 0),
|
26
|
+
Geos.create_point(10, 10),
|
27
|
+
Geos.create_point(20, 20)
|
28
|
+
],
|
29
|
+
|
30
|
+
[
|
31
|
+
Geos.create_point(100, 100),
|
32
|
+
Geos.create_point(200, 200),
|
33
|
+
Geos.create_point(300, 300)
|
34
|
+
]
|
35
|
+
],
|
36
|
+
|
37
|
+
[
|
38
|
+
Geos.create_point(10, 10)
|
39
|
+
],
|
40
|
+
|
41
|
+
[
|
42
|
+
[
|
43
|
+
Geos.create_point(0, 0),
|
44
|
+
Geos.create_point(5, 0),
|
45
|
+
Geos.create_point(5, 5),
|
46
|
+
Geos.create_point(0, 5),
|
47
|
+
Geos.create_point(0, 0)
|
48
|
+
],
|
49
|
+
|
50
|
+
[
|
51
|
+
Geos.create_point(1, 1),
|
52
|
+
Geos.create_point(4, 1),
|
53
|
+
Geos.create_point(4, 4),
|
54
|
+
Geos.create_point(1, 4),
|
55
|
+
Geos.create_point(1, 1)
|
56
|
+
]
|
57
|
+
]
|
58
|
+
], geom.dump_points)
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryDupTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_dup
|
14
|
+
geom_a = read('POINT(0 0)')
|
15
|
+
geom_b = geom_a.dup
|
16
|
+
|
17
|
+
assert_equal(geom_a, geom_b)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_dup_srid
|
21
|
+
srid = 4326
|
22
|
+
geom_a = read('POINT(0 0)')
|
23
|
+
geom_a.srid = srid
|
24
|
+
geom_b = geom_a.dup
|
25
|
+
|
26
|
+
assert_equal(geom_a, geom_b)
|
27
|
+
assert_equal(srid, geom_b.srid)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryEmptyTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_empty
|
14
|
+
refute_geom_empty(read('POINT(0 0)'))
|
15
|
+
assert_geom_empty(read('POINT EMPTY'))
|
16
|
+
refute_geom_empty(read('LINESTRING(0 0, 10 0)'))
|
17
|
+
assert_geom_empty(read('LINESTRING EMPTY'))
|
18
|
+
refute_geom_empty(read('POLYGON((0 0, 10 0, 10 10, 0 0))'))
|
19
|
+
assert_geom_empty(read('POLYGON EMPTY'))
|
20
|
+
refute_geom_empty(read('GEOMETRYCOLLECTION(POINT(0 0))'))
|
21
|
+
assert_geom_empty(read('GEOMETRYCOLLECTION EMPTY'))
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryEnvelopeTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_envelope
|
14
|
+
simple_tester(
|
15
|
+
:envelope,
|
16
|
+
'POINT (0 0)',
|
17
|
+
'POINT(0 0)'
|
18
|
+
)
|
19
|
+
|
20
|
+
simple_tester(
|
21
|
+
:envelope,
|
22
|
+
'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))',
|
23
|
+
'LINESTRING(0 0, 10 10)'
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryEqualIdenticalTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def tester(expected, geom_a, geom_b)
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:eql_identical?)
|
15
|
+
|
16
|
+
assert_equal(expected, read(geom_a).eql_identical?(read(geom_b)))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_different_types
|
20
|
+
tester(false, 'POINT EMPTY', 'LINESTRING EMPTY')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_different_dimensions_empty
|
24
|
+
tester(false, 'POINT EMPTY', 'POINT Z EMPTY')
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_different_dimensions
|
28
|
+
tester(false, 'POINT Z (1 2 3)', 'POINT M (1 2 3)')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_different_dimensions_zm_versus_m
|
32
|
+
tester(false, 'POINT ZM (1 2 3 4)', 'POINT Z (1 2 3)')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_different_structure
|
36
|
+
tester(false, 'LINESTRING (1 1, 2 2)', 'MULTILINESTRING ((1 1, 2 2))')
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_different_types_geometry_collection
|
40
|
+
tester(false, 'GEOMETRYCOLLECTION (LINESTRING (1 1, 2 2))', 'MULTILINESTRING ((1 1, 2 2))')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_non_finite_values
|
44
|
+
tester(true, 'POINT(inf inf)', 'POINT(inf inf)')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_equal_lines
|
48
|
+
tester(true, 'LINESTRING M (1 1 0, 2 2 1)', 'LINESTRING M (1 1 0, 2 2 1)')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_different_lines
|
52
|
+
tester(false, 'LINESTRING M (1 1 0, 2 2 1)', 'LINESTRING M (1 1 1, 2 2 1)')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_equal_polygons
|
56
|
+
tester(true, 'POLYGON ((0 0, 1 0, 1 1, 0 0))', 'POLYGON ((0 0, 1 0, 1 1, 0 0))')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_different_polygons
|
60
|
+
tester(false, 'POLYGON ((0 0, 1 0, 1 1, 0 0))', 'POLYGON ((1 0, 1 1, 0 0, 1 0))')
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_equal_polygons_with_holes
|
64
|
+
tester(false, 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 1))', 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 1), (3 3, 4 3, 4 4, 3 3))')
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_identical_collections
|
68
|
+
tester(true, 'MULTILINESTRING ((1 1, 2 2), (2 2, 3 3))', 'MULTILINESTRING ((1 1, 2 2), (2 2, 3 3))')
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_different_collection_structure
|
72
|
+
tester(false, 'MULTILINESTRING ((1 1, 2 2), (2 2, 3 3))', 'MULTILINESTRING ((2 2, 3 3), (1 1, 2 2))')
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_negative_zeo_and_positive_zero
|
76
|
+
tester(true, 'POINT(1 0)', 'POINT(1 -0)')
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryEqualTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_eql
|
14
|
+
geom_a = read('POINT(1.0 1.0)')
|
15
|
+
geom_b = read('POINT(2.0 2.0)')
|
16
|
+
|
17
|
+
%w{ eql? equals? }.each do |method|
|
18
|
+
assert(geom_a.send(method, geom_a), "Expected geoms to be equal using #{method}")
|
19
|
+
refute(geom_a.send(method, geom_b), "Expected geoms to not be equal using #{method}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_equals_operator
|
24
|
+
geom_a = read('POINT(1.0 1.0)')
|
25
|
+
geom_b = read('POINT(2.0 2.0)')
|
26
|
+
|
27
|
+
refute_equal(geom_a, geom_b, 'Expected geoms to not be equal using ==')
|
28
|
+
refute_equal(geom_a, 'test', 'Expected geoms to not be equal using ==')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_eql_exact
|
32
|
+
geom_a = read('POINT(1.0 1.0)')
|
33
|
+
geom_b = read('POINT(2.0 2.0)')
|
34
|
+
|
35
|
+
%w{ eql_exact? equals_exact? exactly_equals? }.each do |method|
|
36
|
+
refute(geom_a.send(method, geom_b, 0.001), "Expected geoms to not be equal using #{method}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_eql_almost_default
|
41
|
+
geom = read('POINT (1 1)')
|
42
|
+
geom_a = read('POINT (1.0000001 1.0000001)')
|
43
|
+
geom_b = read('POINT (1.000001 1.000001)')
|
44
|
+
|
45
|
+
%w{ eql_almost? equals_almost? almost_equals? }.each do |method|
|
46
|
+
assert(geom.send(method, geom_a), "Expected geoms to be equal using #{method}")
|
47
|
+
refute(geom.send(method, geom_b), "Expected geoms to not be equal using #{method}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_eql_almost
|
52
|
+
geom_a = read('POINT(1.0 1.0)')
|
53
|
+
geom_b = read('POINT(1.1 1.1)')
|
54
|
+
|
55
|
+
refute_equal(geom_a, geom_b)
|
56
|
+
|
57
|
+
%w{ eql_almost? equals_almost? almost_equals? }.each do |method|
|
58
|
+
assert(geom_a.send(method, geom_b, 0), "Expected geoms to be equal using #{method}")
|
59
|
+
refute(geom_a.send(method, geom_b, 1), "Expected geoms to not be equal using #{method}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryInteriorRingTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_exterior_ring
|
14
|
+
simple_tester(
|
15
|
+
:exterior_ring,
|
16
|
+
'LINEARRING (10 10, 10 14, 14 14, 14 10, 10 10)',
|
17
|
+
'POLYGON (
|
18
|
+
(10 10, 10 14, 14 14, 14 10, 10 10),
|
19
|
+
(11 11, 11 12, 12 12, 12 11, 11 11)
|
20
|
+
)'
|
21
|
+
)
|
22
|
+
|
23
|
+
assert_raises(NoMethodError) do
|
24
|
+
read('POINT (0 0)').exterior_ring
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryExtractUniquePointsTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_extract_unique_points
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:extract_unique_points)
|
15
|
+
|
16
|
+
geom = read('GEOMETRYCOLLECTION (
|
17
|
+
MULTIPOLYGON (
|
18
|
+
((0 0, 1 0, 1 1, 0 1, 0 0)),
|
19
|
+
((10 10, 10 14, 14 14, 14 10, 10 10),
|
20
|
+
(11 11, 11 12, 12 12, 12 11, 11 11))
|
21
|
+
),
|
22
|
+
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
|
23
|
+
MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
|
24
|
+
LINESTRING (0 0, 2 3),
|
25
|
+
MULTIPOINT (0 0, 2 3),
|
26
|
+
POINT (9 0),
|
27
|
+
POINT (1 0),
|
28
|
+
LINESTRING EMPTY
|
29
|
+
)')
|
30
|
+
|
31
|
+
simple_tester(
|
32
|
+
:extract_unique_points,
|
33
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
34
|
+
'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))'
|
35
|
+
else
|
36
|
+
'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)'
|
37
|
+
end,
|
38
|
+
geom.extract_unique_points
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryFrechetDistanceTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_frechet_distance
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:frechet_distance)
|
15
|
+
|
16
|
+
assert_in_delta(read('LINESTRING (0 0, 100 0)').frechet_distance(read('LINESTRING (0 0, 50 50, 100 0)')), 70.7106781186548, TOLERANCE)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_frechet_distance_with_densify
|
20
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:frechet_distance)
|
21
|
+
|
22
|
+
assert_in_delta(read('LINESTRING (0 0, 100 0)').frechet_distance(read('LINESTRING (0 0, 50 50, 100 0)'), 0.5), 50.0, TOLERANCE)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryGetGeometryNTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
# get_geometry_n is segfaulting in the binary GEOS build
|
14
|
+
def test_get_geometry_n
|
15
|
+
skip unless defined?(Geos::FFIGeos)
|
16
|
+
|
17
|
+
simple_tester(:get_geometry_n, 'POINT (0 1)', 'MULTIPOINT (0 1, 2 3)', 0)
|
18
|
+
simple_tester(:get_geometry_n, 'POINT (2 3)', 'MULTIPOINT (0 1, 2 3)', 1)
|
19
|
+
simple_tester(:get_geometry_n, nil, 'MULTIPOINT (0 1, 2 3)', 2)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryHausdorffDistanceTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_hausdorff_distance
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hausdorff_distance)
|
15
|
+
|
16
|
+
tester = lambda { |expected, g_1, g_2|
|
17
|
+
geom_1 = read(g_1)
|
18
|
+
geom_2 = read(g_2)
|
19
|
+
|
20
|
+
assert_in_delta(expected, geom_1.hausdorff_distance(geom_2), TOLERANCE)
|
21
|
+
}
|
22
|
+
|
23
|
+
geom_a = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
|
24
|
+
|
25
|
+
tester[10.0498756211209, geom_a, 'POINT(0 10)']
|
26
|
+
tester[2.23606797749979, geom_a, 'POINT(-1 0)']
|
27
|
+
tester[9.0, geom_a, 'LINESTRING (3 0 , 10 0)']
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_hausdorff_distance_with_densify_fract
|
31
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hausdorff_distance)
|
32
|
+
|
33
|
+
tester = lambda { |expected, g_1, g_2|
|
34
|
+
geom_1 = read(g_1)
|
35
|
+
geom_2 = read(g_2)
|
36
|
+
|
37
|
+
assert_in_delta(expected, geom_1.hausdorff_distance(geom_2, 0.001), TOLERANCE)
|
38
|
+
}
|
39
|
+
|
40
|
+
geom_a = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
|
41
|
+
|
42
|
+
tester[10.0498756211209, geom_a, 'POINT(0 10)']
|
43
|
+
tester[2.23606797749979, geom_a, 'POINT(-1 0)']
|
44
|
+
tester[9.0, geom_a, 'LINESTRING (3 0 , 10 0)']
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe '#hilbert_code' do
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'handles various points on the Hilbert curve' do
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hilbert_code)
|
15
|
+
|
16
|
+
geom_a = read('POINT (0 0)')
|
17
|
+
geom_b = read('POINT (1 1)')
|
18
|
+
extent = read('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))')
|
19
|
+
|
20
|
+
assert_equal(0, geom_a.hilbert_code(extent, 1))
|
21
|
+
assert_equal(0, geom_a.hilbert_code(extent, 16))
|
22
|
+
assert_equal(10, geom_b.hilbert_code(extent, 2))
|
23
|
+
assert_equal(43690, geom_b.hilbert_code(extent, 8))
|
24
|
+
assert_equal(2863311530, geom_b.hilbert_code(extent, 16))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can calculate the midpoint' do
|
28
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hilbert_code)
|
29
|
+
|
30
|
+
extent = read('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))')
|
31
|
+
|
32
|
+
assert_equal(2, extent.hilbert_code(extent, 2))
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'handles out of bounds' do
|
36
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hilbert_code)
|
37
|
+
|
38
|
+
geom = read('POINT (0 0)')
|
39
|
+
extent = read('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))')
|
40
|
+
|
41
|
+
assert_raises(Geos::GEOSException) do
|
42
|
+
geom.hilbert_code(extent, 17)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|