]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/geometries/boost_fusion.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / geometries / boost_fusion.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright Akira Takahashi 2011
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #include <geometry_test_common.hpp>
12
13 #include <boost/fusion/include/adapt_struct_named.hpp>
14
15 #include <boost/geometry/geometry.hpp>
16 #include <boost/geometry/geometries/adapted/boost_fusion.hpp>
17 #include <boost/geometry/geometries/adapted/c_array.hpp>
18 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
19 #include <iostream>
20
21 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
22 BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS(cs::cartesian)
23 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
24
25
26 struct for_fusion_2d
27 {
28 float x,y;
29 };
30 struct for_fusion_3d
31 {
32 double x,y,z;
33 };
34
35 BOOST_FUSION_ADAPT_STRUCT(for_fusion_2d, (float, x) (float, y))
36 BOOST_FUSION_ADAPT_STRUCT(for_fusion_3d, (double, x) (double, y) (double, z))
37
38
39 void test_2d()
40 {
41 bg::model::point<double, 2, bg::cs::cartesian> p1(1, 2);
42 double p2[2] = {3, 4};
43 boost::tuple<double, double> p3(5,6);
44
45 for_fusion_2d pf = {7, 8};
46
47 BOOST_CHECK_CLOSE(bg::distance(p1, pf), 8.4852813742385695, 0.01);
48 BOOST_CHECK_CLOSE(bg::distance(p2, pf), 5.6568542494923806, 0.01);
49 BOOST_CHECK_CLOSE(bg::distance(p3, pf), 2.82843, 0.01);
50 }
51
52 void test_3d()
53 {
54 bg::model::point<double, 3, bg::cs::cartesian> p1(1, 2, 3);
55 double p2[3] = {4, 5, 6};
56 boost::tuple<double, double, double> p3(7, 8, 9);
57
58 for_fusion_3d pf = {10, 11, 12};
59
60 BOOST_CHECK_CLOSE(bg::distance(p1, pf), 15.58845726811, 0.01);
61 BOOST_CHECK_CLOSE(bg::distance(p2, pf), 10.392304845413, 0.01);
62 BOOST_CHECK_CLOSE(bg::distance(p3, pf), 5.196152, 0.01);
63 }
64
65 int test_main(int, char* [])
66 {
67 test_2d();
68 test_3d();
69 return 0;
70 }
71