]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/append.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / append.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
7
8 // This file was modified by Oracle on 2014, 2015.
9 // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates.
10
11 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
12
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15
16 // Use, modification and distribution is subject to the Boost Software License,
17 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
19
20 #include <deque>
21 #include <vector>
22
23 #include <boost/concept/requires.hpp>
24 #include <geometry_test_common.hpp>
25
26 #include <boost/geometry/core/access.hpp>
27 #include <boost/geometry/core/point_type.hpp>
28 #include <boost/geometry/core/tags.hpp>
29 #include <boost/geometry/algorithms/make.hpp>
30 #include <boost/geometry/algorithms/clear.hpp>
31 #include <boost/geometry/algorithms/append.hpp>
32 #include <boost/geometry/algorithms/num_points.hpp>
33 #include <boost/geometry/geometries/geometries.hpp>
34 #include <boost/geometry/geometries/concepts/check.hpp>
35 #include <boost/geometry/geometries/register/linestring.hpp>
36 #include <boost/variant/variant.hpp>
37
38 #include <test_common/test_point.hpp>
39 #include <test_geometries/wrapped_boost_array.hpp>
40
41
42 BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::vector)
43 BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::deque)
44
45
46 template <bool EnableAll>
47 struct do_checks
48 {
49 template <typename G>
50 static inline void apply(G const& geometry,
51 std::size_t size1,
52 std::size_t = 0,
53 std::size_t = 0)
54 {
55 BOOST_CHECK_EQUAL(bg::num_points(geometry), size1);
56 }
57 };
58
59
60 template<>
61 struct do_checks<true>
62 {
63 template <typename G>
64 static inline void apply(G const& geometry,
65 std::size_t size1,
66 std::size_t size2 = 0,
67 std::size_t size3 = 0)
68 {
69 do_checks<false>::apply(geometry, size1);
70 BOOST_CHECK_EQUAL(bg::num_points(geometry[0]), size2);
71 BOOST_CHECK_EQUAL(bg::num_points(geometry[1]), size3);
72 }
73 };
74
75
76
77 template <bool HasMultiIndex, bool IsVariant>
78 struct test_geometry
79 {
80 template <typename G>
81 static inline void apply(G& geometry, bool check)
82 {
83 typedef typename bg::point_type<G>::type P;
84 typedef do_checks<HasMultiIndex && !IsVariant> checks;
85
86 bg::append(geometry, bg::make_zero<P>(), -1, 0);
87 if (check)
88 {
89 checks::apply(geometry, 1u, 1u, 0u);
90 }
91
92 // Append a range
93 std::vector<P> v;
94 v.push_back(bg::make_zero<P>());
95 v.push_back(bg::make_zero<P>());
96 bg::append(geometry, v, -1, 1);
97
98 if (check)
99 {
100 checks::apply(geometry, 3u, 1u, 2u);
101 }
102
103 bg::clear(geometry);
104
105 if (check)
106 {
107 do_checks<false>::apply(geometry, 0u);
108 }
109 }
110 };
111
112
113
114 template <typename G>
115 void test_geometry_and_variant(bool check = true)
116 {
117 G geometry;
118 boost::variant<G> variant_geometry = G();
119 test_geometry<false, false>::apply(geometry, check);
120 test_geometry<false, true>::apply(variant_geometry, check);
121 }
122
123
124 template <typename MG>
125 void test_multigeometry_and_variant(bool check = true)
126 {
127 typedef typename boost::range_value<MG>::type G;
128
129 G geometry;
130 MG multigeometry;
131 bg::traits::push_back<MG>::apply(multigeometry, geometry);
132 bg::traits::push_back<MG>::apply(multigeometry, geometry);
133
134 boost::variant<MG> variant_multigeometry = multigeometry;
135 test_geometry<true, false>::apply(multigeometry, check);
136 test_geometry<true, true>::apply(variant_multigeometry, check);
137 }
138
139
140 template <typename P>
141 void test_all()
142 {
143 test_geometry_and_variant<P>(false);
144 test_geometry_and_variant<bg::model::box<P> >(false);
145 test_geometry_and_variant<bg::model::segment<P> >(false);
146 test_geometry_and_variant<bg::model::linestring<P> >();
147 test_geometry_and_variant<bg::model::ring<P> >();
148 test_geometry_and_variant<bg::model::polygon<P> >();
149 test_geometry_and_variant<bg::model::multi_point<P> >();
150 test_multigeometry_and_variant
151 <
152 bg::model::multi_linestring<bg::model::linestring<P> >
153 >();
154 test_multigeometry_and_variant
155 <
156 bg::model::multi_polygon<bg::model::polygon<P> >
157 >();
158
159 test_geometry_and_variant<std::vector<P> >();
160 test_geometry_and_variant<std::deque<P> >();
161 }
162
163 int test_main(int, char* [])
164 {
165 test_all<test::test_point>();
166 test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
167 test_all<bg::model::point<float, 2, bg::cs::cartesian> >();
168 test_all<bg::model::point<double, 2, bg::cs::cartesian> >();
169
170 return 0;
171 }