turn_info.hpp 4.4 KB

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