1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
11 #ifndef BOOST_GEOMETRY_TEST_UNION_LINEAR_LINEAR_HPP
12 #define BOOST_GEOMETRY_TEST_UNION_LINEAR_LINEAR_HPP
16 #include <boost/geometry/geometry.hpp>
17 #include "../test_set_ops_linear_linear.hpp"
18 #include <from_wkt.hpp>
22 //==================================================================
23 //==================================================================
24 // union of (linear) geometries
25 //==================================================================
26 //==================================================================
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,
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) );
46 typename Geometry1, typename Geometry2,
47 typename MultiLineString
49 class test_union_of_geometries
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,
58 bool test_vector_and_deque = false)
60 static bool vector_deque_already_tested = false;
62 typedef typename boost::range_value<MultiLineString>::type LineString;
63 typedef std::vector<LineString> linestring_vector;
64 typedef std::deque<LineString> linestring_deque;
66 MultiLineString mls_output;
68 linestring_vector ls_vector_output;
69 linestring_deque ls_deque_output;
71 // Check strategy passed explicitly
72 typedef typename bg::strategy::relate::services::default_strategy
75 >::type strategy_type;
76 bg::union_(geometry1, geometry2, mls_output, strategy_type());
78 check_result(geometry1, geometry2, mls_output, mls_union1, case_id, tolerance);
80 // Check normal behaviour
81 bg::clear(mls_output);
82 bg::union_(geometry1, geometry2, mls_output);
84 check_result(geometry1, geometry2, mls_output, mls_union1, case_id, tolerance);
86 set_operation_output("union", case_id,
87 geometry1, geometry2, mls_output);
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)
95 std::cout << std::endl;
96 std::cout << "************************************" << std::endl;
97 std::cout << std::endl;
98 std::cout << std::endl;
101 if ( !vector_deque_already_tested && test_vector_and_deque )
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..."
109 bg::union_(geometry1, geometry2, ls_vector_output);
110 bg::union_(geometry1, geometry2, ls_deque_output);
112 BOOST_CHECK(multilinestring_equals
115 >::apply(mls_union1, ls_vector_output, tolerance));
117 BOOST_CHECK(multilinestring_equals
120 >::apply(mls_union1, ls_deque_output, tolerance));
122 #ifdef BOOST_GEOMETRY_TEST_DEBUG
123 std::cout << "Done!" << std::endl << std::endl;
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);
132 check_result(geometry1, geometry2, mls_output, mls_union2, case_id, tolerance);
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)
140 std::cout << std::endl;
141 std::cout << "************************************" << std::endl;
142 std::cout << std::endl;
143 std::cout << std::endl;
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,
155 = std::numeric_limits<double>::epsilon())
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());
164 Geometry1 rg1(geometry1);
165 bg::reverse<Geometry1>(rg1);
167 Geometry2 rg2(geometry2);
168 bg::reverse<Geometry2>(rg2);
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;
176 test_get_turns_ll_invariance<>::apply(rg1, geometry2);
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);
184 #ifdef BOOST_GEOMETRY_TEST_DEBUG
185 std::cout << std::endl;
186 std::cout << std::endl;
191 static inline void apply(Geometry1 const& geometry1,
192 Geometry2 const& geometry2,
193 MultiLineString const& mls_union,
194 std::string const& case_id,
196 = std::numeric_limits<double>::epsilon())
198 apply(geometry1, geometry2, mls_union, mls_union, case_id, tolerance);
203 #endif // BOOST_GEOMETRY_TEST_UNION1_HPP