]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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> | |
f67539c2 | 23 | #include <boost/geometry/algorithms/detail/ring_identifier.hpp> |
7c673cae FG |
24 | |
25 | ||
26 | namespace boost { namespace geometry | |
27 | { | |
28 | ||
29 | ||
7c673cae FG |
30 | // Internal struct to uniquely identify a segment |
31 | // on a linestring,ring | |
32 | // or polygon (needs ring_index) | |
33 | // or multi-geometry (needs multi_index) | |
1e59de90 | 34 | // It is always used for clockwise indication (even if the original is anticlockwise) |
7c673cae FG |
35 | struct segment_identifier |
36 | { | |
37 | 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 | ||
45 | 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 | ||
56 | 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 | |
b32b8144 | 61 | : piece_index != other.piece_index ? piece_index < other.piece_index |
7c673cae FG |
62 | : segment_index < other.segment_index |
63 | ; | |
64 | } | |
65 | ||
66 | 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 | |
b32b8144 | 71 | && piece_index == other.piece_index |
7c673cae FG |
72 | && multi_index == other.multi_index |
73 | ; | |
74 | } | |
75 | ||
76 | #if defined(BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER) | |
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; | |
b32b8144 | 85 | if (seg_id.piece_index >= 0) os << ", p:" << seg_id.piece_index; |
7c673cae FG |
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 | ||
f67539c2 TL |
99 | #ifndef DOXYGEN_NO_DETAIL |
100 | namespace detail { namespace overlay | |
101 | { | |
102 | ||
103 | // Create a ring identifier from a segment identifier | |
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 | } | |
7c673cae | 108 | |
f67539c2 TL |
109 | }} // namespace detail::overlay |
110 | #endif // DOXYGEN_NO_DETAIL | |
7c673cae FG |
111 | |
112 | }} // namespace boost::geometry | |
113 | ||
114 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_IDENTIFIER_HPP |