1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 #ifndef BOOST_GEOMETRY_TEST_CONVERT_HPP
10 #define BOOST_GEOMETRY_TEST_CONVERT_HPP
11 
12 
13 #include <boost/geometry/algorithms/assign.hpp>
14 #include <boost/geometry/algorithms/convert.hpp>
15 #include <boost/geometry/algorithms/make.hpp>
16 #include <boost/geometry/algorithms/num_points.hpp>
17 
18 #include <boost/geometry/io/wkt/wkt.hpp>
19 
20 #include <boost/geometry/geometries/geometries.hpp>
21 #include <boost/geometry/geometries/adapted/c_array.hpp>
22 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
23 
24 #include <boost/variant/variant.hpp>
25 
26 #include <geometry_test_common.hpp>
27 
28 #include <test_common/test_point.hpp>
29 
30 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)31 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
32 
33 
34 
35 template <typename Geometry2, typename Geometry1>
36 void check_mixed(Geometry1 const& geometry1, std::string const& expected, int expected_point_count)
37 {
38     Geometry2 geometry2;
39     bg::convert(geometry1, geometry2);
40 
41     std::ostringstream out;
42     out << bg::wkt(geometry2);
43     BOOST_CHECK_EQUAL(out.str(), expected);
44 
45     std::size_t n = bg::num_points(geometry2);
46     BOOST_CHECK_MESSAGE(expected_point_count < 0 || int(n) == expected_point_count,
47             "convert: "
48             << " #points expected: " << expected_point_count
49             << " detected: " << n
50             << " expected wkt: " << expected
51             );
52 }
53 
54 template <typename Geometry1, typename Geometry2>
test_mixed(std::string const & wkt,std::string const & expected,int expected_point_count)55 void test_mixed(std::string const& wkt, std::string const& expected, int expected_point_count)
56 {
57     Geometry1 geometry1;
58     bg::read_wkt(wkt, geometry1);
59     check_mixed<Geometry2>(geometry1, expected, expected_point_count);
60     check_mixed<Geometry2>(boost::variant<Geometry1>(geometry1), expected, expected_point_count);
61 }
62 
63 template <typename Geometry1, typename Geometry2>
test_mixed_identical_result(std::string const & wkt)64 void test_mixed_identical_result(std::string const& wkt)
65 {
66     test_mixed<Geometry1, Geometry2>(wkt, wkt, -1);
67     test_mixed<Geometry2, Geometry1>(wkt, wkt, -1);
68 }
69 
70 template <typename Geometry1, typename Geometry2>
test_mixed_reversible_result(std::string const & wkt1,std::string const & wkt2)71 void test_mixed_reversible_result(std::string const& wkt1, std::string const& wkt2)
72 {
73     test_mixed<Geometry1, Geometry2>(wkt1, wkt2, -1);
74     test_mixed<Geometry2, Geometry1>(wkt2, wkt1, -1);
75 }
76 
77 #endif
78