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