• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_IDENTIFIER_HPP
10 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_IDENTIFIER_HPP
11 
12 
13 #if defined(BOOST_GEOMETRY_DEBUG_OVERLAY)
14 #  define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
15 #endif
16 
17 #if defined(BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER)
18 #include <iostream>
19 #endif
20 
21 
22 #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
23 #include <boost/geometry/algorithms/detail/ring_identifier.hpp>
24 
25 
26 namespace boost { namespace geometry
27 {
28 
29 
30 
31 // Internal struct to uniquely identify a segment
32 // on a linestring,ring
33 // or polygon (needs ring_index)
34 // or multi-geometry (needs multi_index)
35 struct segment_identifier
36 {
segment_identifierboost::geometry::segment_identifier37     inline segment_identifier()
38         : source_index(-1)
39         , multi_index(-1)
40         , ring_index(-1)
41         , segment_index(-1)
42         , piece_index(-1)
43     {}
44 
segment_identifierboost::geometry::segment_identifier45     inline segment_identifier(signed_size_type src,
46                               signed_size_type mul,
47                               signed_size_type rin,
48                               signed_size_type seg)
49         : source_index(src)
50         , multi_index(mul)
51         , ring_index(rin)
52         , segment_index(seg)
53         , piece_index(-1)
54     {}
55 
operator <boost::geometry::segment_identifier56     inline bool operator<(segment_identifier const& other) const
57     {
58         return source_index != other.source_index ? source_index < other.source_index
59             : multi_index !=other.multi_index ? multi_index < other.multi_index
60             : ring_index != other.ring_index ? ring_index < other.ring_index
61             : piece_index != other.piece_index ? piece_index < other.piece_index
62             : segment_index < other.segment_index
63             ;
64     }
65 
operator ==boost::geometry::segment_identifier66     inline bool operator==(segment_identifier const& other) const
67     {
68         return source_index == other.source_index
69             && segment_index == other.segment_index
70             && ring_index == other.ring_index
71             && piece_index == other.piece_index
72             && multi_index == other.multi_index
73             ;
74     }
75 
76 #if defined(BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER)
operator <<(std::ostream & os,segment_identifier const & seg_id)77     friend std::ostream& operator<<(std::ostream &os, segment_identifier const& seg_id)
78     {
79         os
80             << "s:" << seg_id.source_index
81             << ", v:" << seg_id.segment_index // v:vertex because s is used for source
82             ;
83         if (seg_id.ring_index >= 0) os << ", r:" << seg_id.ring_index;
84         if (seg_id.multi_index >= 0) os << ", m:" << seg_id.multi_index;
85         if (seg_id.piece_index >= 0) os << ", p:" << seg_id.piece_index;
86         return os;
87     }
88 #endif
89 
90     signed_size_type source_index;
91     signed_size_type multi_index;
92     signed_size_type ring_index;
93     signed_size_type segment_index;
94 
95     // For buffer - todo: move this to buffer-only
96     signed_size_type piece_index;
97 };
98 
99 #ifndef DOXYGEN_NO_DETAIL
100 namespace detail { namespace overlay
101 {
102 
103 // Create a ring identifier from a segment identifier
ring_id_by_seg_id(segment_identifier const & seg_id)104 inline ring_identifier ring_id_by_seg_id(segment_identifier const& seg_id)
105 {
106     return ring_identifier(seg_id.source_index, seg_id.multi_index, seg_id.ring_index);
107 }
108 
109 }} // namespace detail::overlay
110 #endif // DOXYGEN_NO_DETAIL
111 
112 }} // namespace boost::geometry
113 
114 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_IDENTIFIER_HPP
115