• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>num_segments</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="num_points.html" title="num_points">
10<link rel="next" href="overlaps.html" title="overlaps">
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="num_points.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="overlaps.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.num_segments"></a><a class="link" href="num_segments.html" title="num_segments">num_segments</a>
28</h4></div></div></div>
29<p>
30          <a class="indexterm" name="idm45635691383872"></a>
31Calculates the number of segments of a geometry.
32        </p>
33<h6>
34<a name="geometry.reference.algorithms.num_segments.h0"></a>
35          <span class="phrase"><a name="geometry.reference.algorithms.num_segments.description"></a></span><a class="link" href="num_segments.html#geometry.reference.algorithms.num_segments.description">Description</a>
36        </h6>
37<p>
38          The free function num_segments calculates the number of segments of a geometry.
39        </p>
40<h6>
41<a name="geometry.reference.algorithms.num_segments.h1"></a>
42          <span class="phrase"><a name="geometry.reference.algorithms.num_segments.synopsis"></a></span><a class="link" href="num_segments.html#geometry.reference.algorithms.num_segments.synopsis">Synopsis</a>
43        </h6>
44<p>
45</p>
46<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>
47<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">num_segments</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>
48<p>
49        </p>
50<h6>
51<a name="geometry.reference.algorithms.num_segments.h2"></a>
52          <span class="phrase"><a name="geometry.reference.algorithms.num_segments.parameters"></a></span><a class="link" href="num_segments.html#geometry.reference.algorithms.num_segments.parameters">Parameters</a>
53        </h6>
54<div class="informaltable"><table class="table">
55<colgroup>
56<col>
57<col>
58<col>
59<col>
60</colgroup>
61<thead><tr>
62<th>
63                  <p>
64                    Type
65                  </p>
66                </th>
67<th>
68                  <p>
69                    Concept
70                  </p>
71                </th>
72<th>
73                  <p>
74                    Name
75                  </p>
76                </th>
77<th>
78                  <p>
79                    Description
80                  </p>
81                </th>
82</tr></thead>
83<tbody><tr>
84<td>
85                  <p>
86                    Geometry const &amp;
87                  </p>
88                </td>
89<td>
90                  <p>
91                    Any type fulfilling a Geometry Concept
92                  </p>
93                </td>
94<td>
95                  <p>
96                    geometry
97                  </p>
98                </td>
99<td>
100                  <p>
101                    A model of the specified concept
102                  </p>
103                </td>
104</tr></tbody>
105</table></div>
106<h6>
107<a name="geometry.reference.algorithms.num_segments.h3"></a>
108          <span class="phrase"><a name="geometry.reference.algorithms.num_segments.returns"></a></span><a class="link" href="num_segments.html#geometry.reference.algorithms.num_segments.returns">Returns</a>
109        </h6>
110<p>
111          The calculated number of segments
112        </p>
113<h6>
114<a name="geometry.reference.algorithms.num_segments.h4"></a>
115          <span class="phrase"><a name="geometry.reference.algorithms.num_segments.header"></a></span><a class="link" href="num_segments.html#geometry.reference.algorithms.num_segments.header">Header</a>
116        </h6>
117<p>
118          Either
119        </p>
120<p>
121          <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>
122        </p>
123<p>
124          Or
125        </p>
126<p>
127          <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">num_segments</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
128        </p>
129<h6>
130<a name="geometry.reference.algorithms.num_segments.h5"></a>
131          <span class="phrase"><a name="geometry.reference.algorithms.num_segments.conformance"></a></span><a class="link" href="num_segments.html#geometry.reference.algorithms.num_segments.conformance">Conformance</a>
132        </h6>
133<p>
134          The function num_segments is not defined by OGC.
135        </p>
136<h6>
137<a name="geometry.reference.algorithms.num_segments.h6"></a>
138          <span class="phrase"><a name="geometry.reference.algorithms.num_segments.behavior"></a></span><a class="link" href="num_segments.html#geometry.reference.algorithms.num_segments.behavior">Behavior</a>
139        </h6>
140<div class="informaltable"><table class="table">
141<colgroup>
142<col>
143<col>
144</colgroup>
145<thead><tr>
146<th>
147                  <p>
148                    Case
149                  </p>
150                </th>
151<th>
152                  <p>
153                    Behavior
154                  </p>
155                </th>
156</tr></thead>
157<tbody>
158<tr>
159<td>
160                  <p>
161                    pointlike (e.g. point)
162                  </p>
163                </td>
164<td>
165                  <p>
166                    Returns 0
167                  </p>
168                </td>
169</tr>
170<tr>
171<td>
172                  <p>
173                    Segment
174                  </p>
175                </td>
176<td>
177                  <p>
178                    Returns 1
179                  </p>
180                </td>
181</tr>
182<tr>
183<td>
184                  <p>
185                    Box
186                  </p>
187                </td>
188<td>
189                  <p>
190                    Returns d * 2^(d-1), where d is the dimension of the box
191                  </p>
192                </td>
193</tr>
194<tr>
195<td>
196                  <p>
197                    Rangelike (linestring, ring)
198                  </p>
199                </td>
200<td>
201                  <p>
202                    Returns boost::size(geometry) - 1
203                  </p>
204                </td>
205</tr>
206<tr>
207<td>
208                  <p>
209                    Other geometries
210                  </p>
211                </td>
212<td>
213                  <p>
214                    Returns the sum of the number of segments of its elements
215                  </p>
216                </td>
217</tr>
218</tbody>
219</table></div>
220<h6>
221<a name="geometry.reference.algorithms.num_segments.h7"></a>
222          <span class="phrase"><a name="geometry.reference.algorithms.num_segments.complexity"></a></span><a class="link" href="num_segments.html#geometry.reference.algorithms.num_segments.complexity">Complexity</a>
223        </h6>
224<p>
225          Constant or Linear
226        </p>
227<h6>
228<a name="geometry.reference.algorithms.num_segments.h8"></a>
229          <span class="phrase"><a name="geometry.reference.algorithms.num_segments.examples"></a></span><a class="link" href="num_segments.html#geometry.reference.algorithms.num_segments.examples">Examples</a>
230        </h6>
231<p>
232          Get the number of segments in a geometry
233        </p>
234<p>
235</p>
236<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
237
238<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>
239<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>
240
241
242<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
243<span class="special">{</span>
244    <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">multi_polygon</span>
245        <span class="special">&lt;</span>
246            <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>
247                <span class="special">&lt;</span>
248                    <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">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="keyword">true</span><span class="special">,</span> <span class="keyword">false</span> <span class="comment">// cw, open polygon</span>
249                <span class="special">&gt;</span>
250        <span class="special">&gt;</span> <span class="identifier">mp</span><span class="special">;</span>
251    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">read_wkt</span><span class="special">(</span><span class="string">"MULTIPOLYGON(((0 0,0 10,10 0),(1 1,8 1,1 8)),((10 10,10 20,20 10)))"</span><span class="special">,</span> <span class="identifier">mp</span><span class="special">);</span>
252    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Number of segments: "</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">num_segments</span><span class="special">(</span><span class="identifier">mp</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>
253    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
254<span class="special">}</span>
255</pre>
256<p>
257        </p>
258<p>
259          Output:
260        </p>
261<pre class="programlisting">Number of segments: 9
262</pre>
263</div>
264<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
265<td align="left"></td>
266<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
267      Wulkiewicz, Oracle and/or its affiliates<p>
268        Distributed under the Boost Software License, Version 1.0. (See accompanying
269        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>)
270      </p>
271</div></td>
272</tr></table>
273<hr>
274<div class="spirit-nav">
275<a accesskey="p" href="num_points.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="overlaps.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
276</div>
277</body>
278</html>
279