remove_duplicate_turns.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2022, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, 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_TURNS_REMOVE_DUPLICATE_TURNS_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_REMOVE_DUPLICATE_TURNS_HPP
  9. #include <algorithm>
  10. #include <boost/geometry/algorithms/detail/equals/point_point.hpp>
  11. namespace boost { namespace geometry
  12. {
  13. namespace detail { namespace turns
  14. {
  15. template <typename Turns, bool Enable>
  16. struct remove_duplicate_turns
  17. {
  18. template <typename Strategy>
  19. static inline void apply(Turns const&, Strategy const&) {}
  20. };
  21. template <typename Turns>
  22. struct remove_duplicate_turns<Turns, true>
  23. {
  24. template <typename Strategy>
  25. static inline void apply(Turns& turns, Strategy const& strategy)
  26. {
  27. turns.erase(
  28. std::unique(turns.begin(), turns.end(),
  29. [&](auto const& t1, auto const& t2)
  30. {
  31. return detail::equals::equals_point_point(t1.point, t2.point, strategy)
  32. && t1.operations[0].seg_id == t2.operations[0].seg_id
  33. && t1.operations[1].seg_id == t2.operations[1].seg_id;
  34. }),
  35. turns.end());
  36. }
  37. };
  38. }} // namespace detail::turns
  39. }} // namespect boost::geometry
  40. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_REMOVE_DUPLICATE_TURNS_HPP