predicate_based_interrupt_policy.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_ALGORITHMS_POLICIES_PREDICATE_BASED_INTERRUPT_POLICY_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_POLICIES_PREDICATE_BASED_INTERRUPT_POLICY_HPP
  8. #include <boost/range.hpp>
  9. #include <boost/geometry/algorithms/detail/check_iterator_range.hpp>
  10. namespace boost { namespace geometry
  11. {
  12. #ifndef DOXYGEN_NO_DETAIL
  13. namespace detail { namespace overlay
  14. {
  15. template
  16. <
  17. typename IsAcceptableTurnPredicate,
  18. bool AllowEmptyTurnRange = true // by default, allow an empty turn range
  19. >
  20. struct stateless_predicate_based_interrupt_policy
  21. {
  22. static bool const enabled = true;
  23. bool has_intersections; // set to true if there is at least one
  24. // unacceptable turn
  25. inline stateless_predicate_based_interrupt_policy()
  26. : has_intersections(false)
  27. {}
  28. template <typename Range>
  29. inline bool apply(Range const& range)
  30. {
  31. // if there is at least one unacceptable turn in the range, return false
  32. has_intersections = !detail::check_iterator_range
  33. <
  34. IsAcceptableTurnPredicate,
  35. AllowEmptyTurnRange
  36. >::apply(boost::begin(range), boost::end(range));
  37. return has_intersections;
  38. }
  39. };
  40. template
  41. <
  42. typename IsAcceptableTurnPredicate,
  43. bool AllowEmptyTurnRange = true // by default, allow an empty turn range
  44. >
  45. struct predicate_based_interrupt_policy
  46. {
  47. static bool const enabled = true;
  48. bool has_intersections; // set to true if there is at least one
  49. // unacceptable turn
  50. IsAcceptableTurnPredicate const& m_predicate;
  51. inline
  52. predicate_based_interrupt_policy(IsAcceptableTurnPredicate const& predicate)
  53. : has_intersections(false)
  54. , m_predicate(predicate)
  55. {}
  56. template <typename Range>
  57. inline bool apply(Range const& range)
  58. {
  59. // if there is at least one unacceptable turn in the range, return false
  60. has_intersections = !detail::check_iterator_range
  61. <
  62. IsAcceptableTurnPredicate,
  63. AllowEmptyTurnRange
  64. >::apply(boost::begin(range), boost::end(range), m_predicate);
  65. return has_intersections;
  66. }
  67. };
  68. }} // namespace detail::overlay
  69. #endif // DOXYGEN_NO_DETAIL
  70. }} // namespace boost::geometry
  71. #endif // BOOST_GEOMETRY_ALGORITHMS_POLICIES_PREDICATE_BASED_INTERRUPT_POLICY_HPP