]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/relational_operations/relate/test_relate.hpp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / relational_operations / relate / test_relate.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2013, 2014, 2015, 2017.
6 // Modifications copyright (c) 2013-2017 Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12
13 #ifndef BOOST_GEOMETRY_TEST_RELATE_HPP
14 #define BOOST_GEOMETRY_TEST_RELATE_HPP
15
16 #include <geometry_test_common.hpp>
17
18 #include <boost/variant.hpp>
19
20 #include <boost/geometry/core/ring_type.hpp>
21 #include <boost/geometry/algorithms/relate.hpp>
22 #include <boost/geometry/algorithms/relation.hpp>
23 #include <boost/geometry/strategies/strategies.hpp>
24 #include <boost/geometry/geometries/geometries.hpp>
25 #include <boost/geometry/geometries/point_xy.hpp>
26
27 #include <boost/geometry/io/wkt/read.hpp>
28
29 #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
30 #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
31 #include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp>
32
33 namespace bgdr = bg::detail::relate;
34
35 std::string transposed(std::string matrix)
36 {
37 if ( !matrix.empty() )
38 {
39 std::swap(matrix[1], matrix[3]);
40 std::swap(matrix[2], matrix[6]);
41 std::swap(matrix[5], matrix[7]);
42 }
43 return matrix;
44 }
45
46 bool matrix_compare(std::string const& m1, std::string const& m2)
47 {
48 BOOST_ASSERT(m1.size() == 9 && m2.size() == 9);
49 for ( size_t i = 0 ; i < 9 ; ++i )
50 {
51 if ( m1[i] == '*' || m2[i] == '*' )
52 continue;
53
54 if ( m1[i] != m2[i] )
55 return false;
56 }
57 return true;
58 }
59
60 bool matrix_compare(std::string const& m, std::string const& res1, std::string const& res2)
61 {
62 return matrix_compare(m, res1)
63 || ( !res2.empty() ? matrix_compare(m, res2) : false );
64 }
65
66 std::string matrix_format(std::string const& matrix1, std::string const& matrix2)
67 {
68 return matrix1
69 + ( !matrix2.empty() ? " || " : "" ) + matrix2;
70 }
71
72 template <typename M>
73 char get_ii(M const& m)
74 {
75 using bg::detail::relate::interior;
76 return m.template get<interior, interior>();
77 }
78
79 template <typename M>
80 char get_ee(M const& m)
81 {
82 using bg::detail::relate::exterior;
83 return m.template get<exterior, exterior>();
84 }
85
86 void check_mask()
87 {
88 bg::de9im::mask m1("");
89 bg::de9im::mask m2("TTT");
90 bg::de9im::mask m3("000111222");
91 bg::de9im::mask m4("000111222FFFF");
92 bg::de9im::mask m5(std::string(""));
93 bg::de9im::mask m6(std::string("TTT"));
94 bg::de9im::mask m7(std::string("000111222"));
95 bg::de9im::mask m8(std::string("000111222FFFF"));
96
97 using bg::detail::relate::interior;
98 using bg::detail::relate::exterior;
99
100 BOOST_CHECK(get_ii(m1) == '*' && get_ee(m1) == '*');
101 BOOST_CHECK(get_ii(m2) == 'T' && get_ee(m2) == '*');
102 BOOST_CHECK(get_ii(m3) == '0' && get_ee(m3) == '2');
103 BOOST_CHECK(get_ii(m4) == '0' && get_ee(m4) == '2');
104 BOOST_CHECK(get_ii(m5) == '*' && get_ee(m5) == '*');
105 BOOST_CHECK(get_ii(m6) == 'T' && get_ee(m6) == '*');
106 BOOST_CHECK(get_ii(m7) == '0' && get_ee(m7) == '2');
107 BOOST_CHECK(get_ii(m8) == '0' && get_ee(m8) == '2');
108 }
109
110 template <typename Geometry1, typename Geometry2>
111 void check_geometry(Geometry1 const& geometry1,
112 Geometry2 const& geometry2,
113 std::string const& wkt1,
114 std::string const& wkt2,
115 std::string const& expected1,
116 std::string const& expected2 = std::string())
117 {
118 boost::variant<Geometry1> variant1 = geometry1;
119 boost::variant<Geometry2> variant2 = geometry2;
120
121 {
122 std::string res_str = bg::relation(geometry1, geometry2).str();
123 bool ok = matrix_compare(res_str, expected1, expected2);
124 BOOST_CHECK_MESSAGE(ok,
125 "relate: " << wkt1
126 << " and " << wkt2
127 << " -> Expected: " << matrix_format(expected1, expected2)
128 << " detected: " << res_str);
129
130 typedef typename bg::strategy::relate::services::default_strategy
131 <
132 Geometry1, Geometry2
133 >::type strategy_type;
134 std::string res_str0 = bg::relation(geometry1, geometry2, strategy_type()).str();
135 BOOST_CHECK(res_str == res_str0);
136
137 // test variants
138 boost::variant<Geometry1> v1 = geometry1;
139 boost::variant<Geometry2> v2 = geometry2;
140 std::string res_str1 = bg::relation(geometry1, variant2).str();
141 std::string res_str2 = bg::relation(variant1, geometry2).str();
142 std::string res_str3 = bg::relation(variant1, variant2).str();
143 BOOST_CHECK(res_str == res_str1);
144 BOOST_CHECK(res_str == res_str2);
145 BOOST_CHECK(res_str == res_str3);
146 }
147
148 // changed sequence of geometries - transposed result
149 {
150 std::string res_str = bg::relation(geometry2, geometry1).str();
151 std::string expected1_tr = transposed(expected1);
152 std::string expected2_tr = transposed(expected2);
153 bool ok = matrix_compare(res_str, expected1_tr, expected2_tr);
154 BOOST_CHECK_MESSAGE(ok,
155 "relate: " << wkt2
156 << " and " << wkt1
157 << " -> Expected: " << matrix_format(expected1_tr, expected2_tr)
158 << " detected: " << res_str);
159 }
160
161 if ( expected2.empty() )
162 {
163 {
164 bool result = bg::relate(geometry1, geometry2, bg::de9im::mask(expected1));
165 // TODO: SHOULD BE !interrupted - CHECK THIS!
166 BOOST_CHECK_MESSAGE(result,
167 "relate: " << wkt1
168 << " and " << wkt2
169 << " -> Expected: " << expected1);
170
171 typedef typename bg::strategy::relate::services::default_strategy
172 <
173 Geometry1, Geometry2
174 >::type strategy_type;
175 bool result0 = bg::relate(geometry1, geometry2, bg::de9im::mask(expected1), strategy_type());
176 BOOST_CHECK(result == result0);
177
178 // test variants
179 bool result1 = bg::relate(geometry1, variant2, bg::de9im::mask(expected1));
180 bool result2 = bg::relate(variant1, geometry2, bg::de9im::mask(expected1));
181 bool result3 = bg::relate(variant1, variant2, bg::de9im::mask(expected1));
182 BOOST_CHECK(result == result1);
183 BOOST_CHECK(result == result2);
184 BOOST_CHECK(result == result3);
185 }
186
187 if ( BOOST_GEOMETRY_CONDITION((
188 bg::detail::relate::interruption_enabled<Geometry1, Geometry2>::value )) )
189 {
190 // brake the expected output
191 std::string expected_interrupt = expected1;
192 bool changed = false;
193 BOOST_FOREACH(char & c, expected_interrupt)
194 {
195 if ( c >= '0' && c <= '9' )
196 {
197 if ( c == '0' )
198 c = 'F';
199 else
200 --c;
201
202 changed = true;
203 }
204 }
205
206 if ( changed )
207 {
208 bool result = bg::relate(geometry1, geometry2, bg::de9im::mask(expected_interrupt));
209 // TODO: SHOULD BE interrupted - CHECK THIS!
210 BOOST_CHECK_MESSAGE(!result,
211 "relate: " << wkt1
212 << " and " << wkt2
213 << " -> Expected interrupt for:" << expected_interrupt);
214 }
215 }
216 }
217 }
218
219 template <typename Geometry1, typename Geometry2>
220 void test_geometry(std::string const& wkt1,
221 std::string const& wkt2,
222 std::string const& expected1,
223 std::string const& expected2 = std::string())
224 {
225 Geometry1 geometry1;
226 Geometry2 geometry2;
227 bg::read_wkt(wkt1, geometry1);
228 bg::read_wkt(wkt2, geometry2);
229 check_geometry(geometry1, geometry2, wkt1, wkt2, expected1, expected2);
230 }
231
232 #endif // BOOST_GEOMETRY_TEST_RELATE_HPP