has_valid_self_turns.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. // 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_IS_VALID_HAS_VALID_SELF_TURNS_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_VALID_SELF_TURNS_HPP
  9. #include <vector>
  10. #include <boost/core/ignore_unused.hpp>
  11. #include <boost/range.hpp>
  12. #include <boost/geometry/algorithms/detail/is_valid/is_acceptable_turn.hpp>
  13. #include <boost/geometry/algorithms/detail/overlay/get_turn_info.hpp>
  14. #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
  15. #include <boost/geometry/algorithms/detail/overlay/self_turn_points.hpp>
  16. #include <boost/geometry/algorithms/validity_failure_type.hpp>
  17. #include <boost/geometry/core/assert.hpp>
  18. #include <boost/geometry/core/point_type.hpp>
  19. #include <boost/geometry/policies/predicate_based_interrupt_policy.hpp>
  20. #include <boost/geometry/policies/robustness/segment_ratio_type.hpp>
  21. #include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
  22. namespace boost { namespace geometry
  23. {
  24. #ifndef DOXYGEN_NO_DETAIL
  25. namespace detail { namespace is_valid
  26. {
  27. template
  28. <
  29. typename Geometry,
  30. typename CSTag
  31. >
  32. class has_valid_self_turns
  33. {
  34. private:
  35. typedef typename point_type<Geometry>::type point_type;
  36. typedef typename geometry::rescale_policy_type
  37. <
  38. point_type,
  39. CSTag
  40. >::type rescale_policy_type;
  41. typedef detail::overlay::get_turn_info
  42. <
  43. detail::overlay::assign_null_policy
  44. > turn_policy;
  45. public:
  46. typedef detail::overlay::turn_info
  47. <
  48. point_type,
  49. typename segment_ratio_type
  50. <
  51. point_type,
  52. rescale_policy_type
  53. >::type
  54. > turn_type;
  55. // returns true if all turns are valid
  56. template <typename Turns, typename VisitPolicy, typename Strategy>
  57. static inline bool apply(Geometry const& geometry,
  58. Turns& turns,
  59. VisitPolicy& visitor,
  60. Strategy const& strategy)
  61. {
  62. boost::ignore_unused(visitor);
  63. rescale_policy_type robust_policy
  64. = geometry::get_rescale_policy<rescale_policy_type>(geometry, strategy);
  65. detail::overlay::stateless_predicate_based_interrupt_policy
  66. <
  67. is_acceptable_turn<Geometry>
  68. > interrupt_policy;
  69. // Calculate self-turns, skipping adjacent segments
  70. detail::self_get_turn_points::self_turns<false, turn_policy>(geometry,
  71. strategy,
  72. robust_policy,
  73. turns,
  74. interrupt_policy,
  75. 0, true);
  76. if (interrupt_policy.has_intersections)
  77. {
  78. BOOST_GEOMETRY_ASSERT(! boost::empty(turns));
  79. return visitor.template apply<failure_self_intersections>(turns);
  80. }
  81. else
  82. {
  83. return visitor.template apply<no_failure>();
  84. }
  85. }
  86. // returns true if all turns are valid
  87. template <typename VisitPolicy, typename Strategy>
  88. static inline bool apply(Geometry const& geometry, VisitPolicy& visitor, Strategy const& strategy)
  89. {
  90. std::vector<turn_type> turns;
  91. return apply(geometry, turns, visitor, strategy);
  92. }
  93. };
  94. }} // namespace detail::is_valid
  95. #endif // DOXYGEN_NO_DETAIL
  96. }} // namespace boost::geometry
  97. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_VALID_SELF_TURNS_HPP