]>
Commit | Line | Data |
---|---|---|
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) | |
2 | // QuickBook Example | |
3 | ||
4 | // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
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 | //[boost_fusion | |
11 | //` Shows how to combine Boost.Fusion with Boost.Geometry | |
12 | ||
13 | #include <iostream> | |
14 | ||
15 | #include <boost/fusion/include/adapt_struct_named.hpp> | |
16 | ||
17 | #include <boost/geometry.hpp> | |
18 | #include <boost/geometry/geometries/adapted/boost_fusion.hpp> | |
19 | ||
20 | ||
21 | struct sample_point | |
22 | { | |
23 | double x, y, z; | |
24 | }; | |
25 | ||
26 | BOOST_FUSION_ADAPT_STRUCT(sample_point, (double, x) (double, y) (double, z)) | |
27 | BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS(cs::cartesian) | |
28 | ||
29 | int main() | |
30 | { | |
31 | sample_point a, b, c; | |
32 | ||
33 | // Set coordinates the Boost.Geometry way (one of the ways) | |
34 | boost::geometry::assign_values(a, 3, 2, 1); | |
35 | ||
36 | // Set coordinates the Boost.Fusion way | |
37 | boost::fusion::at_c<0>(b) = 6; | |
38 | boost::fusion::at_c<1>(b) = 5; | |
39 | boost::fusion::at_c<2>(b) = 4; | |
40 | ||
41 | // Set coordinates the native way | |
42 | c.x = 9; | |
43 | c.y = 8; | |
44 | c.z = 7; | |
45 | ||
46 | std::cout << "Distance a-b: " << boost::geometry::distance(a, b) << std::endl; | |
47 | std::cout << "Distance a-c: " << boost::geometry::distance(a, c) << std::endl; | |
48 | ||
49 | return 0; | |
50 | } | |
51 | ||
52 | //] | |
53 | ||
54 | //[boost_fusion_output | |
55 | /*` | |
56 | Output: | |
57 | [pre | |
58 | Distance a-b: 5.19615 | |
59 | Distance a-c: 10.3923 | |
60 | ] | |
61 | */ | |
62 | //] |