• 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/ring.hpp>
20 #include <boost/geometry/geometries/concepts/ring_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::ring<P> create_ring()
36 {
37     bg::model::ring<P> r1;
38     P p1;
39     P p2;
40     P p3;
41     P p4;
42     bg::assign_values(p1, 2, 2);
43     bg::assign_values(p2, 2, 0);
44     bg::assign_values(p3, 0, 0);
45     bg::assign_values(p4, 0, 2);
46 
47     bg::append(r1, p1);
48     bg::append(r1, p2);
49     bg::append(r1, p3);
50     bg::append(r1, p4);
51     bg::append(r1, p1);
52     return r1;
53 }
54 
55 template <typename P, typename T>
check_point(P & to_check,T x,T y)56 void check_point(P& to_check, T x, T y)
57 {
58     BOOST_CHECK_EQUAL(bg::get<0>(to_check), x);
59     BOOST_CHECK_EQUAL(bg::get<1>(to_check), y);
60 }
61 
62 template <typename R, typename P>
check_ring(R & to_check,P p1,P p2,P p3,P p4)63 void check_ring(R& to_check, P p1, P p2, P p3, P p4)
64 {
65     check_point(to_check[0], bg::get<0>(p1), bg::get<1>(p1));
66     check_point(to_check[1], bg::get<0>(p2), bg::get<1>(p2));
67     check_point(to_check[2], bg::get<0>(p3), bg::get<1>(p3));
68     check_point(to_check[3], bg::get<0>(p4), bg::get<1>(p4));
69     check_point(to_check[4], bg::get<0>(p1), bg::get<1>(p1));
70 }
71 
72 template <typename P>
test_default_constructor()73 void test_default_constructor()
74 {
75     bg::model::ring<P> r1(create_ring<P>());
76     check_ring(r1, P(2, 2), P(2, 0), P(0, 0), P(0, 2));
77 }
78 
79 template <typename P>
test_copy_constructor()80 void test_copy_constructor()
81 {
82     bg::model::ring<P> r1 = create_ring<P>();
83     check_ring(r1, P(2, 2), P(2, 0), P(0, 0), P(0, 2));
84 }
85 
86 template <typename P>
test_copy_assignment()87 void test_copy_assignment()
88 {
89     bg::model::ring<P> r1(create_ring<P>()), r2;
90     r2 = r1;
91     check_ring(r2, P(2, 2), P(2, 0), P(0, 0), P(0, 2));
92 }
93 
94 template <typename P>
test_concept()95 void test_concept()
96 {
97     typedef bg::model::ring<P> R;
98 
99     BOOST_CONCEPT_ASSERT( (bg::concepts::ConstRing<R>) );
100     BOOST_CONCEPT_ASSERT( (bg::concepts::Ring<R>) );
101 
102     typedef typename bg::coordinate_type<R>::type T;
103     typedef typename bg::point_type<R>::type PR;
104     boost::ignore_unused<T, PR>();
105 }
106 
107 template <typename P>
test_all()108 void test_all()
109 {
110     test_default_constructor<P>();
111     test_copy_constructor<P>();
112     test_copy_assignment<P>();
113     test_concept<P>();
114 }
115 
116 template <typename P>
test_custom_ring(bg::model::ring<P> IL)117 void test_custom_ring(bg::model::ring<P> IL)
118 {
119     bg::model::ring<P> r1(IL);
120     std::ostringstream out;
121     out << bg::dsv(r1);
122     BOOST_CHECK_EQUAL(out.str(), "((3, 3), (3, 0), (0, 0), (0, 3), (3, 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> IL = {P(3, 3), P(3, 0), P(0, 0), P(0, 3), P(3, 3)};
130     test_custom_ring<P>(IL);
131 #endif//BOOST_NO_CXX11_HDR_INITIALIZER_LIST
132 }
133 
134 template <typename CS>
test_cs()135 void test_cs()
136 {
137     test_all<bg::model::point<int, 2, CS> >();
138     test_all<bg::model::point<float, 2, CS> >();
139     test_all<bg::model::point<double, 2, CS> >();
140 
141     test_custom<bg::model::point<double, 2, CS> >();
142 }
143 
144 
test_main(int,char * [])145 int test_main(int, char* [])
146 {
147     test_cs<bg::cs::cartesian>();
148     test_cs<bg::cs::spherical<bg::degree> >();
149     test_cs<bg::cs::spherical_equatorial<bg::degree> >();
150     test_cs<bg::cs::geographic<bg::degree> >();
151 
152     test_custom<bg::model::d2::point_xy<double> >();
153 
154     return 0;
155 }
156