/Src/Dependencies/Boost/libs/geometry/test/geometries/boost_range.cpp

http://hadesmem.googlecode.com/ · C++ · 116 lines · 80 code · 27 blank · 9 comment · 2 complexity · dd1b0d92c6bd1b9426c6e0b22a0cd2e7 MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2010 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 <geometry_test_common.hpp>
  8. #include <boost/geometry/geometry.hpp>
  9. #include <boost/geometry/geometries/geometries.hpp>
  10. #include <boost/geometry/geometries/point_xy.hpp>
  11. #include <boost/geometry/geometries/adapted/boost_range/adjacent_filtered.hpp>
  12. #include <boost/geometry/geometries/adapted/boost_range/filtered.hpp>
  13. #include <boost/geometry/geometries/adapted/boost_range/reversed.hpp>
  14. #include <boost/geometry/geometries/adapted/boost_range/strided.hpp>
  15. #include <boost/geometry/geometries/adapted/boost_range/sliced.hpp>
  16. #include <boost/geometry/geometries/adapted/boost_range/uniqued.hpp>
  17. #include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
  18. #include <sstream>
  19. struct not_two
  20. {
  21. template <typename P>
  22. bool operator()(P const& p) const
  23. {
  24. return boost::geometry::get<0>(p) != 2.0;
  25. }
  26. };
  27. struct sum_not_five
  28. {
  29. template <typename P>
  30. bool operator()(P const& p1, P const& p2) const
  31. {
  32. return boost::geometry::get<0>(p1) + boost::geometry::get<0>(p2) != 5.0;
  33. }
  34. };
  35. template <typename P>
  36. void test_range_adaptor()
  37. {
  38. bg::model::linestring<P> ls;
  39. bg::read_wkt("LINESTRING(1 1,2 2,3 3,4 4)", ls);
  40. {
  41. std::ostringstream out;
  42. out << bg::wkt(ls);
  43. BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)");
  44. }
  45. {
  46. std::ostringstream out;
  47. out << bg::wkt(ls | boost::adaptors::reversed);
  48. BOOST_CHECK_EQUAL(out.str(), "LINESTRING(4 4,3 3,2 2,1 1)");
  49. }
  50. {
  51. std::ostringstream out;
  52. out << bg::wkt(ls | boost::adaptors::strided(2));
  53. BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3)");
  54. }
  55. {
  56. std::ostringstream out;
  57. out << bg::wkt(ls | boost::adaptors::sliced(1,3));
  58. BOOST_CHECK_EQUAL(out.str(), "LINESTRING(2 2,3 3)");
  59. }
  60. {
  61. std::ostringstream out;
  62. out << bg::wkt(ls | boost::adaptors::filtered(not_two()));
  63. BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)");
  64. }
  65. {
  66. std::ostringstream out;
  67. out << bg::wkt(ls | boost::adaptors::adjacent_filtered(sum_not_five()));
  68. BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)");
  69. }
  70. {
  71. bg::model::linestring<P> ls2;
  72. bg::read_wkt("LINESTRING(1 1,1 1,2 2,3 3,3 3,4 4)", ls2);
  73. std::ostringstream out;
  74. // uniqued needs == operator, equals
  75. //out << bg::wkt(ls | boost::adaptors::uniqued);
  76. //BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)");
  77. }
  78. }
  79. template <typename P>
  80. void test_all()
  81. {
  82. test_range_adaptor<P>();
  83. }
  84. int test_main(int, char* [])
  85. {
  86. test_all<bg::model::d2::point_xy<double> >();
  87. test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
  88. return 0;
  89. }