1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // This file was modified by Oracle on 2014, 2016, 2017.
8 // Modifications copyright (c) 2014-2017 Oracle and/or its affiliates.
10 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
11 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
19 #ifndef BOOST_GEOMETRY_TEST_ALGORITHMS_OVERLAY_TEST_GET_TURNS_HPP
20 #define BOOST_GEOMETRY_TEST_ALGORITHMS_OVERLAY_TEST_GET_TURNS_HPP
25 #include <geometry_test_common.hpp>
27 #include <boost/geometry/strategies/strategies.hpp>
29 #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
31 #include <boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp>
33 #include <boost/geometry/io/wkt/read.hpp>
34 #include <boost/geometry/io/wkt/write.hpp>
36 struct expected_pusher
38 void push_back(std::string const& ex)
43 expected_pusher & operator()(std::string const& ex)
49 typedef std::vector<std::string>::iterator iterator;
50 typedef std::vector<std::string>::const_iterator const_iterator;
52 iterator begin() { return vec.begin(); }
53 iterator end() { return vec.end(); }
54 const_iterator begin() const { return vec.begin(); }
55 const_iterator end() const { return vec.end(); }
57 std::vector<std::string> vec;
60 inline expected_pusher expected(std::string const& ex)
68 equal_turn(std::string const& s) : turn_ptr(&s) {}
71 bool operator()(T const& t) const
73 std::string const& s = (*turn_ptr);
74 std::string::size_type const count = s.size();
77 ? bg::method_char(t.method) == s[0]
80 ? bg::operation_char(t.operations[0].operation) == s[1]
83 ? bg::operation_char(t.operations[1].operation) == s[2]
85 && equal_operations_ex(t.operations[0], t.operations[1], s);
88 template <typename P, typename R>
89 static bool equal_operations_ex(bg::detail::overlay::turn_operation<P, R> const& op0,
90 bg::detail::overlay::turn_operation<P, R> const& op1,
96 template <typename P, typename R>
97 static bool equal_operations_ex(bg::detail::overlay::turn_operation_linear<P, R> const& op0,
98 bg::detail::overlay::turn_operation_linear<P, R> const& op1,
101 std::string::size_type const count = s.size();
104 ? is_colinear_char(op0.is_collinear) == s[3]
107 ? is_colinear_char(op1.is_collinear) == s[4]
111 static char is_colinear_char(bool is_collinear)
113 return is_collinear ? '=' : '+';
116 const std::string * turn_ptr;
119 template <typename Geometry1, typename Geometry2, typename Expected, typename Strategy>
120 void check_geometry_range(Geometry1 const& g1,
122 std::string const& wkt1,
123 std::string const& wkt2,
124 Expected const& expected,
125 Strategy const& strategy)
127 typedef bg::detail::no_rescale_policy robust_policy_type;
128 typedef typename bg::point_type<Geometry2>::type point_type;
130 typedef typename bg::segment_ratio_type
132 point_type, robust_policy_type
133 >::type segment_ratio_type;
135 typedef bg::detail::overlay::turn_info
137 typename bg::point_type<Geometry2>::type,
139 typename bg::detail::get_turns::turn_operation_type
146 typedef bg::detail::overlay::assign_null_policy assign_policy_t;
147 typedef bg::detail::get_turns::no_interrupt_policy interrupt_policy_t;
149 std::vector<turn_info> turns;
150 interrupt_policy_t interrupt_policy;
151 robust_policy_type robust_policy;
153 // Don't switch the geometries
154 typedef bg::detail::get_turns::get_turn_info_type
156 Geometry1, Geometry2, assign_policy_t
159 bg::dispatch::get_turns
161 typename bg::tag<Geometry1>::type, typename bg::tag<Geometry2>::type,
162 Geometry1, Geometry2, false, false,
164 >::apply(0, g1, 1, g2, strategy, robust_policy, turns, interrupt_policy);
166 bool ok = boost::size(expected) == turns.size();
168 #ifdef BOOST_GEOMETRY_TEST_DEBUG
169 std::vector<turn_info> turns_dbg = turns;
172 BOOST_CHECK_MESSAGE(ok,
173 "get_turns: " << wkt1 << " and " << wkt2
174 << " -> Expected turns #: " << boost::size(expected) << " detected turns #: " << turns.size());
176 for ( typename boost::range_iterator<Expected const>::type sit = boost::begin(expected) ;
177 sit != boost::end(expected) ; ++sit)
179 typename std::vector<turn_info>::iterator
180 it = std::find_if(turns.begin(), turns.end(), equal_turn(*sit));
182 if ( it != turns.end() )
187 BOOST_CHECK_MESSAGE(false,
188 "get_turns: " << wkt1 << " and " << wkt2
189 << " -> Expected turn: " << *sit << " not found");
193 #ifdef BOOST_GEOMETRY_TEST_DEBUG
196 std::cout << "Coordinates: "
197 << typeid(typename bg::coordinate_type<Geometry1>::type).name()
199 << typeid(typename bg::coordinate_type<Geometry2>::type).name()
201 std::cout << "Detected: ";
202 if ( turns_dbg.empty() )
204 std::cout << "{empty}";
208 for ( typename std::vector<turn_info>::const_iterator it = turns_dbg.begin() ;
209 it != turns_dbg.end() ; ++it )
211 if ( it != turns_dbg.begin() )
213 std::cout << bg::method_char(it->method);
214 std::cout << bg::operation_char(it->operations[0].operation);
215 std::cout << bg::operation_char(it->operations[1].operation);
216 std::cout << equal_turn<1>::is_colinear_char(it->operations[0].is_collinear);
217 std::cout << equal_turn<1>::is_colinear_char(it->operations[1].is_collinear);
220 std::cout << std::endl;
225 template <typename Geometry1, typename Geometry2, typename Expected>
226 void check_geometry_range(Geometry1 const& g1,
228 std::string const& wkt1,
229 std::string const& wkt2,
230 Expected const& expected)
232 typename bg::strategy::intersection::services::default_strategy
234 typename bg::cs_tag<Geometry1>::type
237 check_geometry_range(g1, g2, wkt1, wkt2, expected, strategy);
240 template <typename Geometry1, typename Geometry2, typename Expected, typename Strategy>
241 void test_geometry_range(std::string const& wkt1, std::string const& wkt2,
242 Expected const& expected, Strategy const& strategy)
246 bg::read_wkt(wkt1, geometry1);
247 bg::read_wkt(wkt2, geometry2);
248 check_geometry_range(geometry1, geometry2, wkt1, wkt2, expected, strategy);
251 template <typename Geometry1, typename Geometry2, typename Expected>
252 void test_geometry_range(std::string const& wkt1, std::string const& wkt2,
253 Expected const& expected)
257 bg::read_wkt(wkt1, geometry1);
258 bg::read_wkt(wkt2, geometry2);
259 check_geometry_range(geometry1, geometry2, wkt1, wkt2, expected);
262 template <typename G1, typename G2>
263 void test_geometry(std::string const& wkt1, std::string const& wkt2,
264 std::string const& ex0)
266 test_geometry_range<G1, G2>(wkt1, wkt2, expected(ex0));
269 template <typename G1, typename G2>
270 void test_geometry(std::string const& wkt1, std::string const& wkt2,
271 std::string const& ex0, std::string const& ex1)
273 test_geometry_range<G1, G2>(wkt1, wkt2, expected(ex0)(ex1));
276 template <typename G1, typename G2>
277 void test_geometry(std::string const& wkt1, std::string const& wkt2,
278 std::string const& ex0, std::string const& ex1, std::string const& ex2)
280 test_geometry_range<G1, G2>(wkt1, wkt2, expected(ex0)(ex1)(ex2));
283 template <typename G1, typename G2>
284 void test_geometry(std::string const& wkt1, std::string const& wkt2,
285 expected_pusher const& expected)
287 test_geometry_range<G1, G2>(wkt1, wkt2, expected);
290 template <typename G1, typename G2, typename Strategy>
291 void test_geometry(std::string const& wkt1, std::string const& wkt2,
292 expected_pusher const& expected,
293 Strategy const& strategy)
295 test_geometry_range<G1, G2>(wkt1, wkt2, expected, strategy);
298 #endif // BOOST_GEOMETRY_TEST_ALGORITHMS_OVERLAY_TEST_GET_TURNS_HPP