segment_identifier.hpp 3.5 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. struct segment_identifier
  23. {
  24. inline segment_identifier()
  25. : source_index(-1)
  26. , multi_index(-1)
  27. , ring_index(-1)
  28. , segment_index(-1)
  29. , piece_index(-1)
  30. {}
  31. inline segment_identifier(signed_size_type src,
  32. signed_size_type mul,
  33. signed_size_type rin,
  34. signed_size_type seg)
  35. : source_index(src)
  36. , multi_index(mul)
  37. , ring_index(rin)
  38. , segment_index(seg)
  39. , piece_index(-1)
  40. {}
  41. inline bool operator<(segment_identifier const& other) const
  42. {
  43. return source_index != other.source_index ? source_index < other.source_index
  44. : multi_index !=other.multi_index ? multi_index < other.multi_index
  45. : ring_index != other.ring_index ? ring_index < other.ring_index
  46. : piece_index != other.piece_index ? piece_index < other.piece_index
  47. : segment_index < other.segment_index
  48. ;
  49. }
  50. inline bool operator==(segment_identifier const& other) const
  51. {
  52. return source_index == other.source_index
  53. && segment_index == other.segment_index
  54. && ring_index == other.ring_index
  55. && piece_index == other.piece_index
  56. && multi_index == other.multi_index
  57. ;
  58. }
  59. #if defined(BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER)
  60. friend std::ostream& operator<<(std::ostream &os, segment_identifier const& seg_id)
  61. {
  62. os
  63. << "s:" << seg_id.source_index
  64. << ", v:" << seg_id.segment_index // v:vertex because s is used for source
  65. ;
  66. if (seg_id.ring_index >= 0) os << ", r:" << seg_id.ring_index;
  67. if (seg_id.multi_index >= 0) os << ", m:" << seg_id.multi_index;
  68. if (seg_id.piece_index >= 0) os << ", p:" << seg_id.piece_index;
  69. return os;
  70. }
  71. #endif
  72. signed_size_type source_index;
  73. signed_size_type multi_index;
  74. signed_size_type ring_index;
  75. signed_size_type segment_index;
  76. // For buffer - todo: move this to buffer-only
  77. signed_size_type piece_index;
  78. };
  79. #ifndef DOXYGEN_NO_DETAIL
  80. namespace detail { namespace overlay
  81. {
  82. // Create a ring identifier from a segment identifier
  83. inline ring_identifier ring_id_by_seg_id(segment_identifier const& seg_id)
  84. {
  85. return ring_identifier(seg_id.source_index, seg_id.multi_index, seg_id.ring_index);
  86. }
  87. }} // namespace detail::overlay
  88. #endif // DOXYGEN_NO_DETAIL
  89. }} // namespace boost::geometry
  90. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_IDENTIFIER_HPP