c09_custom_fusion_example.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2011-2012 Akira Takahashi
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // Custom point / Boost.Fusion Example
  9. #include <iostream>
  10. #include <boost/fusion/include/adapt_struct_named.hpp>
  11. #include <boost/geometry/algorithms/distance.hpp>
  12. #include <boost/geometry/geometries/adapted/boost_fusion.hpp>
  13. #include <boost/geometry/strategies/strategies.hpp>
  14. #include <boost/geometry/io/dsv/write.hpp>
  15. BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS(cs::cartesian);
  16. // Sample point, having x/y
  17. struct my_2d
  18. {
  19. float x,y;
  20. };
  21. BOOST_FUSION_ADAPT_STRUCT(my_2d,
  22. (float, x)
  23. (float, y))
  24. int main()
  25. {
  26. my_2d p1 = {1, 5};
  27. my_2d p2 = {3, 4};
  28. std::cout << "Coordinate using direct access: "
  29. << p1.x
  30. << std::endl;
  31. std::cout << "Coordinate using Boost.Fusion: "
  32. << boost::fusion::at_c<0>(p1)
  33. << std::endl;
  34. std::cout << "Coordinate using Boost.Geometry: "
  35. << boost::geometry::get<0>(p1)
  36. << std::endl;
  37. std::cout << "Two points are: "
  38. << boost::geometry::dsv(p1) << " "
  39. << boost::geometry::dsv(p2) << std::endl;
  40. std::cout << "Distance: "
  41. << boost::geometry::distance(p1, p2)
  42. << std::endl;
  43. return 0;
  44. }