filter_continue_turns.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014, Oracle and/or its affiliates.
  3. // Licensed under the Boost Software License version 1.0.
  4. // http://www.boost.org/users/license.html
  5. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  6. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_FILTER_CONTINUE_TURNS_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_FILTER_CONTINUE_TURNS_HPP
  8. #include <algorithm>
  9. #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
  10. namespace boost { namespace geometry
  11. {
  12. namespace detail { namespace turns
  13. {
  14. template <typename Turns, bool Enable>
  15. struct filter_continue_turns
  16. {
  17. static inline void apply(Turns&) {}
  18. };
  19. template <typename Turns>
  20. class filter_continue_turns<Turns, true>
  21. {
  22. private:
  23. class IsContinueTurn
  24. {
  25. private:
  26. template <typename Operation>
  27. inline bool is_continue_or_opposite(Operation const& operation) const
  28. {
  29. return operation == detail::overlay::operation_continue
  30. || operation == detail::overlay::operation_opposite;
  31. }
  32. public:
  33. template <typename Turn>
  34. bool operator()(Turn const& turn) const
  35. {
  36. if ( turn.method != detail::overlay::method_collinear
  37. && turn.method != detail::overlay::method_equal )
  38. {
  39. return false;
  40. }
  41. return is_continue_or_opposite(turn.operations[0].operation)
  42. && is_continue_or_opposite(turn.operations[1].operation);
  43. }
  44. };
  45. public:
  46. static inline void apply(Turns& turns)
  47. {
  48. turns.erase( std::remove_if(turns.begin(), turns.end(),
  49. IsContinueTurn()),
  50. turns.end()
  51. );
  52. }
  53. };
  54. }} // namespace detail::turns
  55. }} // namespect boost::geometry
  56. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_FILTER_CONTINUE_TURNS_HPP