]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/make.cpp
add subtree-ish sources for 12.0.3
[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 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15
16 #include <geometry_test_common.hpp>
17
18 #include <boost/geometry/algorithms/make.hpp>
19
20 #include <boost/geometry/io/wkt/write.hpp>
21
22 #include <boost/geometry/geometries/geometries.hpp>
23 #include <boost/geometry/geometries/adapted/c_array.hpp>
24 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
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
31 template <typename T, typename P>
32 void test_point_2d()
33 {
34 P p = bg::make<P>((T) 123, (T) 456);
35 BOOST_CHECK_CLOSE(bg::get<0>(p), 123.0, 1.0e-6);
36 BOOST_CHECK_CLOSE(bg::get<1>(p), 456.0, 1.0e-6);
37 }
38
39 template <typename T, typename P>
40 void test_point_3d()
41 {
42 P p = bg::make<P>((T) 123, (T) 456, (T) 789);
43 BOOST_CHECK_CLOSE( bg::get<0>(p), 123.0, 1.0e-6);
44 BOOST_CHECK_CLOSE( bg::get<1>(p), 456.0, 1.0e-6);
45 BOOST_CHECK_CLOSE( bg::get<2>(p), 789.0, 1.0e-6);
46 }
47
48 template <typename T, typename P>
49 void test_box_2d()
50 {
51 typedef bg::model::box<P> B;
52 B b = bg::make<B>((T) 123, (T) 456, (T) 789, (T) 1011);
53 BOOST_CHECK_CLOSE( (bg::get<bg::min_corner, 0>(b)), 123.0, 1.0e-6);
54 BOOST_CHECK_CLOSE( (bg::get<bg::min_corner, 1>(b)), 456.0, 1.0e-6);
55 BOOST_CHECK_CLOSE( (bg::get<bg::max_corner, 0>(b)), 789.0, 1.0e-6);
56 BOOST_CHECK_CLOSE( (bg::get<bg::max_corner, 1>(b)), 1011.0, 1.0e-6);
57
58 b = bg::make_inverse<B>();
59 }
60
61 template <typename T, typename P>
62 void test_linestring_2d()
63 {
64 typedef bg::model::linestring<P> L;
65
66 T coors[][2] = {{1,2}, {3,4}};
67
68 L line = bg::detail::make::make_points<L>(coors);
69
70 BOOST_CHECK_EQUAL(line.size(), 2u);
71 }
72
73 template <typename T, typename P>
74 void test_linestring_3d()
75 {
76 typedef bg::model::linestring<P> L;
77
78 T coors[][3] = {{1,2,3}, {4,5,6}};
79
80 L line = bg::detail::make::make_points<L>(coors);
81
82 BOOST_CHECK_EQUAL(line.size(), 2u);
83 //std::cout << dsv(line) << std::endl;
84
85 }
86
87 template <typename T, typename P>
88 void test_2d_t()
89 {
90 test_point_2d<T, P>();
91 test_box_2d<T, P>();
92 test_linestring_2d<T, P>();
93 }
94
95 template <typename P>
96 void test_2d()
97 {
98 test_2d_t<int, P>();
99 test_2d_t<float, P>();
100 test_2d_t<double, P>();
101 }
102
103 template <typename T, typename P>
104 void test_3d_t()
105 {
106 test_linestring_3d<T, P>();
107 // test_point_3d<T, test_point>();
108 }
109
110 template <typename P>
111 void test_3d()
112 {
113 test_3d_t<int, P>();
114 test_3d_t<float, P>();
115 test_3d_t<double, P>();
116 }
117
118 int test_main(int, char* [])
119 {
120 //test_2d<int[2]>();
121 //test_2d<float[2]>();
122 //test_2d<double[2]>();
123 test_2d<bg::model::point<int, 2, bg::cs::cartesian> >();
124 test_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
125 test_2d<bg::model::point<double, 2, bg::cs::cartesian> >();
126
127
128 test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();
129
130 #if defined(HAVE_TTMATH)
131 test_2d<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
132 test_3d<bg::model::point<ttmath_big, 3, bg::cs::cartesian> >();
133 #endif
134
135
136 return 0;
137 }