/Src/Dependencies/Boost/libs/geometry/test/algorithms/overlay/select_rings.cpp

http://hadesmem.googlecode.com/ · C++ · 130 lines · 89 code · 32 blank · 9 comment · 3 complexity · 61e7965d20a0441cadd1a5d222bbf40f MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. //
  3. // Copyright (c) 2007-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. #include <geometry_test_common.hpp>
  8. #include <algorithms/test_overlay.hpp>
  9. #include <boost/range/algorithm/copy.hpp>
  10. #include <boost/geometry/geometry.hpp>
  11. #include <boost/geometry/algorithms/detail/overlay/select_rings.hpp>
  12. #include <boost/geometry/algorithms/detail/overlay/assign_parents.hpp>
  13. #include <boost/geometry/geometries/point_xy.hpp>
  14. #include <boost/geometry/geometries/polygon.hpp>
  15. #include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
  16. #include <boost/assign/list_of.hpp>
  17. #include <boost/foreach.hpp>
  18. #include <boost/tuple/tuple.hpp>
  19. template
  20. <
  21. typename Geometry1,
  22. typename Geometry2,
  23. bg::overlay_type OverlayType,
  24. typename RingIdVector,
  25. typename WithinVector
  26. >
  27. void test_geometry(std::string const& wkt1, std::string const& wkt2,
  28. RingIdVector const& expected_ids,
  29. WithinVector const& expected_withins)
  30. {
  31. typedef bg::detail::overlay::ring_properties<typename bg::point_type<Geometry1>::type> properties;
  32. Geometry1 geometry1;
  33. Geometry2 geometry2;
  34. bg::read_wkt(wkt1, geometry1);
  35. bg::read_wkt(wkt2, geometry2);
  36. typedef std::map<bg::ring_identifier, properties> map_type;
  37. map_type selected;
  38. std::map<bg::ring_identifier, int> empty;
  39. bg::detail::overlay::select_rings<OverlayType>(geometry1, geometry2, empty, selected);
  40. BOOST_CHECK_EQUAL(selected.size(), expected_ids.size());
  41. BOOST_CHECK_EQUAL(selected.size(), expected_withins.size());
  42. if (selected.size() <= expected_ids.size())
  43. {
  44. BOOST_AUTO(eit, expected_ids.begin());
  45. BOOST_AUTO(wit, expected_withins.begin());
  46. for(typename map_type::const_iterator it = selected.begin(); it != selected.end(); ++it, ++eit, ++wit)
  47. {
  48. bg::ring_identifier const ring_id = it->first;
  49. BOOST_CHECK_EQUAL(ring_id.source_index, eit->source_index);
  50. BOOST_CHECK_EQUAL(ring_id.multi_index, eit->multi_index);
  51. BOOST_CHECK_EQUAL(ring_id.ring_index, eit->ring_index);
  52. BOOST_CHECK_EQUAL(it->second.within_code, *wit);
  53. }
  54. }
  55. }
  56. template <typename P>
  57. void test_all()
  58. {
  59. // Point in correct clockwise ring -> should return true
  60. typedef bg::ring_identifier rid;
  61. test_geometry<bg::model::polygon<P>, bg::model::polygon<P>, bg::overlay_union>(
  62. winded[0], winded[1],
  63. boost::assign::list_of
  64. (rid(0,-1,-1))
  65. (rid(0,-1, 0))
  66. (rid(0,-1, 1))
  67. (rid(0,-1, 3))
  68. (rid(1,-1, 1))
  69. (rid(1,-1, 2)),
  70. boost::assign::list_of
  71. (-1)
  72. (-1)
  73. (-1)
  74. (-1)
  75. (-1)
  76. (-1)
  77. );
  78. //boost::assign::tuple_list_of(0,-1,-1,-1)(0,-1,0,-1)(0,-1,1,-1)(0,-1,3,-1)(1,-1,1,-1)(1,-1,2,-1));
  79. test_geometry<bg::model::polygon<P>, bg::model::polygon<P>, bg::overlay_intersection>(
  80. winded[0], winded[1],
  81. boost::assign::list_of
  82. (rid(0,-1, 2))
  83. (rid(1,-1,-1))
  84. (rid(1,-1, 0))
  85. (rid(1,-1, 3)),
  86. boost::assign::list_of
  87. (1)
  88. (1)
  89. (1)
  90. (1)
  91. );
  92. //boost::assign::tuple_list_of(0,-1,2,1)(1,-1,-1,1)(1,-1,0,1)(1,-1,3,1));
  93. }
  94. int test_main( int , char* [] )
  95. {
  96. test_all<bg::model::d2::point_xy<double> >();
  97. return 0;
  98. }