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,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryInteriorRingNTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_interior_ring_n
|
14
|
+
simple_tester(
|
15
|
+
:interior_ring_n,
|
16
|
+
'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
|
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
|
+
0
|
22
|
+
)
|
23
|
+
|
24
|
+
simple_tester(
|
25
|
+
:interior_ring_n,
|
26
|
+
'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
|
27
|
+
'POLYGON (
|
28
|
+
(10 10, 10 14, 14 14, 14 10, 10 10),
|
29
|
+
(11 11, 11 12, 12 12, 12 11, 11 11),
|
30
|
+
(13 11, 13 12, 13.5 12, 13.5 11, 13 11)
|
31
|
+
)',
|
32
|
+
0
|
33
|
+
)
|
34
|
+
|
35
|
+
simple_tester(
|
36
|
+
:interior_ring_n,
|
37
|
+
'LINEARRING (13 11, 13 12, 13.5 12, 13.5 11, 13 11)',
|
38
|
+
'POLYGON (
|
39
|
+
(10 10, 10 14, 14 14, 14 10, 10 10),
|
40
|
+
(11 11, 11 12, 12 12, 12 11, 11 11),
|
41
|
+
(13 11, 13 12, 13.5 12, 13.5 11, 13 11)
|
42
|
+
)',
|
43
|
+
1
|
44
|
+
)
|
45
|
+
|
46
|
+
assert_raises(Geos::IndexBoundsError) do
|
47
|
+
simple_tester(
|
48
|
+
:interior_ring_n,
|
49
|
+
nil,
|
50
|
+
'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))',
|
51
|
+
0
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_raises(NoMethodError) do
|
56
|
+
simple_tester(
|
57
|
+
:interior_ring_n,
|
58
|
+
nil,
|
59
|
+
'POINT (0 0)',
|
60
|
+
0
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryInteriorRingsTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_interior_rings
|
14
|
+
array_tester(
|
15
|
+
:interior_rings,
|
16
|
+
['LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)'],
|
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
|
+
array_tester(
|
24
|
+
:interior_rings,
|
25
|
+
[
|
26
|
+
'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
|
27
|
+
'LINEARRING (13 11, 13 12, 13.5 12, 13.5 11, 13 11)'
|
28
|
+
],
|
29
|
+
'POLYGON (
|
30
|
+
(10 10, 10 14, 14 14, 14 10, 10 10),
|
31
|
+
(11 11, 11 12, 12 12, 12 11, 11 11),
|
32
|
+
(13 11, 13 12, 13.5 12, 13.5 11, 13 11)
|
33
|
+
)'
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryInterpolateTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_interpolate
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:interpolate)
|
15
|
+
|
16
|
+
simple_tester(:interpolate, 'POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, false)
|
17
|
+
simple_tester(:interpolate, 'POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, true)
|
18
|
+
|
19
|
+
simple_tester(:interpolate, 'POINT (5 0)', 'LINESTRING(0 0, 10 0)', 5, false)
|
20
|
+
simple_tester(:interpolate, 'POINT (5 0)', 'LINESTRING(0 0, 10 0)', 0.5, true)
|
21
|
+
|
22
|
+
simple_tester(:interpolate, 'POINT (10 0)', 'LINESTRING(0 0, 10 0)', 20, false)
|
23
|
+
simple_tester(:interpolate, 'POINT (10 0)', 'LINESTRING(0 0, 10 0)', 2, true)
|
24
|
+
|
25
|
+
assert_raises(Geos::GEOSException) do
|
26
|
+
read('POINT(1 2)').interpolate(0)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_interpolate_normalized
|
31
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:interpolate_normalized)
|
32
|
+
|
33
|
+
tester = lambda { |expected, g, d|
|
34
|
+
geom = read(g)
|
35
|
+
|
36
|
+
assert_equal(expected, write(geom.interpolate_normalized(d)))
|
37
|
+
}
|
38
|
+
|
39
|
+
writer.trim = true
|
40
|
+
|
41
|
+
tester['POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0]
|
42
|
+
tester['POINT (5 0)', 'LINESTRING(0 0, 10 0)', 0.5]
|
43
|
+
tester['POINT (10 0)', 'LINESTRING(0 0, 10 0)', 2]
|
44
|
+
|
45
|
+
assert_raises(Geos::GEOSException) do
|
46
|
+
read('POINT(1 2)').interpolate_normalized(0)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryIntersectionTests < 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
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryLargestEmptyCircleTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_largest_empty_circle
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:largest_empty_circle)
|
15
|
+
|
16
|
+
geom = read('MULTIPOINT ((100 100), (100 200), (200 200), (200 100))')
|
17
|
+
output = geom.largest_empty_circle(0.001)
|
18
|
+
|
19
|
+
assert_equal('LINESTRING (150 150, 100 100)', write(output))
|
20
|
+
|
21
|
+
geom = read('MULTIPOINT ((100 100), (100 200), (200 200), (200 100))')
|
22
|
+
output = geom.largest_empty_circle(0.001, boundary: read('MULTIPOINT ((100 100), (100 200), (200 200), (200 100))'))
|
23
|
+
|
24
|
+
assert_equal('LINESTRING (100 100, 100 100)', write(output))
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryLengthTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_length
|
14
|
+
simple_tester(:length, 4.0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
|
15
|
+
simple_tester(:length, 0.0, 'POINT (0 0)')
|
16
|
+
simple_tester(:length, 10.0, 'LINESTRING (0 0 , 10 0)')
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe '#line_merge_directed' do
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'merges lines in MULTILINESTRINGs' do
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:line_merge_directed)
|
15
|
+
|
16
|
+
simple_tester(
|
17
|
+
:line_merge_directed,
|
18
|
+
'LINESTRING (0 -5, 0 0, 0 100)',
|
19
|
+
'MULTILINESTRING ((0 0, 0 100), (0 -5, 0 0))'
|
20
|
+
)
|
21
|
+
|
22
|
+
simple_tester(
|
23
|
+
:line_merge_directed,
|
24
|
+
'MULTILINESTRING ((0 0, 0 100), (0 0, 0 -5))',
|
25
|
+
'MULTILINESTRING ((0 0, 0 100), (0 0, 0 -5))'
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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_line_merge
|
14
|
+
simple_tester(
|
15
|
+
:line_merge,
|
16
|
+
'LINESTRING (0 0, 10 10, 10 0, 5 0, 5 -5)',
|
17
|
+
'MULTILINESTRING(
|
18
|
+
(0 0, 10 10),
|
19
|
+
(10 10, 10 0),
|
20
|
+
(5 0, 10 0),
|
21
|
+
(5 -5, 5 0)
|
22
|
+
)'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryLineStringEnumeratorTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_line_string_enumerator
|
14
|
+
geom = read('LINESTRING(0 0, 10 10)')
|
15
|
+
|
16
|
+
assert_kind_of(Enumerable, geom.each)
|
17
|
+
assert_kind_of(Enumerable, geom.to_enum)
|
18
|
+
assert_equal(geom, geom.each(&EMPTY_BLOCK))
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,76 @@
|
|
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_line_substring
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:line_substring)
|
15
|
+
|
16
|
+
simple_tester(
|
17
|
+
:line_substring,
|
18
|
+
'LINESTRING (0 0, 1 1)',
|
19
|
+
'LINESTRING (0 0, 2 2)',
|
20
|
+
0,
|
21
|
+
0.5
|
22
|
+
)
|
23
|
+
|
24
|
+
simple_tester(
|
25
|
+
:line_substring,
|
26
|
+
'MULTILINESTRING ((0 52.5, 0 100), (0 -5, 0 0))',
|
27
|
+
'MULTILINESTRING((0 0, 0 100),(0 -5, 0 0))',
|
28
|
+
0.5,
|
29
|
+
1
|
30
|
+
)
|
31
|
+
|
32
|
+
simple_tester(
|
33
|
+
:line_substring,
|
34
|
+
'LINESTRING (1 1, 1 1)',
|
35
|
+
'LINESTRING (0 0, 2 2)',
|
36
|
+
0.5,
|
37
|
+
0.5
|
38
|
+
)
|
39
|
+
|
40
|
+
simple_tester(
|
41
|
+
:line_substring,
|
42
|
+
'LINESTRING (1 1, 1 1)',
|
43
|
+
'LINESTRING (0 0, 2 2)',
|
44
|
+
0.5,
|
45
|
+
0.5
|
46
|
+
)
|
47
|
+
|
48
|
+
assert_raises(Geos::GEOSException, 'IllegalArgumentException: end fraction must be <= 1') do
|
49
|
+
simple_tester(
|
50
|
+
:line_substring,
|
51
|
+
'',
|
52
|
+
'LINESTRING (0 0, 2 2)',
|
53
|
+
0.5,
|
54
|
+
1.5
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_raises(Geos::GEOSException, 'IllegalArgumentException: end fraction must be <= 1') do
|
59
|
+
simple_tester(
|
60
|
+
:line_substring,
|
61
|
+
'',
|
62
|
+
'LINESTRING (0 0, 2 2)',
|
63
|
+
0.5,
|
64
|
+
-0.1
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
simple_tester(
|
69
|
+
:line_substring,
|
70
|
+
'LINESTRING (0.5 0.5, 0 0)',
|
71
|
+
'LINESTRING (0 0, 1 1)',
|
72
|
+
0.5,
|
73
|
+
0
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryMakeValidTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_make_valid
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:make_valid)
|
15
|
+
|
16
|
+
geom = read('POLYGON((0 0, 1 1, 0 1, 1 0, 0 0))')
|
17
|
+
|
18
|
+
assert_equal(
|
19
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
20
|
+
'MULTIPOLYGON (((1 0, 0 0, 0.5 0.5, 1 0)), ((1 1, 0.5 0.5, 0 1, 1 1)))'
|
21
|
+
else
|
22
|
+
'MULTIPOLYGON (((0 0, 0.5 0.5, 1 0, 0 0)), ((0.5 0.5, 0 1, 1 1, 0.5 0.5)))'
|
23
|
+
end,
|
24
|
+
write(geom.make_valid)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryMaximumInscribledCircleTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_maximum_inscribed_circle
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:maximum_inscribed_circle)
|
15
|
+
|
16
|
+
geom = read('POLYGON ((100 200, 200 200, 200 100, 100 100, 100 200))')
|
17
|
+
output = geom.maximum_inscribed_circle(0.001)
|
18
|
+
|
19
|
+
assert_equal('LINESTRING (150 150, 150 200)', write(output))
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryMinimumBoundingCircleTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_minimum_bounding_circle
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_bounding_circle)
|
15
|
+
|
16
|
+
geom = read('LINESTRING(0 10, 0 20)')
|
17
|
+
|
18
|
+
assert_equal(
|
19
|
+
'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))',
|
20
|
+
write(geom.minimum_bounding_circle.snap_to_grid(1))
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryMinimumClearanceTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_minimum_clearance
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_clearance)
|
15
|
+
|
16
|
+
tester = lambda { |expected_clearance, geom|
|
17
|
+
geom = read(geom)
|
18
|
+
clearance = geom.minimum_clearance
|
19
|
+
|
20
|
+
if expected_clearance.eql?(Float::INFINITY)
|
21
|
+
assert_predicate(clearance, :infinite?)
|
22
|
+
else
|
23
|
+
assert_in_delta(expected_clearance, clearance, TOLERANCE)
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
tester[Float::INFINITY, 'LINESTRING EMPTY']
|
28
|
+
tester[20, 'LINESTRING (30 100, 10 100)']
|
29
|
+
tester[100, 'LINESTRING (200 200, 200 100)']
|
30
|
+
tester[3.49284983912134e-05, 'LINESTRING (-112.712119 33.575919, -112.712127 33.575885)']
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_minimum_clearance_line
|
34
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_clearance_line)
|
35
|
+
|
36
|
+
tester = lambda { |expected_geom, geom|
|
37
|
+
geom = read(geom)
|
38
|
+
clearance_geom = geom.minimum_clearance_line
|
39
|
+
|
40
|
+
assert_equal(expected_geom, write(clearance_geom))
|
41
|
+
}
|
42
|
+
|
43
|
+
tester['LINESTRING EMPTY', 'MULTIPOINT ((100 100), (100 100))']
|
44
|
+
tester['LINESTRING (30 100, 10 100)', 'MULTIPOINT ((100 100), (10 100), (30 100))']
|
45
|
+
tester['LINESTRING (200 200, 200 100)', 'POLYGON ((100 100, 300 100, 200 200, 100 100))']
|
46
|
+
tester[
|
47
|
+
'LINESTRING (-112.712119 33.575919, -112.712127 33.575885)',
|
48
|
+
'0106000000010000000103000000010000001a00000035d42824992d5cc01b834e081dca404073b9c150872d5cc03465a71fd4c940400ec00644882d5cc03b8a' \
|
49
|
+
'73d4d1c94040376dc669882d5cc0bf9cd9aed0c940401363997e892d5cc002f4fbfecdc94040ca4e3fa88b2d5cc0a487a1d5c9c940408f1ce90c8c2d5cc06989' \
|
50
|
+
'95d1c8c94040fab836548c2d5cc0bd175fb4c7c940409f1f46088f2d5cc0962023a0c2c940407b15191d902d5cc068041bd7bfc940400397c79a912d5cc0287d' \
|
51
|
+
'21e4bcc940403201bf46922d5cc065e3c116bbc940409d9d0c8e922d5cc0060fd3beb9c940400ef7915b932d5cc09012bbb6b7c940404fe61f7d932d5cc0e4a0' \
|
52
|
+
'8499b6c94040fc71fbe5932d5cc0ea9106b7b5c94040eaec6470942d5cc0c2323674b3c94040601dc70f952d5cc043588d25acc94040aea06989952d5cc03ecf' \
|
53
|
+
'9f36aac94040307f85cc952d5cc0e5eb32fca7c94040dd0a6135962d5cc01b615111a7c9404048a7ae7c962d5cc00a2aaa7ea5c94040f4328ae5962d5cc05eb8' \
|
54
|
+
'7361a4c94040c49448a2972d5cc04d81cccea2c940407c80eecb992d5cc06745d4449fc9404035d42824992d5cc01b834e081dca4040'
|
55
|
+
]
|
56
|
+
tester['LINESTRING EMPTY', 'POLYGON EMPTY']
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryMinimumRotatedRectangleTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_minimum_rotated_rectangle
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_rotated_rectangle)
|
15
|
+
|
16
|
+
geom = read('POLYGON ((1 6, 6 11, 11 6, 6 1, 1 6))')
|
17
|
+
minimum_rotated_rectangle = geom.minimum_rotated_rectangle
|
18
|
+
|
19
|
+
assert_equal(
|
20
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
21
|
+
'POLYGON ((6 1, 1 6, 6 11, 11 6, 6 1))'
|
22
|
+
else
|
23
|
+
'POLYGON ((6 1, 11 6, 6 11, 1 6, 6 1))'
|
24
|
+
end,
|
25
|
+
write(minimum_rotated_rectangle)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryMinimumWidthTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_minimum_width
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:minimum_width)
|
15
|
+
|
16
|
+
geom = read('POLYGON ((0 0, 0 15, 5 10, 5 0, 0 0))')
|
17
|
+
output = geom.minimum_width
|
18
|
+
|
19
|
+
assert_equal('LINESTRING (0 0, 5 0)', write(output))
|
20
|
+
|
21
|
+
geom = read('LINESTRING (0 0,0 10, 10 10)')
|
22
|
+
output = geom.minimum_width
|
23
|
+
|
24
|
+
assert_equal('LINESTRING (5 5, 0 10)', write(output))
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryMiscTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_empty_geometry_has_0_area
|
14
|
+
assert_equal(0, read('POLYGON EMPTY').area)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_empty_geometry_has_0_length
|
18
|
+
assert_equal(0, read('POLYGON EMPTY').length)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_to_s
|
22
|
+
assert_match(/^\#<Geos::Point: .+>$/, read('POINT(0 0)').to_s)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryNearestPointsTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_nearest_points
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:nearest_points)
|
15
|
+
|
16
|
+
tester = lambda { |expected, g_1, g_2|
|
17
|
+
geom_1 = read(g_1)
|
18
|
+
geom_2 = read(g_2)
|
19
|
+
|
20
|
+
cs = geom_1.nearest_points(geom_2)
|
21
|
+
result = cs.to_s if cs
|
22
|
+
|
23
|
+
if expected.nil?
|
24
|
+
assert_nil(result)
|
25
|
+
else
|
26
|
+
assert_equal(expected, result)
|
27
|
+
end
|
28
|
+
}
|
29
|
+
|
30
|
+
tester[
|
31
|
+
nil,
|
32
|
+
'POINT EMPTY',
|
33
|
+
'POINT EMPTY'
|
34
|
+
]
|
35
|
+
|
36
|
+
tester[
|
37
|
+
if Geos::GEOS_NICE_VERSION >= '030800'
|
38
|
+
'5.0 5.0, 8.0 8.0'
|
39
|
+
else
|
40
|
+
'5.0 5.0 NaN, 8.0 8.0 NaN'
|
41
|
+
end,
|
42
|
+
'POLYGON((1 1, 1 5, 5 5, 5 1, 1 1))',
|
43
|
+
'POLYGON((8 8, 9 9, 9 10, 8 8))'
|
44
|
+
]
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryNodeTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_node
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:node)
|
15
|
+
|
16
|
+
simple_tester(
|
17
|
+
:node,
|
18
|
+
'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0, 5 -5, 5 0), (5 0, 5 5))',
|
19
|
+
'LINESTRING(0 0, 10 0, 5 -5, 5 5)'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|