sweep.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
  3. // Copyright (c) 2015, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SWEEP_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SWEEP_HPP
  9. #include <boost/geometry/util/condition.hpp>
  10. #include <boost/core/ignore_unused.hpp>
  11. namespace boost { namespace geometry
  12. {
  13. #ifndef DOXYGEN_NO_DETAIL
  14. namespace detail { namespace sweep
  15. {
  16. struct no_interrupt_policy
  17. {
  18. static bool const enabled = false;
  19. template <typename Event>
  20. static inline bool apply(Event const&)
  21. {
  22. return false;
  23. }
  24. };
  25. }} // namespace detail::sweep
  26. #endif // DOXYGEN_NO_DETAIL
  27. template
  28. <
  29. typename Range,
  30. typename PriorityQueue,
  31. typename InitializationVisitor,
  32. typename EventVisitor,
  33. typename InterruptPolicy
  34. >
  35. inline void sweep(Range const& range, PriorityQueue& queue,
  36. InitializationVisitor& initialization_visitor,
  37. EventVisitor& event_visitor,
  38. InterruptPolicy const& interrupt_policy)
  39. {
  40. typedef typename PriorityQueue::value_type event_type;
  41. initialization_visitor.apply(range, queue, event_visitor);
  42. while (! queue.empty())
  43. {
  44. event_type event = queue.top();
  45. queue.pop();
  46. event_visitor.apply(event, queue);
  47. if (BOOST_GEOMETRY_CONDITION(interrupt_policy.enabled) && interrupt_policy.apply(event))
  48. {
  49. break;
  50. }
  51. }
  52. boost::ignore_unused(interrupt_policy);
  53. }
  54. template
  55. <
  56. typename Range,
  57. typename PriorityQueue,
  58. typename InitializationVisitor,
  59. typename EventVisitor
  60. >
  61. inline void sweep(Range const& range, PriorityQueue& queue,
  62. InitializationVisitor& initialization_visitor,
  63. EventVisitor& event_visitor)
  64. {
  65. sweep(range, queue, initialization_visitor, event_visitor,
  66. detail::sweep::no_interrupt_policy());
  67. }
  68. }} // namespace boost::geometry
  69. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SWEEP_HPP