segment_identifier.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_SEGMENT_IDENTIFIER_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_IDENTIFIER_HPP
  8. #if defined(BOOST_GEOMETRY_DEBUG_OVERLAY)
  9. # define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
  10. #endif
  11. #if defined(BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER)
  12. #include <iostream>
  13. #endif
  14. #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
  15. #include <boost/geometry/algorithms/detail/ring_identifier.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. // Internal struct to uniquely identify a segment
  19. // on a linestring,ring
  20. // or polygon (needs ring_index)
  21. // or multi-geometry (needs multi_index)
  22. // It is always used for clockwise indication (even if the original is anticlockwise)
  23. struct segment_identifier
  24. {
  25. inline segment_identifier()
  26. : source_index(-1)
  27. , multi_index(-1)
  28. , ring_index(-1)
  29. , segment_index(-1)
  30. , piece_index(-1)
  31. {}
  32. inline segment_identifier(signed_size_type src,
  33. signed_size_type mul,
  34. signed_size_type rin,
  35. signed_size_type seg)
  36. : source_index(src)
  37. , multi_index(mul)
  38. , ring_index(rin)
  39. , segment_index(seg)
  40. , piece_index(-1)
  41. {}
  42. inline bool operator<(segment_identifier const& other) const
  43. {
  44. return source_index != other.source_index ? source_index < other.source_index
  45. : multi_index !=other.multi_index ? multi_index < other.multi_index
  46. : ring_index != other.ring_index ? ring_index < other.ring_index
  47. : piece_index != other.piece_index ? piece_index < other.piece_index
  48. : segment_index < other.segment_index
  49. ;
  50. }
  51. inline bool operator==(segment_identifier const& other) const
  52. {
  53. return source_index == other.source_index
  54. && segment_index == other.segment_index
  55. && ring_index == other.ring_index
  56. && piece_index == other.piece_index
  57. && multi_index == other.multi_index
  58. ;
  59. }
  60. #if defined(BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER)
  61. friend std::ostream& operator<<(std::ostream &os, segment_identifier const& seg_id)
  62. {
  63. os
  64. << "s:" << seg_id.source_index
  65. << ", v:" << seg_id.segment_index // v:vertex because s is used for source
  66. ;
  67. if (seg_id.ring_index >= 0) os << ", r:" << seg_id.ring_index;
  68. if (seg_id.multi_index >= 0) os << ", m:" << seg_id.multi_index;
  69. if (seg_id.piece_index >= 0) os << ", p:" << seg_id.piece_index;
  70. return os;
  71. }
  72. #endif
  73. signed_size_type source_index;
  74. signed_size_type multi_index;
  75. signed_size_type ring_index;
  76. signed_size_type segment_index;
  77. // For buffer - todo: move this to buffer-only
  78. signed_size_type piece_index;
  79. };
  80. #ifndef DOXYGEN_NO_DETAIL
  81. namespace detail { namespace overlay
  82. {
  83. // Create a ring identifier from a segment identifier
  84. inline ring_identifier ring_id_by_seg_id(segment_identifier const& seg_id)
  85. {
  86. return ring_identifier(seg_id.source_index, seg_id.multi_index, seg_id.ring_index);
  87. }
  88. }} // namespace detail::overlay
  89. #endif // DOXYGEN_NO_DETAIL
  90. }} // namespace boost::geometry
  91. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_IDENTIFIER_HPP