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

http://hadesmem.googlecode.com/ · C++ · 57 lines · 21 code · 16 blank · 20 comment · 2 complexity · 5edc405d53479c9e7c9b6be8508da6e6 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. //[segment_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::segment
  14. <
  15. boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
  16. > segment_type;
  17. typedef boost::geometry::segment_view<segment_type> segment_view;
  18. segment_type segment;
  19. boost::geometry::assign_values(segment, 0, 0, 1, 1);
  20. segment_view view(segment);
  21. // Iterating over the points of this segment
  22. for (boost::range_iterator<segment_view const>::type it = boost::begin(view);
  23. it != boost::end(view); ++it)
  24. {
  25. std::cout << " " << boost::geometry::dsv(*it);
  26. }
  27. std::cout << std::endl;
  28. // Note that a segment_view is tagged as a linestring, so supports length etc.
  29. std::cout << "Length: " << boost::geometry::length(view) << std::endl;
  30. return 0;
  31. }
  32. //]
  33. //[segment_view_output
  34. /*`
  35. Output:
  36. [pre
  37. (0, 0) (0, 4) (4, 4) (4, 0) (0, 0)
  38. Area: 16
  39. ]
  40. */
  41. //]