check_turn_less.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2015, 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_TEST_CHECK_TURN_LESS_HPP
  8. #define BOOST_GEOMETRY_TEST_CHECK_TURN_LESS_HPP
  9. #include <boost/range.hpp>
  10. #include "test_set_ops_linear_linear.hpp"
  11. // check less functor for turns
  12. template <typename Turns, typename Less>
  13. inline void verify_less_for_turns(Turns turns, Less const& less)
  14. {
  15. typedef typename boost::range_iterator<Turns const>::type iterator_type;
  16. if (boost::size(turns) < 2)
  17. {
  18. return;
  19. }
  20. iterator_type last = --boost::end(turns);
  21. for (iterator_type it1 = boost::begin(turns); it1 != last; ++it1)
  22. {
  23. iterator_type it2 = it1;
  24. ++it2;
  25. for (; it2 != boost::end(turns); ++it2)
  26. {
  27. if (less(*it1, *it2))
  28. {
  29. BOOST_CHECK(! less(*it2, *it1));
  30. }
  31. if (less(*it2, *it1))
  32. {
  33. BOOST_CHECK(! less(*it1, *it2));
  34. }
  35. }
  36. }
  37. }
  38. struct check_turn_less
  39. {
  40. template <bool EnableDegenerateTurns = true>
  41. struct assign_policy
  42. {
  43. static bool const include_no_turn = false;
  44. static bool const include_degenerate = EnableDegenerateTurns;
  45. static bool const include_opposite = false;
  46. template
  47. <
  48. typename Info,
  49. typename Point1,
  50. typename Point2,
  51. typename IntersectionInfo
  52. >
  53. static inline void apply(Info& , Point1 const& , Point2 const& ,
  54. IntersectionInfo const& )
  55. {
  56. }
  57. };
  58. template <typename Geometry1, typename Geometry2>
  59. static inline void apply(Geometry1 const& geometry1,
  60. Geometry2 const& geometry2)
  61. {
  62. typedef typename bg::strategy::intersection::services::default_strategy
  63. <
  64. typename bg::cs_tag<Geometry1>::type
  65. >::type strategy_type;
  66. typedef bg::detail::no_rescale_policy robust_policy_type;
  67. typedef bg::detail::relate::turns::get_turns
  68. <
  69. Geometry1,
  70. Geometry2,
  71. bg::detail::get_turns::get_turn_info_type
  72. <
  73. Geometry1, Geometry2, assign_policy<>
  74. >
  75. > get_turns_type;
  76. typedef typename get_turns_type::template turn_info_type
  77. <
  78. strategy_type, robust_policy_type
  79. >::type turn_info;
  80. typedef std::vector<turn_info> turns_container;
  81. turns_container turns;
  82. bg::detail::get_turns::no_interrupt_policy interrupt_policy;
  83. get_turns_type::apply(turns, geometry1, geometry2,
  84. interrupt_policy,
  85. strategy_type(), robust_policy_type());
  86. typedef bg::detail::turns::less_seg_fraction_other_op<> turn_less_type;
  87. verify_less_for_turns(turns, turn_less_type());
  88. }
  89. };
  90. #endif // BOOST_GEOMETRY_TEST_CHECK_TURN_LESS_HPP