• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 // Unit Test
3 
4 // Copyright (c) 2019 Oracle and/or its affiliates.
5 
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7 
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 
12 
13 #include <geometry_test_common.hpp>
14 
15 #include <boost/geometry/algorithms/detail/tupled_output.hpp>
16 #include <boost/geometry/geometries/geometries.hpp>
17 #include <boost/geometry/util/range.hpp>
18 
19 namespace bgd = boost::geometry::detail;
20 namespace bgt = boost::geometry::tuples;
21 namespace bgr = boost::geometry::range;
22 
23 template <typename MultiPoint>
add_points(MultiPoint & mp)24 void add_points(MultiPoint & mp)
25 {
26     typedef typename bg::point_type<MultiPoint>::type point_type;
27 
28     bg::range::push_back(mp, point_type(1, 2));
29     bg::range::push_back(mp, point_type(2, 3));
30     bg::range::push_back(mp, point_type(3, 4));
31 }
32 
33 template <typename TupleM, typename TupleS>
test_range_values()34 void test_range_values()
35 {
36     typedef typename bgd::tupled_range_values<TupleM>::type tuple_s;
37     BOOST_CHECK_EQUAL((boost::is_same<tuple_s, TupleS>::value), true);
38 }
39 
40 template <typename TupleM, typename TupleBI>
test_back_inserters()41 void test_back_inserters()
42 {
43     typedef typename bgd::tupled_back_inserters<TupleM>::type tuple_bi;
44     BOOST_CHECK_EQUAL((boost::is_same<tuple_bi, TupleBI>::value), true);
45 
46     TupleM tup;
47     bgd::tupled_back_inserters<TupleM>::apply(tup);
48 }
49 
50 template <typename TuplePoLs, typename TupleLsMPt>
test_all()51 void test_all()
52 {
53     BOOST_CHECK_EQUAL((bgd::is_tupled_output<TuplePoLs>::value), false);
54     BOOST_CHECK_EQUAL((bgd::is_tupled_output<TupleLsMPt>::value), true);
55 
56     BOOST_CHECK_EQUAL((bgd::tupled_output_has<TuplePoLs, bg::multi_point_tag>::value), false);
57     BOOST_CHECK_EQUAL((bgd::tupled_output_has<TupleLsMPt, bg::multi_point_tag>::value), true);
58 
59     BOOST_CHECK_EQUAL((bgd::tupled_output_has<TuplePoLs, bg::multi_polygon_tag>::value), false);
60     BOOST_CHECK_EQUAL((bgd::tupled_output_has<TupleLsMPt, bg::multi_polygon_tag>::value), false);
61 
62     TupleLsMPt tup;
63     add_points(bgd::tupled_output_get<bg::multi_point_tag>(tup));
64     BOOST_CHECK_EQUAL((boost::size(bgt::get<1>(tup))), 3u);
65 }
66 
test_main(int,char * [])67 int test_main(int, char* [])
68 {
69     typedef bg::model::point<double, 2, bg::cs::cartesian> point;
70     typedef bg::model::linestring<point> linestring;
71     typedef bg::model::polygon<point> polygon;
72     typedef bg::model::multi_point<point> multi_point;
73     typedef bg::model::multi_linestring<linestring> multi_linestring;
74     //typedef bg::model::multi_polygon<polygon> multi_polygon;
75 
76     BOOST_CHECK_EQUAL((bgd::is_range<int>::value), false);
77     BOOST_CHECK_EQUAL((bgd::is_range<linestring>::value), true);
78     BOOST_CHECK_EQUAL((bgd::is_range<multi_point>::value), true);
79 
80     BOOST_CHECK_EQUAL((bgd::is_tupled_output_element<int>::value), false);
81     BOOST_CHECK_EQUAL((bgd::is_tupled_output_element<linestring>::value), false);
82     BOOST_CHECK_EQUAL((bgd::is_tupled_output_element<multi_point>::value), true);
83 
84     test_all<boost::tuple<polygon, linestring>, boost::tuple<linestring, multi_point> >();
85     test_all<std::pair<polygon, linestring>, std::pair<linestring, multi_point> >();
86 
87     test_range_values<boost::tuple<multi_linestring, multi_point>,
88                       boost::tuples::cons<linestring,
89                         boost::tuples::cons<point,
90                             boost::tuples::null_type> > >();
91     test_range_values<std::pair<multi_linestring, multi_point>,
92                       std::pair<linestring, point> >();
93 
94     test_back_inserters<boost::tuple<multi_linestring, multi_point>,
95                         boost::tuples::cons<bgr::back_insert_iterator<multi_linestring>,
96                             boost::tuples::cons<bgr::back_insert_iterator<multi_point>,
97                                 boost::tuples::null_type> > >();
98     test_back_inserters<std::pair<multi_linestring, multi_point>,
99                         std::pair<bgr::back_insert_iterator<multi_linestring>,
100                                   bgr::back_insert_iterator<multi_point> > >();
101 
102 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_VARIADIC_TEMPLATES)
103 
104     test_all<std::tuple<polygon, linestring>, std::tuple<linestring, multi_point> >();
105 
106     test_range_values<std::tuple<multi_linestring, multi_point>,
107                       std::tuple<linestring, point> >();
108 
109     test_back_inserters<std::tuple<multi_linestring, multi_point>,
110                         std::tuple<bgr::back_insert_iterator<multi_linestring>,
111                                    bgr::back_insert_iterator<multi_point> > >();
112 
113 #endif
114 
115     return 0;
116 }
117