/Src/Dependencies/Boost/libs/geometry/doc/src/examples/algorithms/make_2d_point.cpp

http://hadesmem.googlecode.com/ · C++ · 63 lines · 28 code · 14 blank · 21 comment · 0 complexity · 1b08d02f71be7d6380dec71bb4c360f9 MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // QuickBook Example
  3. // Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
  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. //[make_2d_point
  8. //` Shows the usage of make as a generic constructor for different point types
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. #include <boost/geometry/geometries/point_xy.hpp>
  12. #include <boost/geometry/geometries/register/point.hpp>
  13. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  14. #include <boost/geometry/geometries/adapted/boost_polygon/point.hpp>
  15. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  16. struct mypoint { float _x, _y; };
  17. BOOST_GEOMETRY_REGISTER_POINT_2D(mypoint, float, cs::cartesian, _x, _y)
  18. template <typename Point>
  19. void construct_and_display()
  20. {
  21. using boost::geometry::make;
  22. using boost::geometry::get;
  23. Point p = make<Point>(1, 2);
  24. std::cout << "x=" << get<0>(p) << " y=" << get<1>(p)
  25. << " (" << typeid(Point).name() << ")"
  26. << std::endl;
  27. }
  28. int main()
  29. {
  30. construct_and_display<boost::geometry::model::d2::point_xy<double> >();
  31. construct_and_display<boost::geometry::model::d2::point_xy<int> >();
  32. construct_and_display<boost::tuple<double, double> >();
  33. construct_and_display<boost::polygon::point_data<int> >();
  34. construct_and_display<mypoint>();
  35. return 0;
  36. }
  37. //]
  38. //[make_2d_point_output
  39. /*`
  40. Output (compiled using gcc):
  41. [pre
  42. x=1 y=2 (N5boost8geometry5model2d28point_xyIdNS0_2cs9cartesianEEE)
  43. x=1 y=2 (N5boost8geometry5model2d28point_xyIiNS0_2cs9cartesianEEE)
  44. x=1 y=2 (N5boost6tuples5tupleIddNS0_9null_typeES2_S2_S2_S2_S2_S2_S2_EE)
  45. x=1 y=2 (N5boost7polygon10point_dataIiEE)
  46. x=1 y=2 (7mypoint)
  47. ]
  48. */
  49. //]