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/multi_point.hpp>
20 #include <boost/geometry/geometries/concepts/multi_point_concept.hpp>
21 #include <boost/geometry/geometries/adapted/c_array.hpp>
22 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
23 #include <boost/geometry/io/dsv/write.hpp>
24
25 #include <test_common/test_point.hpp>
26
27 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)28 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
29
30 #ifdef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
31 #include <initializer_list>
32 #endif//BOOST_NO_CXX11_HDR_INITIALIZER_LIST
33
34 template <typename P>
35 bg::model::multi_point<P> create_multi_point()
36 {
37 bg::model::multi_point<P> mp1;
38 P p1;
39 bg::assign_values(p1, 1, 2, 3);
40 bg::append(mp1, p1);
41 return mp1;
42 }
43
44 template <typename L, typename T>
check_multi_point(L & to_check,T x,T y,T z)45 void check_multi_point(L& to_check, T x, T y, T z)
46 {
47 BOOST_CHECK_EQUAL(bg::get<0>(to_check[0]), x);
48 BOOST_CHECK_EQUAL(bg::get<1>(to_check[0]), y);
49 BOOST_CHECK_EQUAL(bg::get<2>(to_check[0]), z);
50 }
51
52 template <typename P>
test_default_constructor()53 void test_default_constructor()
54 {
55 bg::model::multi_point<P> mp1(create_multi_point<P>());
56 check_multi_point(mp1, 1, 2, 3);
57 }
58
59 template <typename P>
test_copy_constructor()60 void test_copy_constructor()
61 {
62 bg::model::multi_point<P> mp1 = create_multi_point<P>();
63 check_multi_point(mp1, 1, 2, 3);
64 }
65
66 template <typename P>
test_copy_assignment()67 void test_copy_assignment()
68 {
69 bg::model::multi_point<P> mp1(create_multi_point<P>()), mp2;
70 mp2 = mp1;
71 check_multi_point(mp2, 1, 2, 3);
72 }
73
74 template <typename P>
test_concept()75 void test_concept()
76 {
77 typedef bg::model::multi_point<P> MP;
78
79 BOOST_CONCEPT_ASSERT( (bg::concepts::ConstMultiPoint<MP>) );
80 BOOST_CONCEPT_ASSERT( (bg::concepts::MultiPoint<MP>) );
81
82 typedef typename bg::coordinate_type<MP>::type T;
83 typedef typename bg::point_type<MP>::type MPP;
84 boost::ignore_unused<T, MPP>();
85 }
86
87 template <typename P>
test_all()88 void test_all()
89 {
90 test_default_constructor<P>();
91 test_copy_constructor<P>();
92 test_copy_assignment<P>();
93 test_concept<P>();
94 }
95
96 template <typename P>
test_custom_multi_point(std::initializer_list<P> IL)97 void test_custom_multi_point(std::initializer_list<P> IL)
98 {
99 bg::model::multi_point<P> mp1(IL);
100 std::ostringstream out;
101 out << bg::dsv(mp1);
102 BOOST_CHECK_EQUAL(out.str(), "((0, 0), (1, 2), (2, 0))");
103 }
104
105 template <typename P>
test_custom()106 void test_custom()
107 {
108 #ifdef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
109 std::initializer_list<P> IL = {P(0, 0), P(1, 2), P(2, 0)};
110 test_custom_multi_point<P>(IL);
111 #endif//BOOST_NO_CXX11_HDR_INITIALIZER_LIST
112 }
113
114 template <typename CS>
test_cs()115 void test_cs()
116 {
117 test_all<bg::model::point<int, 3, CS> >();
118 test_all<bg::model::point<float, 3, CS> >();
119 test_all<bg::model::point<double, 3, CS> >();
120
121 test_custom<bg::model::point<double, 2, CS> >();
122 }
123
124
test_main(int,char * [])125 int test_main(int, char* [])
126 {
127 test_cs<bg::cs::cartesian>();
128 test_cs<bg::cs::spherical<bg::degree> >();
129 test_cs<bg::cs::spherical_equatorial<bg::degree> >();
130 test_cs<bg::cs::geographic<bg::degree> >();
131
132 test_custom<bg::model::d2::point_xy<double> >();
133
134 return 0;
135 }
136