]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/test/geometries/multi_polygon.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / geometry / test / geometries / multi_polygon.cpp
CommitLineData
f67539c2
TL
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/polygon.hpp>
20#include <boost/geometry/geometries/multi_polygon.hpp>
21#include <boost/geometry/geometries/concepts/multi_polygon_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
28BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
29BOOST_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
35template <typename P>
36bg::model::polygon<P> create_polygon()
37{
38 bg::model::polygon<P> pl1;
39 P p1;
40 P p2;
41 P p3;
42 bg::assign_values(p1, 1, 2);
43 bg::assign_values(p2, 2, 0);
44 bg::assign_values(p3, 0, 0);
45
46 bg::append(pl1, p1);
47 bg::append(pl1, p2);
48 bg::append(pl1, p3);
49 bg::append(pl1, p1);
50 return pl1;
51}
52
53template <typename P, typename PL>
54bg::model::multi_polygon<PL> create_multi_polygon()
55{
56 bg::model::multi_polygon<PL> mpl1;
57 PL pl1(create_polygon<P>());
58 mpl1.push_back(pl1);
59 mpl1.push_back(pl1);
60 return mpl1;
61}
62
63template <typename MPL, typename PL>
64void check_multi_polygon(MPL& to_check, PL pl1)
65{
66 MPL cur;
67 cur.push_back(pl1);
68 cur.push_back(pl1);
69
70 std::ostringstream out1, out2;
71 out1 << bg::dsv(to_check);
72 out2 << bg::dsv(cur);
73 BOOST_CHECK_EQUAL(out1.str(), out2.str());
74}
75
76template <typename P, typename PL>
77void test_default_constructor()
78{
79 bg::model::multi_polygon<PL> mpl1(create_multi_polygon<P, PL>());
80 check_multi_polygon(mpl1, PL(create_polygon<P>()));
81}
82
83template <typename P, typename PL>
84void test_copy_constructor()
85{
86 bg::model::multi_polygon<PL> mpl1 = create_multi_polygon<P, PL>();
87 check_multi_polygon(mpl1, PL(create_polygon<P>()));
88}
89
90template <typename P, typename PL>
91void test_copy_assignment()
92{
93 bg::model::multi_polygon<PL> mpl1(create_multi_polygon<P, PL>()), mpl2;
94 mpl2 = mpl1;
95 check_multi_polygon(mpl2, PL(create_polygon<P>()));
96}
97
98template <typename PL>
99void test_concept()
100{
101 typedef bg::model::multi_polygon<PL> MPL;
102
103 BOOST_CONCEPT_ASSERT( (bg::concepts::ConstMultiPolygon<MPL>) );
104 BOOST_CONCEPT_ASSERT( (bg::concepts::MultiPolygon<MPL>) );
105
106 typedef typename bg::coordinate_type<MPL>::type T;
107 typedef typename bg::point_type<MPL>::type PMPL;
108 boost::ignore_unused<T, PMPL>();
109}
110
111template <typename P>
112void test_all()
113{
114 typedef bg::model::polygon<P> PL;
115
116 test_default_constructor<P, PL>();
117 test_copy_constructor<P, PL>();
118 test_copy_assignment<P, PL>();
119 test_concept<PL>();
120}
121
122template <typename P>
123void test_custom_multi_polygon(bg::model::polygon<P> IL)
124{
125 typedef bg::model::polygon<P> PL;
126
127 std::initializer_list<PL> PIL = {IL};
128 bg::model::multi_polygon<PL> mpl1(PIL);
129 std::ostringstream out;
130 out << bg::dsv(mpl1);
131 BOOST_CHECK_EQUAL(out.str(), "((((3, 3), (3, 0), (0, 0), (0, 3), (3, 3))))");
132}
133
134template <typename P>
135void test_custom()
136{
137#ifdef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
138 std::initializer_list<P> IL = {P(3, 3), P(3, 0), P(0, 0), P(0, 3), P(3, 3)};
139 bg::model::ring<P> r1(IL);
140 std::initializer_list<bg::model::ring<P> > RIL = {r1};
141 test_custom_multi_polygon<P>(RIL);
142#endif//BOOST_NO_CXX11_HDR_INITIALIZER_LIST
143}
144
145template <typename CS>
146void test_cs()
147{
148 test_all<bg::model::point<int, 2, CS> >();
149 test_all<bg::model::point<float, 2, CS> >();
150 test_all<bg::model::point<double, 2, CS> >();
151
152 test_custom<bg::model::point<double, 2, CS> >();
153}
154
155
156int test_main(int, char* [])
157{
158 test_cs<bg::cs::cartesian>();
159 test_cs<bg::cs::spherical<bg::degree> >();
160 test_cs<bg::cs::spherical_equatorial<bg::degree> >();
161 test_cs<bg::cs::geographic<bg::degree> >();
162
163 test_custom<bg::model::d2::point_xy<double> >();
164
165 return 0;
166}