]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/make.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / make.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7
8 // This file was modified by Oracle on 2020.
9 // Modifications copyright (c) 2020, Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18
19
20 #include <geometry_test_common.hpp>
21
22 #include <boost/geometry/algorithms/make.hpp>
23
24 #include <boost/geometry/io/wkt/write.hpp>
25
26 #include <boost/geometry/geometries/geometries.hpp>
27 #include <boost/geometry/geometries/adapted/c_array.hpp>
28 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
29 #include <test_common/test_point.hpp>
30
31 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
32 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
33
34
35 template <typename T, typename P>
36 void test_point_2d()
37 {
38 P p = bg::make<P>((T) 123, (T) 456);
39 BOOST_CHECK_CLOSE(bg::get<0>(p), 123.0, 1.0e-6);
40 BOOST_CHECK_CLOSE(bg::get<1>(p), 456.0, 1.0e-6);
41 }
42
43 template <typename T, typename P>
44 void test_point_3d()
45 {
46 P p = bg::make<P>((T) 123, (T) 456, (T) 789);
47 BOOST_CHECK_CLOSE( bg::get<0>(p), 123.0, 1.0e-6);
48 BOOST_CHECK_CLOSE( bg::get<1>(p), 456.0, 1.0e-6);
49 BOOST_CHECK_CLOSE( bg::get<2>(p), 789.0, 1.0e-6);
50 }
51
52 template <typename T, typename P>
53 void test_box_2d()
54 {
55 typedef bg::model::box<P> B;
56 B b = bg::make<B>((T) 123, (T) 456, (T) 789, (T) 1011);
57 BOOST_CHECK_CLOSE( (bg::get<bg::min_corner, 0>(b)), 123.0, 1.0e-6);
58 BOOST_CHECK_CLOSE( (bg::get<bg::min_corner, 1>(b)), 456.0, 1.0e-6);
59 BOOST_CHECK_CLOSE( (bg::get<bg::max_corner, 0>(b)), 789.0, 1.0e-6);
60 BOOST_CHECK_CLOSE( (bg::get<bg::max_corner, 1>(b)), 1011.0, 1.0e-6);
61
62 b = bg::make_inverse<B>();
63 }
64
65 template <typename T, typename P>
66 void test_linestring_2d()
67 {
68 typedef bg::model::linestring<P> L;
69
70 T coors[][2] = {{1,2}, {3,4}};
71
72 L line = bg::detail::make::make_points<L>(coors);
73
74 BOOST_CHECK_EQUAL(line.size(), 2u);
75 }
76
77 template <typename T, typename P>
78 void test_linestring_3d()
79 {
80 typedef bg::model::linestring<P> L;
81
82 T coors[][3] = {{1,2,3}, {4,5,6}};
83
84 L line = bg::detail::make::make_points<L>(coors);
85
86 BOOST_CHECK_EQUAL(line.size(), 2u);
87 //std::cout << dsv(line) << std::endl;
88
89 }
90
91 template <typename T, typename P>
92 void test_2d_t()
93 {
94 test_point_2d<T, P>();
95 test_box_2d<T, P>();
96 test_linestring_2d<T, P>();
97 }
98
99 template <typename P>
100 void test_2d()
101 {
102 test_2d_t<int, P>();
103 test_2d_t<float, P>();
104 test_2d_t<double, P>();
105 }
106
107 template <typename T, typename P>
108 void test_3d_t()
109 {
110 test_linestring_3d<T, P>();
111 // test_point_3d<T, test_point>();
112 }
113
114 template <typename P>
115 void test_3d()
116 {
117 test_3d_t<int, P>();
118 test_3d_t<float, P>();
119 test_3d_t<double, P>();
120 }
121
122 template <typename P>
123 void test_2d_constexpr()
124 {
125 constexpr P p = bg::make<P>(1, 2);
126 BOOST_CHECK_EQUAL((bg::get<0>(p)), 1);
127 BOOST_CHECK_EQUAL((bg::get<1>(p)), 2);
128 }
129
130 template <typename P>
131 void test_3d_constexpr()
132 {
133 constexpr P p = bg::make<P>(1, 2, 3);
134 BOOST_CHECK_EQUAL((bg::get<0>(p)), 1);
135 BOOST_CHECK_EQUAL((bg::get<1>(p)), 2);
136 BOOST_CHECK_EQUAL((bg::get<2>(p)), 3);
137 }
138
139 int test_main(int, char* [])
140 {
141 //test_2d<int[2]>();
142 //test_2d<float[2]>();
143 //test_2d<double[2]>();
144 test_2d<bg::model::point<int, 2, bg::cs::cartesian> >();
145 test_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
146 test_2d<bg::model::point<double, 2, bg::cs::cartesian> >();
147
148 test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();
149
150 test_2d_constexpr<bg::model::point<double, 2, bg::cs::cartesian> >();
151
152 test_3d_constexpr<bg::model::point<double, 3, bg::cs::cartesian> >();
153
154 return 0;
155 }