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