• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>perimeter</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="../perimeter.html" title="perimeter">
9<link rel="prev" href="../perimeter.html" title="perimeter">
10<link rel="next" href="perimeter_2_with_strategy.html" title="perimeter (with strategy)">
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="../perimeter.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../perimeter.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="perimeter_2_with_strategy.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h5 class="title">
27<a name="geometry.reference.algorithms.perimeter.perimeter_1"></a><a class="link" href="perimeter_1.html" title="perimeter">perimeter</a>
28</h5></div></div></div>
29<p>
30            <a class="indexterm" name="idm45635690432288"></a>
31Calculates the perimeter of a geometry.
32          </p>
33<h6>
34<a name="geometry.reference.algorithms.perimeter.perimeter_1.h0"></a>
35            <span class="phrase"><a name="geometry.reference.algorithms.perimeter.perimeter_1.description"></a></span><a class="link" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.description">Description</a>
36          </h6>
37<p>
38            The function perimeter returns the perimeter of a geometry, using the
39            default distance-calculation-strategy
40          </p>
41<h6>
42<a name="geometry.reference.algorithms.perimeter.perimeter_1.h1"></a>
43            <span class="phrase"><a name="geometry.reference.algorithms.perimeter.perimeter_1.synopsis"></a></span><a class="link" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.synopsis">Synopsis</a>
44          </h6>
45<p>
46</p>
47<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>
48<span class="identifier">default_length_result</span><span class="special">&lt;</span><span class="identifier">Geometry</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">perimeter</span><span class="special">(</span><span class="identifier">Geometry</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">geometry</span><span class="special">)</span></pre>
49<p>
50          </p>
51<h6>
52<a name="geometry.reference.algorithms.perimeter.perimeter_1.h2"></a>
53            <span class="phrase"><a name="geometry.reference.algorithms.perimeter.perimeter_1.parameters"></a></span><a class="link" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.parameters">Parameters</a>
54          </h6>
55<div class="informaltable"><table class="table">
56<colgroup>
57<col>
58<col>
59<col>
60<col>
61</colgroup>
62<thead><tr>
63<th>
64                    <p>
65                      Type
66                    </p>
67                  </th>
68<th>
69                    <p>
70                      Concept
71                    </p>
72                  </th>
73<th>
74                    <p>
75                      Name
76                    </p>
77                  </th>
78<th>
79                    <p>
80                      Description
81                    </p>
82                  </th>
83</tr></thead>
84<tbody><tr>
85<td>
86                    <p>
87                      Geometry const &amp;
88                    </p>
89                  </td>
90<td>
91                    <p>
92                      Any type fulfilling a Geometry Concept
93                    </p>
94                  </td>
95<td>
96                    <p>
97                      geometry
98                    </p>
99                  </td>
100<td>
101                    <p>
102                      A model of the specified concept
103                    </p>
104                  </td>
105</tr></tbody>
106</table></div>
107<h6>
108<a name="geometry.reference.algorithms.perimeter.perimeter_1.h3"></a>
109            <span class="phrase"><a name="geometry.reference.algorithms.perimeter.perimeter_1.returns"></a></span><a class="link" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.returns">Returns</a>
110          </h6>
111<p>
112            The calculated perimeter
113          </p>
114<h6>
115<a name="geometry.reference.algorithms.perimeter.perimeter_1.h4"></a>
116            <span class="phrase"><a name="geometry.reference.algorithms.perimeter.perimeter_1.header"></a></span><a class="link" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.header">Header</a>
117          </h6>
118<p>
119            Either
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">hpp</span><span class="special">&gt;</span></code>
123          </p>
124<p>
125            Or
126          </p>
127<p>
128            <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">perimeter</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
129          </p>
130<h6>
131<a name="geometry.reference.algorithms.perimeter.perimeter_1.h5"></a>
132            <span class="phrase"><a name="geometry.reference.algorithms.perimeter.perimeter_1.conformance"></a></span><a class="link" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.conformance">Conformance</a>
133          </h6>
134<p>
135            The function perimeter is not defined by OGC.
136          </p>
137<div class="note"><table border="0" summary="Note">
138<tr>
139<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td>
140<th align="left">Note</th>
141</tr>
142<tr><td align="left" valign="top"><p>
143              PostGIS contains an algorithm with the same name and the same functionality.
144              See the <a href="http://www.postgis.org/docs/ST_Perimeter.html" target="_top">PostGIS
145              documentation</a>.
146            </p></td></tr>
147</table></div>
148<h6>
149<a name="geometry.reference.algorithms.perimeter.perimeter_1.h6"></a>
150            <span class="phrase"><a name="geometry.reference.algorithms.perimeter.perimeter_1.behavior"></a></span><a class="link" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.behavior">Behavior</a>
151          </h6>
152<div class="informaltable"><table class="table">
153<colgroup>
154<col>
155<col>
156</colgroup>
157<thead><tr>
158<th>
159                    <p>
160                      Case
161                    </p>
162                  </th>
163<th>
164                    <p>
165                      Behavior
166                    </p>
167                  </th>
168</tr></thead>
169<tbody>
170<tr>
171<td>
172                    <p>
173                      pointlike (e.g. point)
174                    </p>
175                  </td>
176<td>
177                    <p>
178                      Returns zero
179                    </p>
180                  </td>
181</tr>
182<tr>
183<td>
184                    <p>
185                      linear (e.g. linestring)
186                    </p>
187                  </td>
188<td>
189                    <p>
190                      Returns zero
191                    </p>
192                  </td>
193</tr>
194<tr>
195<td>
196                    <p>
197                      areal (e.g. polygon)
198                    </p>
199                  </td>
200<td>
201                    <p>
202                      Returns the perimeter
203                    </p>
204                  </td>
205</tr>
206</tbody>
207</table></div>
208<h6>
209<a name="geometry.reference.algorithms.perimeter.perimeter_1.h7"></a>
210            <span class="phrase"><a name="geometry.reference.algorithms.perimeter.perimeter_1.complexity"></a></span><a class="link" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.complexity">Complexity</a>
211          </h6>
212<p>
213            Linear
214          </p>
215<h6>
216<a name="geometry.reference.algorithms.perimeter.perimeter_1.h8"></a>
217            <span class="phrase"><a name="geometry.reference.algorithms.perimeter.perimeter_1.example"></a></span><a class="link" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.example">Example</a>
218          </h6>
219<p>
220            Calculate the perimeter of a polygon
221          </p>
222<p>
223</p>
224<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
225
226<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>
227<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">point_xy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
228<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>
229
230<span class="keyword">namespace</span> <span class="identifier">bg</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">;</span> <a class="co" name="geometry.reference.algorithms.perimeter.perimeter_1.c0" href="perimeter_1.html#geometry.reference.algorithms.perimeter.perimeter_1.c1"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>
231
232<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
233<span class="special">{</span>
234    <span class="comment">// Calculate the perimeter of a cartesian polygon</span>
235    <span class="identifier">bg</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">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">d2</span><span class="special">::</span><span class="identifier">point_xy</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">poly</span><span class="special">;</span>
236    <span class="identifier">bg</span><span class="special">::</span><span class="identifier">read_wkt</span><span class="special">(</span><span class="string">"POLYGON((0 0,3 4,5 -5,-2 -4, 0 0))"</span><span class="special">,</span> <span class="identifier">poly</span><span class="special">);</span>
237    <span class="keyword">double</span> <span class="identifier">perimeter</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">perimeter</span><span class="special">(</span><span class="identifier">poly</span><span class="special">);</span>
238    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Perimeter: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">perimeter</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>
239
240    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
241<span class="special">}</span>
242</pre>
243<p>
244          </p>
245<div class="calloutlist"><table border="0" summary="Callout list"><tr>
246<td width="5%" valign="top" align="left"><p><a name="geometry.reference.algorithms.perimeter.perimeter_1.c1"></a><a href="#geometry.reference.algorithms.perimeter.perimeter_1.c0"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
247<td valign="top" align="left"><p>
248                Convenient namespace alias
249              </p></td>
250</tr></table></div>
251<p>
252            Output:
253          </p>
254<pre class="programlisting">Perimeter: 25.7627
255</pre>
256</div>
257<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
258<td align="left"></td>
259<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
260      Wulkiewicz, Oracle and/or its affiliates<p>
261        Distributed under the Boost Software License, Version 1.0. (See accompanying
262        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>)
263      </p>
264</div></td>
265</tr></table>
266<hr>
267<div class="spirit-nav">
268<a accesskey="p" href="../perimeter.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../perimeter.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="perimeter_2_with_strategy.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
269</div>
270</body>
271</html>
272