]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/overlay/get_ring.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / overlay / get_ring.cpp
1 // Boost.Geometry
2 // Unit Test
3
4 // Copyright (c) 2021 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #include <geometry_test_common.hpp>
11
12 #include <boost/geometry/algorithms/detail/overlay/get_ring.hpp>
13
14 #include <boost/geometry/algorithms/area.hpp>
15 #include <boost/geometry/algorithms/is_valid.hpp>
16
17 #include <boost/geometry/strategies/strategies.hpp>
18 #include <boost/geometry/geometries/geometries.hpp>
19 #include <boost/geometry/io/wkt/wkt.hpp>
20
21 namespace
22 {
23
24 bool g_debug = false;
25
26 std::string const simplex = "POLYGON((0 2,1 2,1 1,0 1,0 2))";
27 std::string const case_a = "POLYGON((1 0,0 5,5 2,1 0),(2 1,3 2,1 3,2 1))";
28 std::string const multi = "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0),(1 1,2 1,2 2,1 2,1 1),(3 3,4 3,4 4,3 4,3 3)),((6 6,6 10,10 10,10 6,6 6),(7 7,8 7,8 8,7 7)))";
29 }
30
31 template <typename Geometry>
32 void test_get_ring(std::string const& case_id, std::string const& wkt,
33 bg::ring_identifier const& ring_id,
34 std::string const& expected_wkt)
35 {
36 using tag = typename bg::tag<Geometry>::type;
37
38 Geometry geometry;
39 bg::read_wkt(wkt, geometry);
40
41 auto const ring = bg::detail::overlay::get_ring<tag>::apply(ring_id, geometry);
42
43 if (g_debug)
44 {
45 std::cout << case_id
46 << " valid: " << bg::is_valid(geometry)
47 << " area: " << bg::area(geometry)
48 << " area(ring): " << bg::area(ring)
49 << " wkt(ring): " << bg::wkt(ring)
50 << std::endl;
51 }
52
53 std::ostringstream out;
54 out << bg::wkt(ring);
55 std::string const detected = out.str();
56 BOOST_CHECK_MESSAGE(detected == expected_wkt, "get_ring: " << case_id
57 << " expected: " << expected_wkt
58 << " detected: " << detected);
59 }
60
61 template <typename Geometry>
62 void test_segment_count_on_ring(std::string const& case_id, std::string const& wkt,
63 bg::ring_identifier const& ring_id, bg::signed_size_type expected_count)
64 {
65 Geometry geometry;
66 bg::read_wkt(wkt, geometry);
67
68 auto const detected_count = bg::detail::overlay::segment_count_on_ring(geometry, ring_id);
69
70 BOOST_CHECK_MESSAGE(detected_count == expected_count,
71 "test_get_ring: " << case_id
72 << " expected: " << expected_count
73 << " detected: " << detected_count);
74 }
75
76 template <typename Geometry>
77 void test_segment_distance(std::string const& case_id, int line, std::string const& wkt,
78 bg::segment_identifier const& id1,
79 bg::segment_identifier const& id2,
80 bg::signed_size_type expected_distance)
81 {
82 Geometry geometry;
83 bg::read_wkt(wkt, geometry);
84
85 auto const detected_distance = bg::detail::overlay::segment_distance(geometry, id1, id2);
86
87 BOOST_CHECK_MESSAGE(detected_distance == expected_distance,
88 "segment_distance: " << case_id << " (" << line << ")"
89 << " expected: " << expected_distance
90 << " detected: " << detected_distance);
91 }
92
93 template <typename Point, bool Closed>
94 void test_get_ring()
95 {
96 using ring = bg::model::ring<Point, Closed>;
97 using polygon = bg::model::polygon<Point, Closed>;
98 using multi_polygon = bg::model::multi_polygon<polygon>;
99
100 test_get_ring<ring>("ring_simplex", simplex, {0, -1, -1}, simplex);
101 test_get_ring<polygon>("polygon_simplex", simplex, {0, -1, -1}, simplex);
102 test_get_ring<polygon>("case_a_outer", case_a, {0, -1, -1}, "POLYGON((1 0,0 5,5 2,1 0))");
103 test_get_ring<polygon>("case_a_0", case_a, {0, -1, 0}, "POLYGON((2 1,3 2,1 3,2 1))");
104 test_get_ring<multi_polygon>("multi_0_outer", multi, {0, 0, -1}, "POLYGON((0 0,0 5,5 5,5 0,0 0))");
105 test_get_ring<multi_polygon>("multi_0_0", multi, {0, 0, 0}, "POLYGON((1 1,2 1,2 2,1 2,1 1))");
106 test_get_ring<multi_polygon>("multi_0_1", multi, {0, 0, 1}, "POLYGON((3 3,4 3,4 4,3 4,3 3))");
107 test_get_ring<multi_polygon>("multi_1_outer", multi, {0, 1, -1}, "POLYGON((6 6,6 10,10 10,10 6,6 6))");
108 test_get_ring<multi_polygon>("multi_1_1", multi, {0, 1, 0}, "POLYGON((7 7,8 7,8 8,7 7))");
109 }
110
111 template <typename Point, bool Closed>
112 void test_segment_count_on_ring()
113 {
114 using ring = bg::model::ring<Point, true, Closed>;
115 using polygon = bg::model::polygon<Point, true, Closed>;
116 using multi_polygon = bg::model::multi_polygon<polygon>;
117
118 test_segment_count_on_ring<ring>("ring_simplex", simplex, {0, -1, -1}, 4);
119 test_segment_count_on_ring<polygon>("polygon_simplex", simplex, {0, -1, -1}, 4);
120 test_segment_count_on_ring<polygon>("case_a_outer", case_a, {0, -1, -1}, 3);
121 test_segment_count_on_ring<polygon>("case_a_0", case_a, {0, -1, 0}, 3);
122 test_segment_count_on_ring<multi_polygon>("multi_0_outer", multi, {0, 0, -1}, 4);
123 test_segment_count_on_ring<multi_polygon>("multi_0_0", multi, {0, 0, 0}, 4);
124 test_segment_count_on_ring<multi_polygon>("multi_0_1", multi, {0, 0, 1}, 4);
125 test_segment_count_on_ring<multi_polygon>("multi_1_outer", multi, {0, 1, -1}, 4);
126 test_segment_count_on_ring<multi_polygon>("multi_1_1", multi, {0, 1, 0}, 3);
127 }
128
129 template <typename Point, bool Closed>
130 void test_segment_distance()
131 {
132 using ring = bg::model::ring<Point, true, Closed>;
133
134 std::string const case_id = "ring_simplex";
135
136 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 0}, {0, -1, -1, 0}, 0);
137 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 0}, {0, -1, -1, 1}, 1);
138 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 0}, {0, -1, -1, 2}, 2);
139 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 0}, {0, -1, -1, 3}, 3);
140
141 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 1}, {0, -1, -1, 0}, 3);
142 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 1}, {0, -1, -1, 1}, 0);
143 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 1}, {0, -1, -1, 2}, 1);
144 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 1}, {0, -1, -1, 3}, 2);
145
146 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 2}, {0, -1, -1, 0}, 2);
147 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 2}, {0, -1, -1, 1}, 3);
148 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 2}, {0, -1, -1, 2}, 0);
149 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 2}, {0, -1, -1, 3}, 1);
150
151 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 3}, {0, -1, -1, 0}, 1);
152 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 3}, {0, -1, -1, 1}, 2);
153 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 3}, {0, -1, -1, 2}, 3);
154 test_segment_distance<ring>(case_id, __LINE__, simplex, {0, -1, -1, 3}, {0, -1, -1, 3}, 0);
155 }
156
157 int test_main(int, char* [])
158 {
159 using point = bg::model::point<default_test_type, 2, bg::cs::cartesian>;
160 test_get_ring<point, true>();
161 test_segment_count_on_ring<point, true>();
162 test_segment_count_on_ring<point, false>();
163 test_segment_distance<point, true>();
164 test_segment_distance<point, false>();
165 return 0;
166 }