• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2020 Digvijay Janartha, Hamirpur, India.
5 
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 #include <iostream>
11 
12 #include <geometry_test_common.hpp>
13 
14 #include <boost/core/ignore_unused.hpp>
15 #include <boost/geometry/algorithms/make.hpp>
16 #include <boost/geometry/algorithms/append.hpp>
17 #include <boost/geometry/geometries/point.hpp>
18 #include <boost/geometry/geometries/point_xy.hpp>
19 #include <boost/geometry/geometries/linestring.hpp>
20 #include <boost/geometry/geometries/multi_linestring.hpp>
21 #include <boost/geometry/geometries/concepts/multi_linestring_concept.hpp>
22 #include <boost/geometry/geometries/adapted/c_array.hpp>
23 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
24 #include <boost/geometry/io/dsv/write.hpp>
25 
26 #include <test_common/test_point.hpp>
27 
28 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)29 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
30 
31 #ifdef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
32 #include <initializer_list>
33 #endif//BOOST_NO_CXX11_HDR_INITIALIZER_LIST
34 
35 template <typename P>
36 bg::model::linestring<P> create_linestring()
37 {
38     bg::model::linestring<P> l1;
39     P p1(1, 2);
40     bg::append(l1, p1);
41     return l1;
42 }
43 
44 template <typename P, typename L>
create_multi_linestring()45 bg::model::multi_linestring<L> create_multi_linestring()
46 {
47     bg::model::multi_linestring<L> ml1;
48     L l1(create_linestring<P>());
49     ml1.push_back(l1);
50     ml1.push_back(l1);
51     return ml1;
52 }
53 
54 template <typename ML, typename L>
check_multi_linestring(ML & to_check,L l1)55 void check_multi_linestring(ML& to_check, L l1)
56 {
57     ML cur;
58     cur.push_back(l1);
59     cur.push_back(l1);
60 
61     std::ostringstream out1, out2;
62     out1 << bg::dsv(to_check);
63     out2 << bg::dsv(cur);
64     BOOST_CHECK_EQUAL(out1.str(), out2.str());
65 }
66 
67 template <typename P, typename L>
test_default_constructor()68 void test_default_constructor()
69 {
70     bg::model::multi_linestring<L> ml1(create_multi_linestring<P, L>());
71     check_multi_linestring(ml1, L(create_linestring<P>()));
72 }
73 
74 template <typename P, typename L>
test_copy_constructor()75 void test_copy_constructor()
76 {
77     bg::model::multi_linestring<L> ml1 = create_multi_linestring<P, L>();
78     check_multi_linestring(ml1, L(create_linestring<P>()));
79 }
80 
81 template <typename P, typename L>
test_copy_assignment()82 void test_copy_assignment()
83 {
84     bg::model::multi_linestring<L> ml1(create_multi_linestring<P, L>()), ml2;
85     ml2 = ml1;
86     check_multi_linestring(ml2, L(create_linestring<P>()));
87 }
88 
89 template <typename L>
test_concept()90 void test_concept()
91 {
92     typedef bg::model::multi_linestring<L> ML;
93 
94     BOOST_CONCEPT_ASSERT( (bg::concepts::ConstMultiLinestring<ML>) );
95     BOOST_CONCEPT_ASSERT( (bg::concepts::MultiLinestring<ML>) );
96 
97     typedef typename bg::coordinate_type<ML>::type T;
98     typedef typename bg::point_type<ML>::type PML;
99     boost::ignore_unused<T, PML>();
100 }
101 
102 template <typename P>
test_all()103 void test_all()
104 {
105     typedef bg::model::linestring<P> L;
106 
107     test_default_constructor<P, L>();
108     test_copy_constructor<P, L>();
109     test_copy_assignment<P, L>();
110     test_concept<L>();
111 }
112 
113 template <typename P>
test_custom_multi_linestring(bg::model::linestring<P> IL)114 void test_custom_multi_linestring(bg::model::linestring<P> IL)
115 {
116     typedef bg::model::linestring<P> L;
117 
118     std::initializer_list<L> LIL = {IL};
119     bg::model::multi_linestring<L> ml1(LIL);
120     std::ostringstream out;
121     out << bg::dsv(ml1);
122     BOOST_CHECK_EQUAL(out.str(), "(((1, 1), (2, 2), (3, 3), (0, 0), (0, 2), (0, 3)))");
123 }
124 
125 template <typename P>
test_custom()126 void test_custom()
127 {
128 #ifdef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
129     std::initializer_list<P> IL1 = {P(1, 1), P(2, 2), P(3, 3)};
130     std::initializer_list<P> IL2 = {P(0, 0), P(0, 2), P(0, 3)};
131     bg::model::linestring<P> l1;
132     bg::append(l1, IL1);
133     bg::append(l1, IL2);
134     test_custom_multi_linestring<P>(l1);
135 #endif//BOOST_NO_CXX11_HDR_INITIALIZER_LIST
136 }
137 
138 template <typename CS>
test_cs()139 void test_cs()
140 {
141     test_all<bg::model::point<int, 2, CS> >();
142     test_all<bg::model::point<float, 2, CS> >();
143     test_all<bg::model::point<double, 2, CS> >();
144 
145     test_custom<bg::model::point<double, 2, CS> >();
146 }
147 
148 
test_main(int,char * [])149 int test_main(int, char* [])
150 {
151     test_cs<bg::cs::cartesian>();
152     test_cs<bg::cs::spherical<bg::degree> >();
153     test_cs<bg::cs::spherical_equatorial<bg::degree> >();
154     test_cs<bg::cs::geographic<bg::degree> >();
155 
156     test_custom<bg::model::d2::point_xy<double> >();
157 
158     return 0;
159 }
160