1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2011-2012 Akira Takahashi
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 // Custom point / Boost.Fusion Example
11
12 #include <iostream>
13
14 #include <boost/fusion/include/adapt_struct_named.hpp>
15
16 #include <boost/geometry/algorithms/distance.hpp>
17
18 #include <boost/geometry/geometries/adapted/boost_fusion.hpp>
19
20 #include <boost/geometry/strategies/strategies.hpp>
21 #include <boost/geometry/io/dsv/write.hpp>
22
23 BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS(cs::cartesian);
24
25
26 // Sample point, having x/y
27 struct my_2d
28 {
29 float x,y;
30 };
31
32
33 BOOST_FUSION_ADAPT_STRUCT(my_2d,
34 (float, x)
35 (float, y))
36
37
main()38 int main()
39 {
40 my_2d p1 = {1, 5};
41 my_2d p2 = {3, 4};
42
43 std::cout << "Coordinate using direct access: "
44 << p1.x
45 << std::endl;
46 std::cout << "Coordinate using Boost.Fusion: "
47 << boost::fusion::at_c<0>(p1)
48 << std::endl;
49 std::cout << "Coordinate using Boost.Geometry: "
50 << boost::geometry::get<0>(p1)
51 << std::endl;
52
53 std::cout << "Two points are: "
54 << boost::geometry::dsv(p1) << " "
55 << boost::geometry::dsv(p2) << std::endl;
56
57 std::cout << "Distance: "
58 << boost::geometry::distance(p1, p2)
59 << std::endl;
60
61 return 0;
62 }
63