]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/set_operations/union/test_union_linear_linear.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / set_operations / union / test_union_linear_linear.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2014-2017, Oracle and/or its affiliates.
4 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
9
10
11 #ifndef BOOST_GEOMETRY_TEST_UNION_LINEAR_LINEAR_HPP
12 #define BOOST_GEOMETRY_TEST_UNION_LINEAR_LINEAR_HPP
13
14 #include <limits>
15
16 #include <boost/geometry/geometry.hpp>
17 #include "../test_set_ops_linear_linear.hpp"
18 #include <from_wkt.hpp>
19 #include <to_svg.hpp>
20
21
22 //==================================================================
23 //==================================================================
24 // union of (linear) geometries
25 //==================================================================
26 //==================================================================
27
28 template <typename Geometry1, typename Geometry2, typename MultiLineString>
29 inline void check_result(Geometry1 const& geometry1,
30 Geometry2 const& geometry2,
31 MultiLineString const& mls_output,
32 MultiLineString const& mls_union,
33 std::string const& case_id,
34 double tolerance)
35 {
36 BOOST_CHECK_MESSAGE( equals::apply(mls_union, mls_output, tolerance),
37 "case id: " << case_id
38 << ", union L/L: " << bg::wkt(geometry1)
39 << " " << bg::wkt(geometry2)
40 << " -> Expected: " << bg::wkt(mls_union)
41 << " computed: " << bg::wkt(mls_output) );
42 }
43
44 template
45 <
46 typename Geometry1, typename Geometry2,
47 typename MultiLineString
48 >
49 class test_union_of_geometries
50 {
51 private:
52 static inline void base_test(Geometry1 const& geometry1,
53 Geometry2 const& geometry2,
54 MultiLineString const& mls_union1,
55 MultiLineString const& mls_union2,
56 std::string const& case_id,
57 double tolerance,
58 bool test_vector_and_deque = false)
59 {
60 static bool vector_deque_already_tested = false;
61
62 typedef typename boost::range_value<MultiLineString>::type LineString;
63 typedef std::vector<LineString> linestring_vector;
64 typedef std::deque<LineString> linestring_deque;
65
66 MultiLineString mls_output;
67
68 linestring_vector ls_vector_output;
69 linestring_deque ls_deque_output;
70
71 // Check strategy passed explicitly
72 typedef typename bg::strategy::relate::services::default_strategy
73 <
74 Geometry1, Geometry2
75 >::type strategy_type;
76 bg::union_(geometry1, geometry2, mls_output, strategy_type());
77
78 check_result(geometry1, geometry2, mls_output, mls_union1, case_id, tolerance);
79
80 // Check normal behaviour
81 bg::clear(mls_output);
82 bg::union_(geometry1, geometry2, mls_output);
83
84 check_result(geometry1, geometry2, mls_output, mls_union1, case_id, tolerance);
85
86 set_operation_output("union", case_id,
87 geometry1, geometry2, mls_output);
88
89 #ifdef BOOST_GEOMETRY_TEST_DEBUG
90 std::cout << "Geometry #1: " << bg::wkt(geometry1) << std::endl;
91 std::cout << "Geometry #2: " << bg::wkt(geometry2) << std::endl;
92 std::cout << "union : " << bg::wkt(mls_output) << std::endl;
93 std::cout << "expected union : " << bg::wkt(mls_union1)
94 << std::endl;
95 std::cout << std::endl;
96 std::cout << "************************************" << std::endl;
97 std::cout << std::endl;
98 std::cout << std::endl;
99 #endif
100
101 if ( !vector_deque_already_tested && test_vector_and_deque )
102 {
103 vector_deque_already_tested = true;
104 #ifdef BOOST_GEOMETRY_TEST_DEBUG
105 std::cout << std::endl;
106 std::cout << "Testing with vector and deque as output container..."
107 << std::endl;
108 #endif
109 bg::union_(geometry1, geometry2, ls_vector_output);
110 bg::union_(geometry1, geometry2, ls_deque_output);
111
112 BOOST_CHECK(multilinestring_equals
113 <
114 false
115 >::apply(mls_union1, ls_vector_output, tolerance));
116
117 BOOST_CHECK(multilinestring_equals
118 <
119 false
120 >::apply(mls_union1, ls_deque_output, tolerance));
121
122 #ifdef BOOST_GEOMETRY_TEST_DEBUG
123 std::cout << "Done!" << std::endl << std::endl;
124 #endif
125 }
126
127 // check the union where the order of the two
128 // geometries is reversed
129 bg::clear(mls_output);
130 bg::union_(geometry2, geometry1, mls_output);
131
132 check_result(geometry1, geometry2, mls_output, mls_union2, case_id, tolerance);
133
134 #ifdef BOOST_GEOMETRY_TEST_DEBUG
135 std::cout << "Geometry #1: " << bg::wkt(geometry2) << std::endl;
136 std::cout << "Geometry #2: " << bg::wkt(geometry1) << std::endl;
137 std::cout << "union : " << bg::wkt(mls_output) << std::endl;
138 std::cout << "expected union : " << bg::wkt(mls_union2)
139 << std::endl;
140 std::cout << std::endl;
141 std::cout << "************************************" << std::endl;
142 std::cout << std::endl;
143 std::cout << std::endl;
144 #endif
145 }
146
147
148 public:
149 static inline void apply(Geometry1 const& geometry1,
150 Geometry2 const& geometry2,
151 MultiLineString const& mls_union1,
152 MultiLineString const& mls_union2,
153 std::string const& case_id,
154 double tolerance
155 = std::numeric_limits<double>::epsilon())
156 {
157 #ifdef BOOST_GEOMETRY_TEST_DEBUG
158 std::cout << "test case: " << case_id << std::endl;
159 std::stringstream sstr;
160 sstr << "svgs/" << case_id << ".svg";
161 to_svg(geometry1, geometry2, sstr.str());
162 #endif
163
164 Geometry1 rg1(geometry1);
165 bg::reverse<Geometry1>(rg1);
166
167 Geometry2 rg2(geometry2);
168 bg::reverse<Geometry2>(rg2);
169
170 test_get_turns_ll_invariance<>::apply(geometry1, geometry2);
171 #ifdef BOOST_GEOMETRY_TEST_DEBUG
172 std::cout << std::endl
173 << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
174 << std::endl << std::endl;
175 #endif
176 test_get_turns_ll_invariance<>::apply(rg1, geometry2);
177
178 base_test(geometry1, geometry2, mls_union1, mls_union2,
179 case_id, tolerance, true);
180 // base_test(geometry1, rg2, mls_sym_diff);
181 // base_test(rg1, geometry2, mls_sym_diff);
182 base_test(rg1, rg2, mls_union1, mls_union2, case_id, tolerance);
183
184 #ifdef BOOST_GEOMETRY_TEST_DEBUG
185 std::cout << std::endl;
186 std::cout << std::endl;
187 #endif
188 }
189
190
191 static inline void apply(Geometry1 const& geometry1,
192 Geometry2 const& geometry2,
193 MultiLineString const& mls_union,
194 std::string const& case_id,
195 double tolerance
196 = std::numeric_limits<double>::epsilon())
197 {
198 apply(geometry1, geometry2, mls_union, mls_union, case_id, tolerance);
199 }
200 };
201
202
203 #endif // BOOST_GEOMETRY_TEST_UNION1_HPP