segment_identifier.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. namespace boost { namespace geometry
  16. {
  17. // Internal struct to uniquely identify a segment
  18. // on a linestring,ring
  19. // or polygon (needs ring_index)
  20. // or multi-geometry (needs multi_index)
  21. struct segment_identifier
  22. {
  23. inline segment_identifier()
  24. : source_index(-1)
  25. , multi_index(-1)
  26. , ring_index(-1)
  27. , segment_index(-1)
  28. , piece_index(-1)
  29. {}
  30. inline segment_identifier(signed_size_type src,
  31. signed_size_type mul,
  32. signed_size_type rin,
  33. signed_size_type seg)
  34. : source_index(src)
  35. , multi_index(mul)
  36. , ring_index(rin)
  37. , segment_index(seg)
  38. , piece_index(-1)
  39. {}
  40. inline bool operator<(segment_identifier const& other) const
  41. {
  42. return source_index != other.source_index ? source_index < other.source_index
  43. : multi_index !=other.multi_index ? multi_index < other.multi_index
  44. : ring_index != other.ring_index ? ring_index < other.ring_index
  45. : piece_index != other.piece_index ? piece_index < other.piece_index
  46. : segment_index < other.segment_index
  47. ;
  48. }
  49. inline bool operator==(segment_identifier const& other) const
  50. {
  51. return source_index == other.source_index
  52. && segment_index == other.segment_index
  53. && ring_index == other.ring_index
  54. && piece_index == other.piece_index
  55. && multi_index == other.multi_index
  56. ;
  57. }
  58. #if defined(BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER)
  59. friend std::ostream& operator<<(std::ostream &os, segment_identifier const& seg_id)
  60. {
  61. os
  62. << "s:" << seg_id.source_index
  63. << ", v:" << seg_id.segment_index // v:vertex because s is used for source
  64. ;
  65. if (seg_id.ring_index >= 0) os << ", r:" << seg_id.ring_index;
  66. if (seg_id.multi_index >= 0) os << ", m:" << seg_id.multi_index;
  67. if (seg_id.piece_index >= 0) os << ", p:" << seg_id.piece_index;
  68. return os;
  69. }
  70. #endif
  71. signed_size_type source_index;
  72. signed_size_type multi_index;
  73. signed_size_type ring_index;
  74. signed_size_type segment_index;
  75. // For buffer - todo: move this to buffer-only
  76. signed_size_type piece_index;
  77. };
  78. }} // namespace boost::geometry
  79. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_IDENTIFIER_HPP