• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>reverse</title>
5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../index.html" title="Chapter 1. Geometry">
8<link rel="up" href="../algorithms.html" title="Algorithms">
9<link rel="prev" href="relation/relation_2.html" title="relation">
10<link rel="next" href="simplify.html" title="simplify">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="relation/relation_2.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../algorithms.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="simplify.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h4 class="title">
27<a name="geometry.reference.algorithms.reverse"></a><a class="link" href="reverse.html" title="reverse">reverse</a>
28</h4></div></div></div>
29<p>
30          <a class="indexterm" name="idm45635689483328"></a>
31Reverses the points within a geometry.
32        </p>
33<h6>
34<a name="geometry.reference.algorithms.reverse.h0"></a>
35          <span class="phrase"><a name="geometry.reference.algorithms.reverse.description"></a></span><a class="link" href="reverse.html#geometry.reference.algorithms.reverse.description">Description</a>
36        </h6>
37<p>
38          Generic function to reverse a geometry. It resembles the std::reverse functionality,
39          but it takes the geometry type into account. Only for a ring or for a linestring
40          it is the same as the std::reverse.
41        </p>
42<h6>
43<a name="geometry.reference.algorithms.reverse.h1"></a>
44          <span class="phrase"><a name="geometry.reference.algorithms.reverse.synopsis"></a></span><a class="link" href="reverse.html#geometry.reference.algorithms.reverse.synopsis">Synopsis</a>
45        </h6>
46<p>
47</p>
48<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Geometry</span><span class="special">&gt;</span>
49<span class="keyword">void</span> <span class="identifier">reverse</span><span class="special">(</span><span class="identifier">Geometry</span> <span class="special">&amp;</span> <span class="identifier">geometry</span><span class="special">)</span></pre>
50<p>
51        </p>
52<h6>
53<a name="geometry.reference.algorithms.reverse.h2"></a>
54          <span class="phrase"><a name="geometry.reference.algorithms.reverse.parameters"></a></span><a class="link" href="reverse.html#geometry.reference.algorithms.reverse.parameters">Parameters</a>
55        </h6>
56<div class="informaltable"><table class="table">
57<colgroup>
58<col>
59<col>
60<col>
61<col>
62</colgroup>
63<thead><tr>
64<th>
65                  <p>
66                    Type
67                  </p>
68                </th>
69<th>
70                  <p>
71                    Concept
72                  </p>
73                </th>
74<th>
75                  <p>
76                    Name
77                  </p>
78                </th>
79<th>
80                  <p>
81                    Description
82                  </p>
83                </th>
84</tr></thead>
85<tbody><tr>
86<td>
87                  <p>
88                    Geometry &amp;
89                  </p>
90                </td>
91<td>
92                  <p>
93                    Any type fulfilling a Geometry Concept
94                  </p>
95                </td>
96<td>
97                  <p>
98                    geometry
99                  </p>
100                </td>
101<td>
102                  <p>
103                    A model of the specified concept which will be reversed
104                  </p>
105                </td>
106</tr></tbody>
107</table></div>
108<h6>
109<a name="geometry.reference.algorithms.reverse.h3"></a>
110          <span class="phrase"><a name="geometry.reference.algorithms.reverse.header"></a></span><a class="link" href="reverse.html#geometry.reference.algorithms.reverse.header">Header</a>
111        </h6>
112<p>
113          Either
114        </p>
115<p>
116          <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
117        </p>
118<p>
119          Or
120        </p>
121<p>
122          <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">algorithms</span><span class="special">/</span><span class="identifier">reverse</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
123        </p>
124<h6>
125<a name="geometry.reference.algorithms.reverse.h4"></a>
126          <span class="phrase"><a name="geometry.reference.algorithms.reverse.conformance"></a></span><a class="link" href="reverse.html#geometry.reference.algorithms.reverse.conformance">Conformance</a>
127        </h6>
128<p>
129          The function reverse is not defined by OGC.
130        </p>
131<p>
132          The function reverse conforms to the std::reverse function of the C++ std-library.
133        </p>
134<h6>
135<a name="geometry.reference.algorithms.reverse.h5"></a>
136          <span class="phrase"><a name="geometry.reference.algorithms.reverse.behavior"></a></span><a class="link" href="reverse.html#geometry.reference.algorithms.reverse.behavior">Behavior</a>
137        </h6>
138<div class="informaltable"><table class="table">
139<colgroup>
140<col>
141<col>
142</colgroup>
143<thead><tr>
144<th>
145                  <p>
146                    Case
147                  </p>
148                </th>
149<th>
150                  <p>
151                    Behavior
152                  </p>
153                </th>
154</tr></thead>
155<tbody>
156<tr>
157<td>
158                  <p>
159                    Point
160                  </p>
161                </td>
162<td>
163                  <p>
164                    Nothing happens, geometry is unchanged
165                  </p>
166                </td>
167</tr>
168<tr>
169<td>
170                  <p>
171                    Segment
172                  </p>
173                </td>
174<td>
175                  <p>
176                    Not yet supported in this version
177                  </p>
178                </td>
179</tr>
180<tr>
181<td>
182                  <p>
183                    Box
184                  </p>
185                </td>
186<td>
187                  <p>
188                    Nothing happens, geometry is unchanged
189                  </p>
190                </td>
191</tr>
192<tr>
193<td>
194                  <p>
195                    Linestring
196                  </p>
197                </td>
198<td>
199                  <p>
200                    Reverses the Linestring
201                  </p>
202                </td>
203</tr>
204<tr>
205<td>
206                  <p>
207                    Ring
208                  </p>
209                </td>
210<td>
211                  <p>
212                    Reverses the Ring
213                  </p>
214                </td>
215</tr>
216<tr>
217<td>
218                  <p>
219                    Polygon
220                  </p>
221                </td>
222<td>
223                  <p>
224                    Reverses the exterior ring and all interior rings in the polygon
225                  </p>
226                </td>
227</tr>
228<tr>
229<td>
230                  <p>
231                    Multi Point
232                  </p>
233                </td>
234<td>
235                  <p>
236                    Nothing happens, geometry is unchanged
237                  </p>
238                </td>
239</tr>
240<tr>
241<td>
242                  <p>
243                    Multi Linestring
244                  </p>
245                </td>
246<td>
247                  <p>
248                    Reverses all contained linestrings individually
249                  </p>
250                </td>
251</tr>
252<tr>
253<td>
254                  <p>
255                    Multi Polygon
256                  </p>
257                </td>
258<td>
259                  <p>
260                    Reverses all contained polygons individually
261                  </p>
262                </td>
263</tr>
264</tbody>
265</table></div>
266<div class="note"><table border="0" summary="Note">
267<tr>
268<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
269<th align="left">Note</th>
270</tr>
271<tr><td align="left" valign="top"><p>
272            The reverse of a (multi)polygon or ring might make a valid geometry invalid
273            because the (counter)clockwise orientation reverses.
274          </p></td></tr>
275</table></div>
276<h6>
277<a name="geometry.reference.algorithms.reverse.h6"></a>
278          <span class="phrase"><a name="geometry.reference.algorithms.reverse.complexity"></a></span><a class="link" href="reverse.html#geometry.reference.algorithms.reverse.complexity">Complexity</a>
279        </h6>
280<p>
281          Linear
282        </p>
283<h6>
284<a name="geometry.reference.algorithms.reverse.h7"></a>
285          <span class="phrase"><a name="geometry.reference.algorithms.reverse.example"></a></span><a class="link" href="reverse.html#geometry.reference.algorithms.reverse.example">Example</a>
286        </h6>
287<p>
288          Shows how to reverse a ring or polygon
289        </p>
290<p>
291</p>
292<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
293
294<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
295<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">polygon</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
296<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">ring</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
297<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">adapted</span><span class="special">/</span><span class="identifier">boost_tuple</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
298
299<span class="identifier">BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS</span><span class="special">(</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">)</span>
300
301<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">assign</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
302
303<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
304<span class="special">{</span>
305    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">assign</span><span class="special">::</span><span class="identifier">tuple_list_of</span><span class="special">;</span>
306
307    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">point</span><span class="special">;</span>
308    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">polygon</span><span class="special">&lt;</span><span class="identifier">point</span><span class="special">&gt;</span> <span class="identifier">polygon</span><span class="special">;</span>
309    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">ring</span><span class="special">&lt;</span><span class="identifier">point</span><span class="special">&gt;</span> <span class="identifier">ring</span><span class="special">;</span>
310
311
312    <span class="identifier">polygon</span> <span class="identifier">poly</span><span class="special">;</span>
313    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">exterior_ring</span><span class="special">(</span><span class="identifier">poly</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">tuple_list_of</span><span class="special">(</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">)(</span><span class="number">0</span><span class="special">,</span> <span class="number">9</span><span class="special">)(</span><span class="number">10</span><span class="special">,</span> <span class="number">10</span><span class="special">)(</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">);</span>
314    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">interior_rings</span><span class="special">(</span><span class="identifier">poly</span><span class="special">).</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">tuple_list_of</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">)(</span><span class="number">4</span><span class="special">,</span> <span class="number">6</span><span class="special">)(</span><span class="number">2</span><span class="special">,</span> <span class="number">8</span><span class="special">)(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">));</span>
315
316    <span class="keyword">double</span> <span class="identifier">area_before</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">area</span><span class="special">(</span><span class="identifier">poly</span><span class="special">);</span>
317    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">reverse</span><span class="special">(</span><span class="identifier">poly</span><span class="special">);</span>
318    <span class="keyword">double</span> <span class="identifier">area_after</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">area</span><span class="special">(</span><span class="identifier">poly</span><span class="special">);</span>
319    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">dsv</span><span class="special">(</span><span class="identifier">poly</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
320    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">area_before</span> <span class="special">&lt;&lt;</span> <span class="string">" -&gt; "</span> <span class="special">&lt;&lt;</span> <span class="identifier">area_after</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
321
322    <span class="identifier">ring</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">tuple_list_of</span><span class="special">(</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">)(</span><span class="number">0</span><span class="special">,</span> <span class="number">9</span><span class="special">)(</span><span class="number">8</span><span class="special">,</span> <span class="number">8</span><span class="special">)(</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">);</span>
323
324    <span class="identifier">area_before</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">area</span><span class="special">(</span><span class="identifier">r</span><span class="special">);</span>
325    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">reverse</span><span class="special">(</span><span class="identifier">r</span><span class="special">);</span>
326    <span class="identifier">area_after</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">area</span><span class="special">(</span><span class="identifier">r</span><span class="special">);</span>
327    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">dsv</span><span class="special">(</span><span class="identifier">r</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
328    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">area_before</span> <span class="special">&lt;&lt;</span> <span class="string">" -&gt; "</span> <span class="special">&lt;&lt;</span> <span class="identifier">area_after</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
329
330    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
331<span class="special">}</span>
332</pre>
333<p>
334        </p>
335<p>
336          Output:
337        </p>
338<pre class="programlisting">(((0, 0), (10, 10), (0, 9), (0, 0)), ((1, 2), (2, 8), (4, 6), (1, 2)))
33938 -&gt; -38
340((0, 0), (8, 8), (0, 9), (0, 0))
34136 -&gt; -36
342</pre>
343</div>
344<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
345<td align="left"></td>
346<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
347      Wulkiewicz, Oracle and/or its affiliates<p>
348        Distributed under the Boost Software License, Version 1.0. (See accompanying
349        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
350      </p>
351</div></td>
352</tr></table>
353<hr>
354<div class="spirit-nav">
355<a accesskey="p" href="relation/relation_2.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../algorithms.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="simplify.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
356</div>
357</body>
358</html>
359