has_duplicates.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2019, 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_DETAIL_IS_VALID_HAS_DUPLICATES_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_DUPLICATES_HPP
  8. #include <boost/core/ignore_unused.hpp>
  9. #include <boost/range.hpp>
  10. #include <boost/geometry/core/closure.hpp>
  11. #include <boost/geometry/policies/compare.hpp>
  12. #include <boost/geometry/policies/is_valid/default_policy.hpp>
  13. #include <boost/geometry/views/closeable_view.hpp>
  14. #include <boost/geometry/algorithms/validity_failure_type.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. #ifndef DOXYGEN_NO_DETAIL
  18. namespace detail { namespace is_valid
  19. {
  20. template <typename Range, closure_selector Closure, typename CSTag>
  21. struct has_duplicates
  22. {
  23. template <typename VisitPolicy>
  24. static inline bool apply(Range const& range, VisitPolicy& visitor)
  25. {
  26. boost::ignore_unused(visitor);
  27. typedef typename closeable_view<Range const, Closure>::type view_type;
  28. typedef typename boost::range_const_iterator
  29. <
  30. view_type const
  31. >::type const_iterator;
  32. view_type view(range);
  33. if ( boost::size(view) < 2 )
  34. {
  35. return ! visitor.template apply<no_failure>();
  36. }
  37. geometry::equal_to
  38. <
  39. typename boost::range_value<Range>::type,
  40. -1,
  41. CSTag
  42. > equal;
  43. const_iterator it = boost::const_begin(view);
  44. const_iterator next = it;
  45. ++next;
  46. for (; next != boost::const_end(view); ++it, ++next)
  47. {
  48. if ( equal(*it, *next) )
  49. {
  50. return ! visitor.template apply<failure_duplicate_points>(*it);
  51. }
  52. }
  53. return ! visitor.template apply<no_failure>();
  54. }
  55. };
  56. }} // namespace detail::is_valid
  57. #endif // DOXYGEN_NO_DETAIL
  58. }} // namespace boost::geometry
  59. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_DUPLICATES_HPP