segment_view.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2010-2012 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. #include <algorithm>
  8. #include <iterator>
  9. #include <sstream>
  10. #include <string>
  11. #include <geometry_test_common.hpp>
  12. #include <boost/geometry/geometries/geometries.hpp>
  13. #include <boost/geometry/geometries/point_xy.hpp>
  14. #include <boost/geometry/views/segment_view.hpp>
  15. #include <boost/geometry/io/wkt/read.hpp>
  16. template <typename Segment>
  17. void test_geometry(std::string const& wkt, std::string const& expected)
  18. {
  19. Segment segment;
  20. bg::read_wkt(wkt, segment);
  21. typedef bg::segment_view<Segment> range_type;
  22. range_type range(segment);
  23. {
  24. std::ostringstream out;
  25. for (typename boost::range_iterator<range_type>::type it = boost::begin(range);
  26. it != boost::end(range); ++it)
  27. {
  28. out << " " << bg::get<0>(*it) << bg::get<1>(*it);
  29. }
  30. BOOST_CHECK_EQUAL(out.str(), expected);
  31. }
  32. {
  33. // Check forward/backward behaviour
  34. std::ostringstream out;
  35. typename boost::range_iterator<range_type>::type it = boost::begin(range);
  36. it++;
  37. it--;
  38. out << " " << bg::get<0>(*it) << bg::get<1>(*it);
  39. typename boost::range_iterator<range_type>::type it2 = boost::end(range);
  40. it2--;
  41. out << " " << bg::get<0>(*it2) << bg::get<1>(*it2);
  42. BOOST_CHECK_EQUAL(out.str(), expected);
  43. }
  44. {
  45. // Check random access behaviour
  46. int const n = boost::size(range);
  47. BOOST_CHECK_EQUAL(n, 2);
  48. }
  49. // Check Boost.Range concept
  50. BOOST_CONCEPT_ASSERT( (boost::RandomAccessRangeConcept<range_type>) );
  51. }
  52. template <typename P>
  53. void test_all()
  54. {
  55. test_geometry<bg::model::segment<P> >("linestring(1 1,2 2)", " 11 22");
  56. test_geometry<bg::model::segment<P> >("linestring(4 4,3 3)", " 44 33");
  57. }
  58. int test_main(int, char* [])
  59. {
  60. std::vector<int> a;
  61. a.push_back(1);
  62. boost::range_iterator<std::vector<int> const>::type it = a.end();
  63. --it;
  64. std::cout << *it << std::endl;
  65. test_all<bg::model::d2::point_xy<double> >();
  66. return 0;
  67. }