check_enrich.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2018.
  4. // Modifications copyright (c) 2018 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CHECK_ENRICH_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CHECK_ENRICH_HPP
  11. #ifdef BOOST_GEOMETRY_DEBUG_ENRICH
  12. #include <iostream>
  13. #endif // BOOST_GEOMETRY_DEBUG_ENRICH
  14. #include <cstddef>
  15. #include <vector>
  16. #include <boost/range/begin.hpp>
  17. #include <boost/range/end.hpp>
  18. #include <boost/range/value_type.hpp>
  19. #include <boost/geometry/algorithms/detail/overlay/overlay_type.hpp>
  20. #include <boost/geometry/algorithms/detail/ring_identifier.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. #ifndef DOXYGEN_NO_DETAIL
  24. namespace detail { namespace overlay
  25. {
  26. template<typename Turn>
  27. struct meta_turn
  28. {
  29. int index;
  30. Turn const* turn;
  31. bool handled[2];
  32. inline meta_turn(int i, Turn const& t)
  33. : index(i), turn(&t)
  34. {
  35. handled[0] = false;
  36. handled[1] = false;
  37. }
  38. };
  39. template <typename MetaTurn>
  40. inline void display(MetaTurn const& meta_turn, const char* reason = "")
  41. {
  42. #ifdef BOOST_GEOMETRY_DEBUG_ENRICH
  43. std::cout << meta_turn.index
  44. << "\tMethods: " << method_char(meta_turn.turn->method)
  45. << " operations: " << operation_char(meta_turn.turn->operations[0].operation)
  46. << operation_char(meta_turn.turn->operations[1].operation)
  47. << " travels to " << meta_turn.turn->operations[0].enriched.travels_to_ip_index
  48. << " and " << meta_turn.turn->operations[1].enriched.travels_to_ip_index
  49. //<< " -> " << op_index
  50. << " " << reason
  51. << std::endl;
  52. #endif
  53. }
  54. template <typename MetaTurns, typename MetaTurn>
  55. inline void check_detailed(MetaTurns& meta_turns, MetaTurn const& meta_turn,
  56. int op_index, int cycle, int start, operation_type for_operation,
  57. bool& error)
  58. {
  59. display(meta_turn);
  60. int const ip_index = meta_turn.turn->operations[op_index].enriched.travels_to_ip_index;
  61. if (ip_index >= 0)
  62. {
  63. bool found = false;
  64. if (ip_index == start)
  65. {
  66. display(meta_turns[ip_index], " FINISH");
  67. return;
  68. }
  69. // check on continuing, or on same-operation-on-same-geometry
  70. if (! meta_turns[ip_index].handled[op_index]
  71. && (meta_turns[ip_index].turn->operations[op_index].operation == operation_continue
  72. || meta_turns[ip_index].turn->operations[op_index].operation == for_operation)
  73. )
  74. {
  75. meta_turns[ip_index].handled[op_index] = true;
  76. check_detailed(meta_turns, meta_turns[ip_index], op_index, cycle, start, for_operation, error);
  77. found = true;
  78. }
  79. // check on other geometry
  80. if (! found)
  81. {
  82. int const other_index = 1 - op_index;
  83. if (! meta_turns[ip_index].handled[other_index]
  84. && meta_turns[ip_index].turn->operations[other_index].operation == for_operation)
  85. {
  86. meta_turns[ip_index].handled[other_index] = true;
  87. check_detailed(meta_turns, meta_turns[ip_index], other_index, cycle, start, for_operation, error);
  88. found = true;
  89. }
  90. }
  91. if (! found)
  92. {
  93. display(meta_turns[ip_index], " STOP");
  94. error = true;
  95. #ifndef BOOST_GEOMETRY_DEBUG_ENRICH
  96. //std::cout << " STOP";
  97. #endif
  98. }
  99. }
  100. }
  101. template <typename TurnPoints>
  102. inline bool check_graph(TurnPoints& turn_points, operation_type for_operation)
  103. {
  104. typedef typename boost::range_value<TurnPoints>::type turn_point_type;
  105. bool error = false;
  106. int index = 0;
  107. std::vector<meta_turn<turn_point_type> > meta_turns;
  108. for (typename boost::range_iterator<TurnPoints const>::type
  109. it = boost::begin(turn_points);
  110. it != boost::end(turn_points);
  111. ++it, ++index)
  112. {
  113. meta_turns.push_back(meta_turn<turn_point_type>(index, *it));
  114. }
  115. int cycle = 0;
  116. for (typename boost::range_iterator<std::vector<meta_turn<turn_point_type> > > ::type
  117. it = boost::begin(meta_turns);
  118. it != boost::end(meta_turns);
  119. ++it)
  120. {
  121. if (! (it->turn->blocked() || it->turn->discarded))
  122. {
  123. for (int i = 0 ; i < 2; i++)
  124. {
  125. if (! it->handled[i]
  126. && it->turn->operations[i].operation == for_operation)
  127. {
  128. #ifdef BOOST_GEOMETRY_DEBUG_ENRICH
  129. std::cout << "CYCLE " << cycle << std::endl;
  130. #endif
  131. it->handled[i] = true;
  132. check_detailed(meta_turns, *it, i, cycle++, it->index, for_operation, error);
  133. #ifdef BOOST_GEOMETRY_DEBUG_ENRICH
  134. std::cout <<" END CYCLE " << it->index << std::endl;
  135. #endif
  136. }
  137. }
  138. }
  139. }
  140. return error;
  141. }
  142. }} // namespace detail::overlay
  143. #endif //DOXYGEN_NO_DETAIL
  144. }} // namespace boost::geometry
  145. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CHECK_ENRICH_HPP