]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/algorithms/detail/overlay/check_enrich.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / overlay / check_enrich.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
3// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4
92f5a8d4
TL
5// This file was modified by Oracle on 2018.
6// Modifications copyright (c) 2018 Oracle and/or its affiliates.
7
8// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9
7c673cae
FG
10// Use, modification and distribution is subject to the Boost Software License,
11// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12// http://www.boost.org/LICENSE_1_0.txt)
13
14#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CHECK_ENRICH_HPP
15#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CHECK_ENRICH_HPP
16
92f5a8d4
TL
17#ifdef BOOST_GEOMETRY_DEBUG_ENRICH
18#include <iostream>
19#endif // BOOST_GEOMETRY_DEBUG_ENRICH
7c673cae
FG
20
21#include <cstddef>
92f5a8d4 22#include <vector>
7c673cae 23
92f5a8d4
TL
24#include <boost/range/begin.hpp>
25#include <boost/range/end.hpp>
26#include <boost/range/value_type.hpp>
7c673cae 27
92f5a8d4 28#include <boost/geometry/algorithms/detail/overlay/overlay_type.hpp>
7c673cae
FG
29
30
31namespace boost { namespace geometry
32{
33
34#ifndef DOXYGEN_NO_DETAIL
35namespace detail { namespace overlay
36{
37
38
39template<typename Turn>
40struct meta_turn
41{
42 int index;
43 Turn const* turn;
44 bool handled[2];
45
46 inline meta_turn(int i, Turn const& t)
47 : index(i), turn(&t)
48 {
49 handled[0] = false;
50 handled[1] = false;
51 }
52};
53
54
55template <typename MetaTurn>
92f5a8d4 56inline void display(MetaTurn const& meta_turn, const char* reason = "")
7c673cae
FG
57{
58#ifdef BOOST_GEOMETRY_DEBUG_ENRICH
59 std::cout << meta_turn.index
60 << "\tMethods: " << method_char(meta_turn.turn->method)
61 << " operations: " << operation_char(meta_turn.turn->operations[0].operation)
62 << operation_char(meta_turn.turn->operations[1].operation)
63 << " travels to " << meta_turn.turn->operations[0].enriched.travels_to_ip_index
64 << " and " << meta_turn.turn->operations[1].enriched.travels_to_ip_index
65 //<< " -> " << op_index
66 << " " << reason
67 << std::endl;
68#endif
69}
70
71
72template <typename MetaTurns, typename MetaTurn>
73inline void check_detailed(MetaTurns& meta_turns, MetaTurn const& meta_turn,
74 int op_index, int cycle, int start, operation_type for_operation,
75 bool& error)
76{
77 display(meta_turn);
78 int const ip_index = meta_turn.turn->operations[op_index].enriched.travels_to_ip_index;
79 if (ip_index >= 0)
80 {
81 bool found = false;
82
83 if (ip_index == start)
84 {
85 display(meta_turns[ip_index], " FINISH");
86 return;
87 }
88
89 // check on continuing, or on same-operation-on-same-geometry
90 if (! meta_turns[ip_index].handled[op_index]
91 && (meta_turns[ip_index].turn->operations[op_index].operation == operation_continue
92 || meta_turns[ip_index].turn->operations[op_index].operation == for_operation)
93 )
94 {
95 meta_turns[ip_index].handled[op_index] = true;
96 check_detailed(meta_turns, meta_turns[ip_index], op_index, cycle, start, for_operation, error);
97 found = true;
98 }
99 // check on other geometry
100 if (! found)
101 {
102 int const other_index = 1 - op_index;
103 if (! meta_turns[ip_index].handled[other_index]
104 && meta_turns[ip_index].turn->operations[other_index].operation == for_operation)
105 {
106 meta_turns[ip_index].handled[other_index] = true;
107 check_detailed(meta_turns, meta_turns[ip_index], other_index, cycle, start, for_operation, error);
108 found = true;
109 }
110 }
111
112 if (! found)
113 {
114 display(meta_turns[ip_index], " STOP");
115 error = true;
116#ifndef BOOST_GEOMETRY_DEBUG_ENRICH
117 //std::cout << " STOP";
118#endif
119 }
120 }
121}
122
123
124template <typename TurnPoints>
125inline bool check_graph(TurnPoints& turn_points, operation_type for_operation)
126{
127 typedef typename boost::range_value<TurnPoints>::type turn_point_type;
128
129 bool error = false;
130 int index = 0;
131
132 std::vector<meta_turn<turn_point_type> > meta_turns;
133 for (typename boost::range_iterator<TurnPoints const>::type
134 it = boost::begin(turn_points);
135 it != boost::end(turn_points);
136 ++it, ++index)
137 {
138 meta_turns.push_back(meta_turn<turn_point_type>(index, *it));
139 }
140
141 int cycle = 0;
142 for (typename boost::range_iterator<std::vector<meta_turn<turn_point_type> > > ::type
143 it = boost::begin(meta_turns);
144 it != boost::end(meta_turns);
145 ++it)
146 {
147 if (! (it->turn->blocked() || it->turn->discarded))
148 {
149 for (int i = 0 ; i < 2; i++)
150 {
151 if (! it->handled[i]
152 && it->turn->operations[i].operation == for_operation)
153 {
154#ifdef BOOST_GEOMETRY_DEBUG_ENRICH
155 std::cout << "CYCLE " << cycle << std::endl;
156#endif
157 it->handled[i] = true;
158 check_detailed(meta_turns, *it, i, cycle++, it->index, for_operation, error);
159#ifdef BOOST_GEOMETRY_DEBUG_ENRICH
160 std::cout <<" END CYCLE " << it->index << std::endl;
161#endif
162 }
163 }
164 }
165 }
166 return error;
167}
168
169
170
171}} // namespace detail::overlay
172#endif //DOXYGEN_NO_DETAIL
173
174
175
176}} // namespace boost::geometry
177
178
179#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CHECK_ENRICH_HPP