intersection_policy.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2020 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2020.
  4. // Modifications copyright (c) 2020 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_POLICY_HPP
  10. #define BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_POLICY_HPP
  11. #include <string>
  12. #include <tuple>
  13. #include <boost/geometry/policies/relate/direction.hpp>
  14. #include <boost/geometry/policies/relate/intersection_points.hpp>
  15. #include <boost/geometry/strategies/side_info.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. namespace policies { namespace relate
  19. {
  20. template <typename IntersectionPointsReturnType>
  21. struct segments_intersection_policy
  22. {
  23. private:
  24. typedef policies::relate::segments_intersection_points
  25. <
  26. IntersectionPointsReturnType
  27. > pts_policy;
  28. typedef policies::relate::segments_direction dir_policy;
  29. public:
  30. struct return_type
  31. {
  32. typedef typename pts_policy::return_type intersection_points_type;
  33. typedef typename dir_policy::return_type direction_type;
  34. return_type(intersection_points_type const& pts_result,
  35. direction_type const& dir_result)
  36. : intersection_points(pts_result)
  37. , direction(dir_result)
  38. {}
  39. intersection_points_type intersection_points;
  40. direction_type direction;
  41. };
  42. template <typename Segment1, typename Segment2, typename SegmentIntersectionInfo>
  43. static inline return_type segments_crosses(side_info const& sides,
  44. SegmentIntersectionInfo const& sinfo,
  45. Segment1 const& s1, Segment2 const& s2)
  46. {
  47. return return_type
  48. (
  49. pts_policy::segments_crosses(sides, sinfo, s1, s2),
  50. dir_policy::segments_crosses(sides, sinfo, s1, s2)
  51. );
  52. }
  53. template <typename SegmentIntersectionInfo, typename Point>
  54. static inline return_type
  55. segments_share_common_point(side_info const& sides,
  56. SegmentIntersectionInfo const& sinfo,
  57. Point const& p)
  58. {
  59. return return_type
  60. (
  61. pts_policy::segments_share_common_point(sides, sinfo, p),
  62. dir_policy::segments_share_common_point(sides, sinfo, p)
  63. );
  64. }
  65. template <typename Segment1, typename Segment2, typename Ratio>
  66. static inline return_type segments_collinear(
  67. Segment1 const& segment1,
  68. Segment2 const& segment2,
  69. bool opposite,
  70. int pa1, int pa2, int pb1, int pb2,
  71. Ratio const& ra1, Ratio const& ra2,
  72. Ratio const& rb1, Ratio const& rb2)
  73. {
  74. return return_type
  75. (
  76. pts_policy::segments_collinear(segment1, segment2,
  77. opposite,
  78. pa1, pa2, pb1, pb2,
  79. ra1, ra2, rb1, rb2),
  80. dir_policy::segments_collinear(segment1, segment2,
  81. opposite,
  82. pa1, pa2, pb1, pb2,
  83. ra1, ra2, rb1, rb2)
  84. );
  85. }
  86. template <typename Segment>
  87. static inline return_type degenerate(Segment const& segment,
  88. bool a_degenerate)
  89. {
  90. return return_type
  91. (
  92. pts_policy::degenerate(segment, a_degenerate),
  93. dir_policy::degenerate(segment, a_degenerate)
  94. );
  95. }
  96. template <typename Segment, typename Ratio>
  97. static inline return_type one_degenerate(Segment const& segment,
  98. Ratio const& ratio,
  99. bool a_degenerate)
  100. {
  101. return return_type
  102. (
  103. pts_policy::one_degenerate(segment, ratio, a_degenerate),
  104. dir_policy::one_degenerate(segment, ratio, a_degenerate)
  105. );
  106. }
  107. static inline return_type disjoint()
  108. {
  109. return return_type
  110. (
  111. pts_policy::disjoint(),
  112. dir_policy::disjoint()
  113. );
  114. }
  115. static inline return_type error(std::string const& msg)
  116. {
  117. return return_type
  118. (
  119. pts_policy::error(msg),
  120. dir_policy::error(msg)
  121. );
  122. }
  123. };
  124. }} // namespace policies::relate
  125. }} // namespace boost::geometry
  126. #endif // BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_POLICY_HPP