boost_fusion.cpp 1.9 KB

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