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.
8 // Modifications copyright (c) 2014-2016 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>
120 void check_geometry_range(Geometry1 const& g1,
122 std::string const& wkt1,
123 std::string const& wkt2,
124 Expected const& expected)
126 typedef bg::detail::no_rescale_policy robust_policy_type;
127 typedef typename bg::point_type<Geometry2>::type point_type;
129 typedef typename bg::segment_ratio_type<point_type, robust_policy_type>::type segment_ratio_type;
131 typedef bg::detail::overlay::turn_info
133 typename bg::point_type<Geometry2>::type,
135 typename bg::detail::get_turns::turn_operation_type
142 typedef bg::detail::overlay::assign_null_policy assign_policy_t;
143 typedef bg::detail::get_turns::no_interrupt_policy interrupt_policy_t;
145 std::vector<turn_info> turns;
146 interrupt_policy_t interrupt_policy;
147 robust_policy_type robust_policy;
149 // Don't switch the geometries
150 typedef bg::detail::get_turns::get_turn_info_type<Geometry1, Geometry2, assign_policy_t> turn_policy_t;
151 bg::dispatch::get_turns
153 typename bg::tag<Geometry1>::type, typename bg::tag<Geometry2>::type,
154 Geometry1, Geometry2, false, false,
156 >::apply(0, g1, 1, g2, robust_policy, turns, interrupt_policy);
158 bool ok = boost::size(expected) == turns.size();
160 #ifdef BOOST_GEOMETRY_TEST_DEBUG
161 std::vector<turn_info> turns_dbg = turns;
164 BOOST_CHECK_MESSAGE(ok,
165 "get_turns: " << wkt1 << " and " << wkt2
166 << " -> Expected turns #: " << boost::size(expected) << " detected turns #: " << turns.size());
168 for ( typename boost::range_iterator<Expected const>::type sit = boost::begin(expected) ;
169 sit != boost::end(expected) ; ++sit)
171 typename std::vector<turn_info>::iterator
172 it = std::find_if(turns.begin(), turns.end(), equal_turn(*sit));
174 if ( it != turns.end() )
179 BOOST_CHECK_MESSAGE(false,
180 "get_turns: " << wkt1 << " and " << wkt2
181 << " -> Expected turn: " << *sit << " not found");
185 #ifdef BOOST_GEOMETRY_TEST_DEBUG
188 std::cout << "Coordinates: "
189 << typeid(typename bg::coordinate_type<Geometry1>::type).name()
191 << typeid(typename bg::coordinate_type<Geometry2>::type).name()
193 std::cout << "Detected: ";
194 if ( turns_dbg.empty() )
196 std::cout << "{empty}";
200 for ( typename std::vector<turn_info>::const_iterator it = turns_dbg.begin() ;
201 it != turns_dbg.end() ; ++it )
203 if ( it != turns_dbg.begin() )
205 std::cout << bg::method_char(it->method);
206 std::cout << bg::operation_char(it->operations[0].operation);
207 std::cout << bg::operation_char(it->operations[1].operation);
208 std::cout << equal_turn<1>::is_colinear_char(it->operations[0].is_collinear);
209 std::cout << equal_turn<1>::is_colinear_char(it->operations[1].is_collinear);
212 std::cout << std::endl;
217 template <typename Geometry1, typename Geometry2, typename Expected>
218 void test_geometry_range(std::string const& wkt1, std::string const& wkt2,
219 Expected const& expected)
223 bg::read_wkt(wkt1, geometry1);
224 bg::read_wkt(wkt2, geometry2);
225 check_geometry_range(geometry1, geometry2, wkt1, wkt2, expected);
228 template <typename G1, typename G2>
229 void test_geometry(std::string const& wkt1, std::string const& wkt2,
230 std::string const& ex0)
232 test_geometry_range<G1, G2>(wkt1, wkt2, expected(ex0));
235 template <typename G1, typename G2>
236 void test_geometry(std::string const& wkt1, std::string const& wkt2,
237 std::string const& ex0, std::string const& ex1)
239 test_geometry_range<G1, G2>(wkt1, wkt2, expected(ex0)(ex1));
242 template <typename G1, typename G2>
243 void test_geometry(std::string const& wkt1, std::string const& wkt2,
244 std::string const& ex0, std::string const& ex1, std::string const& ex2)
246 test_geometry_range<G1, G2>(wkt1, wkt2, expected(ex0)(ex1)(ex2));
249 template <typename G1, typename G2>
250 void test_geometry(std::string const& wkt1, std::string const& wkt2,
251 expected_pusher const& expected)
253 test_geometry_range<G1, G2>(wkt1, wkt2, expected);
256 #endif // BOOST_GEOMETRY_TEST_ALGORITHMS_OVERLAY_TEST_GET_TURNS_HPP