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

http://hadesmem.googlecode.com/ · C++ · 66 lines · 29 code · 15 blank · 22 comment · 0 complexity · 9e3d4f2e2fc0f5dc9ca7c0655f226a3f 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. //[assign
  8. //` Shows how to assign a geometry from another geometry
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. #include <boost/geometry/geometries/box.hpp>
  12. #include <boost/geometry/geometries/point_xy.hpp>
  13. #include <boost/geometry/geometries/polygon.hpp>
  14. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  15. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  16. int main()
  17. {
  18. typedef boost::geometry::model::d2::point_xy<double> point;
  19. typedef boost::geometry::model::box<point> box;
  20. typedef boost::geometry::model::polygon<point> polygon;
  21. point p1;
  22. box b;
  23. boost::geometry::assign_values(p1, 1, 1);
  24. boost::geometry::assign_values(b, 1, 1, 2, 2);
  25. // Assign a box to a polygon (target = source)
  26. polygon p;
  27. boost::geometry::assign(p, b);
  28. // Assign a point to another point type (conversion of point-type)
  29. boost::tuple<double, double> p2;
  30. boost::geometry::assign(p2, p1);
  31. using boost::geometry::dsv;
  32. std::cout
  33. << "box: " << dsv(b) << std::endl
  34. << "polygon: " << dsv(p) << std::endl
  35. << "point: " << dsv(p1) << std::endl
  36. << "point tuples: " << dsv(p2) << std::endl
  37. ;
  38. return 0;
  39. }
  40. //]
  41. //[assign_output
  42. /*`
  43. Output:
  44. [pre
  45. box: ((1, 1), (2, 2))
  46. polygon: (((1, 1), (1, 2), (2, 2), (2, 1), (1, 1)))
  47. point: (1, 1)
  48. point tuples: (1, 1)
  49. ]
  50. */
  51. //]