remove_duplicate_turns.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_REMOVE_DUPLICATE_TURNS_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_REMOVE_DUPLICATE_TURNS_HPP
  8. #include <algorithm>
  9. #include <boost/geometry/algorithms/equals.hpp>
  10. namespace boost { namespace geometry
  11. {
  12. namespace detail { namespace turns
  13. {
  14. template <typename Turns, bool Enable>
  15. struct remove_duplicate_turns
  16. {
  17. static inline void apply(Turns&) {}
  18. };
  19. template <typename Turns>
  20. class remove_duplicate_turns<Turns, true>
  21. {
  22. private:
  23. struct TurnEqualsTo
  24. {
  25. template <typename Turn>
  26. bool operator()(Turn const& t1, Turn const& t2) const
  27. {
  28. return geometry::equals(t1.point, t2.point)
  29. && t1.operations[0].seg_id == t2.operations[0].seg_id
  30. && t1.operations[1].seg_id == t2.operations[1].seg_id;
  31. }
  32. };
  33. public:
  34. static inline void apply(Turns& turns)
  35. {
  36. turns.erase( std::unique(turns.begin(), turns.end(),
  37. TurnEqualsTo()),
  38. turns.end()
  39. );
  40. }
  41. };
  42. }} // namespace detail::turns
  43. }} // namespect boost::geometry
  44. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_REMOVE_DUPLICATE_TURNS_HPP