/Src/Dependencies/Boost/libs/geometry/doc/src/examples/views/box_view.cpp

http://hadesmem.googlecode.com/ · C++ · 58 lines · 21 code · 16 blank · 21 comment · 2 complexity · 536b2c5fd070b95cbffe899b9392953b 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. //[box_view
  8. //` Shows usage of the Boost.Range compatible view on a box
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. int main()
  12. {
  13. typedef boost::geometry::model::box
  14. <
  15. boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
  16. > box_type;
  17. // Define the Boost.Range compatible type:
  18. typedef boost::geometry::box_view<box_type> box_view;
  19. box_type box;
  20. boost::geometry::assign_values(box, 0, 0, 4, 4);
  21. box_view view(box);
  22. // Iterating in clockwise direction over the points of this box
  23. for (boost::range_iterator<box_view const>::type it = boost::begin(view);
  24. it != boost::end(view); ++it)
  25. {
  26. std::cout << " " << boost::geometry::dsv(*it);
  27. }
  28. std::cout << std::endl;
  29. // Note that a box_view is tagged as a ring, so supports area etc.
  30. std::cout << "Area: " << boost::geometry::area(view) << std::endl;
  31. return 0;
  32. }
  33. //]
  34. //[box_view_output
  35. /*`
  36. Output:
  37. [pre
  38. (0, 0) (0, 4) (4, 4) (4, 0) (0, 0)
  39. Area: 16
  40. ]
  41. */
  42. //]