turn_info.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP
  9. #include <array>
  10. #include <boost/geometry/core/coordinate_type.hpp>
  11. #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
  12. #include <boost/geometry/algorithms/detail/overlay/segment_identifier.hpp>
  13. #include <boost/geometry/algorithms/detail/overlay/overlay_type.hpp>
  14. #include <boost/geometry/policies/robustness/segment_ratio.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. #ifndef DOXYGEN_NO_DETAIL
  18. namespace detail { namespace overlay
  19. {
  20. enum method_type
  21. {
  22. method_none,
  23. method_disjoint,
  24. method_crosses,
  25. method_touch,
  26. method_touch_interior,
  27. method_collinear,
  28. method_equal,
  29. method_start,
  30. method_error
  31. };
  32. /*!
  33. \brief Turn operation: operation
  34. \details Information necessary for traversal phase (a phase
  35. of the overlay process). The information is gathered during the
  36. get_turns (segment intersection) phase.
  37. The class is to be included in the turn_info class, either direct
  38. or a derived or similar class with more (e.g. enrichment) information.
  39. */
  40. template <typename Point, typename SegmentRatio>
  41. struct turn_operation
  42. {
  43. typedef SegmentRatio segment_ratio_type;
  44. operation_type operation;
  45. segment_identifier seg_id;
  46. SegmentRatio fraction;
  47. typedef typename coordinate_type<Point>::type comparable_distance_type;
  48. comparable_distance_type remaining_distance;
  49. inline turn_operation()
  50. : operation(operation_none)
  51. , remaining_distance(0)
  52. {}
  53. };
  54. /*!
  55. \brief Turn information: intersection point, method, and turn information
  56. \details Information necessary for traversal phase (a phase
  57. of the overlay process). The information is gathered during the
  58. get_turns (segment intersection) phase.
  59. \tparam Point point type of intersection point
  60. \tparam Operation gives classes opportunity to add additional info
  61. \tparam Container gives classes opportunity to define how operations are stored
  62. */
  63. template
  64. <
  65. typename Point,
  66. typename SegmentRatio = geometry::segment_ratio<typename coordinate_type<Point>::type>,
  67. typename Operation = turn_operation<Point, SegmentRatio>,
  68. typename Container = std::array<Operation, 2>
  69. >
  70. struct turn_info
  71. {
  72. typedef Point point_type;
  73. typedef SegmentRatio segment_ratio_type;
  74. typedef Operation turn_operation_type;
  75. typedef Container container_type;
  76. Point point;
  77. method_type method;
  78. bool touch_only; // True in case of method touch(interior) and lines do not cross
  79. signed_size_type cluster_id; // For multiple turns on same location, > 0. Else -1. 0 is unused.
  80. bool discarded;
  81. bool has_colocated_both; // Colocated with a uu turn (for union) or ii (other)
  82. Container operations;
  83. inline turn_info()
  84. : method(method_none)
  85. , touch_only(false)
  86. , cluster_id(-1)
  87. , discarded(false)
  88. , has_colocated_both(false)
  89. {}
  90. inline bool both(operation_type type) const
  91. {
  92. return has12(type, type);
  93. }
  94. inline bool has(operation_type type) const
  95. {
  96. return this->operations[0].operation == type
  97. || this->operations[1].operation == type;
  98. }
  99. inline bool combination(operation_type type1, operation_type type2) const
  100. {
  101. return has12(type1, type2) || has12(type2, type1);
  102. }
  103. inline bool blocked() const
  104. {
  105. return both(operation_blocked);
  106. }
  107. inline bool opposite() const
  108. {
  109. return both(operation_opposite);
  110. }
  111. inline bool any_blocked() const
  112. {
  113. return has(operation_blocked);
  114. }
  115. inline bool is_clustered() const
  116. {
  117. return cluster_id > 0;
  118. }
  119. inline bool is_self() const
  120. {
  121. return operations[0].seg_id.source_index
  122. == operations[1].seg_id.source_index;
  123. }
  124. private :
  125. inline bool has12(operation_type type1, operation_type type2) const
  126. {
  127. return this->operations[0].operation == type1
  128. && this->operations[1].operation == type2
  129. ;
  130. }
  131. };
  132. }} // namespace detail::overlay
  133. #endif //DOXYGEN_NO_DETAIL
  134. }} // namespace boost::geometry
  135. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP