select_rings.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. //
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. //
  5. // This file was modified by Oracle on 2017.
  6. // Modifications copyright (c) 2017 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. //
  9. // Use, modification and distribution is subject to the Boost Software License,
  10. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. #include <geometry_test_common.hpp>
  13. #include <boost/foreach.hpp>
  14. #include <boost/range/algorithm/copy.hpp>
  15. #include <boost/tuple/tuple.hpp>
  16. #include <boost/typeof/typeof.hpp>
  17. #include <algorithms/test_overlay.hpp>
  18. #include <boost/geometry/geometry.hpp>
  19. #include <boost/geometry/algorithms/detail/overlay/select_rings.hpp>
  20. #include <boost/geometry/algorithms/detail/overlay/assign_parents.hpp>
  21. #include <boost/geometry/geometries/point_xy.hpp>
  22. #include <boost/geometry/geometries/polygon.hpp>
  23. #include <boost/geometry/io/wkt/read.hpp>
  24. #include <boost/assign/list_of.hpp>
  25. template
  26. <
  27. typename Geometry1,
  28. typename Geometry2,
  29. bg::overlay_type OverlayType,
  30. typename RingIdVector
  31. >
  32. void test_geometry(std::string const& wkt1, std::string const& wkt2,
  33. RingIdVector const& expected_ids)
  34. {
  35. typedef bg::detail::overlay::ring_properties
  36. <
  37. typename bg::point_type<Geometry1>::type,
  38. double
  39. > properties;
  40. Geometry1 geometry1;
  41. Geometry2 geometry2;
  42. bg::read_wkt(wkt1, geometry1);
  43. bg::read_wkt(wkt2, geometry2);
  44. typedef std::map<bg::ring_identifier, properties> map_type;
  45. map_type selected;
  46. std::map<bg::ring_identifier, bg::detail::overlay::ring_turn_info> empty;
  47. typedef typename bg::strategy::intersection::services::default_strategy
  48. <
  49. typename bg::cs_tag<Geometry1>::type
  50. >::type strategy_type;
  51. bg::detail::overlay::select_rings<OverlayType>(geometry1, geometry2, empty, selected, strategy_type());
  52. BOOST_CHECK_EQUAL(selected.size(), expected_ids.size());
  53. if (selected.size() <= expected_ids.size())
  54. {
  55. BOOST_AUTO(eit, expected_ids.begin());
  56. for(typename map_type::const_iterator it = selected.begin(); it != selected.end(); ++it, ++eit)
  57. {
  58. bg::ring_identifier const ring_id = it->first;
  59. BOOST_CHECK_EQUAL(ring_id.source_index, eit->source_index);
  60. BOOST_CHECK_EQUAL(ring_id.multi_index, eit->multi_index);
  61. BOOST_CHECK_EQUAL(ring_id.ring_index, eit->ring_index);
  62. }
  63. }
  64. }
  65. template <typename P>
  66. void test_all()
  67. {
  68. // Point in correct clockwise ring -> should return true
  69. typedef bg::ring_identifier rid;
  70. test_geometry<bg::model::polygon<P>, bg::model::polygon<P>, bg::overlay_union>(
  71. winded[0], winded[1],
  72. boost::assign::list_of
  73. (rid(0,-1,-1))
  74. (rid(0,-1, 0))
  75. (rid(0,-1, 1))
  76. (rid(0,-1, 3))
  77. (rid(1,-1, 1))
  78. (rid(1,-1, 2)));
  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. }
  87. int test_main( int , char* [] )
  88. {
  89. test_all<bg::model::d2::point_xy<double> >();
  90. return 0;
  91. }