intersection_policy.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 Segment1, typename Segment2, typename Ratio>
  54. static inline return_type segments_collinear(
  55. Segment1 const& segment1,
  56. Segment2 const& segment2,
  57. bool opposite,
  58. int pa1, int pa2, int pb1, int pb2,
  59. Ratio const& ra1, Ratio const& ra2,
  60. Ratio const& rb1, Ratio const& rb2)
  61. {
  62. return return_type
  63. (
  64. pts_policy::segments_collinear(segment1, segment2,
  65. opposite,
  66. pa1, pa2, pb1, pb2,
  67. ra1, ra2, rb1, rb2),
  68. dir_policy::segments_collinear(segment1, segment2,
  69. opposite,
  70. pa1, pa2, pb1, pb2,
  71. ra1, ra2, rb1, rb2)
  72. );
  73. }
  74. template <typename Segment>
  75. static inline return_type degenerate(Segment const& segment,
  76. bool a_degenerate)
  77. {
  78. return return_type
  79. (
  80. pts_policy::degenerate(segment, a_degenerate),
  81. dir_policy::degenerate(segment, a_degenerate)
  82. );
  83. }
  84. template <typename Segment, typename Ratio>
  85. static inline return_type one_degenerate(Segment const& segment,
  86. Ratio const& ratio,
  87. bool a_degenerate)
  88. {
  89. return return_type
  90. (
  91. pts_policy::one_degenerate(segment, ratio, a_degenerate),
  92. dir_policy::one_degenerate(segment, ratio, a_degenerate)
  93. );
  94. }
  95. static inline return_type disjoint()
  96. {
  97. return return_type
  98. (
  99. pts_policy::disjoint(),
  100. dir_policy::disjoint()
  101. );
  102. }
  103. static inline return_type error(std::string const& msg)
  104. {
  105. return return_type
  106. (
  107. pts_policy::error(msg),
  108. dir_policy::error(msg)
  109. );
  110. }
  111. };
  112. }} // namespace policies::relate
  113. }} // namespace boost::geometry
  114. #endif // BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_POLICY_HPP