1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>model::ring</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="../models.html" title="Models"> 9<link rel="prev" href="model_box.html" title="model::box"> 10<link rel="next" href="model_segment.html" title="model::segment"> 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="model_box.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../models.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="model_segment.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.models.model_ring"></a><a class="link" href="model_ring.html" title="model::ring">model::ring</a> 28</h4></div></div></div> 29<p> 30 <a class="indexterm" name="idm45635678487872"></a><a class="indexterm" name="idm45635678487184"></a> 31A ring (aka linear ring) is a closed line which should not be selfintersecting. 32 </p> 33<h6> 34<a name="geometry.reference.models.model_ring.h0"></a> 35 <span class="phrase"><a name="geometry.reference.models.model_ring.model_of"></a></span><a class="link" href="model_ring.html#geometry.reference.models.model_ring.model_of">Model 36 of</a> 37 </h6> 38<p> 39 <a class="link" href="../concepts/concept_ring.html" title="Ring Concept">Ring Concept</a> 40 </p> 41<h6> 42<a name="geometry.reference.models.model_ring.h1"></a> 43 <span class="phrase"><a name="geometry.reference.models.model_ring.synopsis"></a></span><a class="link" href="model_ring.html#geometry.reference.models.model_ring.synopsis">Synopsis</a> 44 </h6> 45<p> 46</p> 47<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Point</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">ClockWise</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">Closed</span><span class="special">,</span> <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span><span class="special">,</span> <span class="keyword">typename</span> <span class="special">></span> <span class="keyword">class</span> <span class="identifier">Container</span><span class="special">,</span> 48 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="special">></span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">></span> 49<span class="keyword">class</span> <span class="identifier">model</span><span class="special">::</span><span class="identifier">ring</span> 50 <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">Container</span><span class="special"><</span> <span class="identifier">Point</span><span class="special">,</span> <span class="identifier">Allocator</span><span class="special"><</span> <span class="identifier">Point</span> <span class="special">></span> <span class="special">></span> 51<span class="special">{</span> 52 <span class="comment">// ...</span> 53<span class="special">};</span> 54</pre> 55<p> 56 </p> 57<h6> 58<a name="geometry.reference.models.model_ring.h2"></a> 59 <span class="phrase"><a name="geometry.reference.models.model_ring.template_parameter_s_"></a></span><a class="link" href="model_ring.html#geometry.reference.models.model_ring.template_parameter_s_">Template 60 parameter(s)</a> 61 </h6> 62<div class="informaltable"><table class="table"> 63<colgroup> 64<col> 65<col> 66<col> 67</colgroup> 68<thead><tr> 69<th> 70 <p> 71 Parameter 72 </p> 73 </th> 74<th> 75 <p> 76 Default 77 </p> 78 </th> 79<th> 80 <p> 81 Description 82 </p> 83 </th> 84</tr></thead> 85<tbody> 86<tr> 87<td> 88 <p> 89 typename Point 90 </p> 91 </td> 92<td> 93 </td> 94<td> 95 <p> 96 point type 97 </p> 98 </td> 99</tr> 100<tr> 101<td> 102 <p> 103 bool ClockWise 104 </p> 105 </td> 106<td> 107 <p> 108 true 109 </p> 110 </td> 111<td> 112 <p> 113 true for clockwise direction, false for CounterClockWise direction 114 </p> 115 </td> 116</tr> 117<tr> 118<td> 119 <p> 120 bool Closed 121 </p> 122 </td> 123<td> 124 <p> 125 true 126 </p> 127 </td> 128<td> 129 <p> 130 true for closed polygons (last point == first point), false open 131 points 132 </p> 133 </td> 134</tr> 135<tr> 136<td> 137 <p> 138 template< typename, typename > class Container 139 </p> 140 </td> 141<td> 142 <p> 143 std::vector 144 </p> 145 </td> 146<td> 147 <p> 148 container type, for example std::vector, std::deque 149 </p> 150 </td> 151</tr> 152<tr> 153<td> 154 <p> 155 template< typename > class Allocator 156 </p> 157 </td> 158<td> 159 <p> 160 std::allocator 161 </p> 162 </td> 163<td> 164 <p> 165 container-allocator-type 166 </p> 167 </td> 168</tr> 169</tbody> 170</table></div> 171<h6> 172<a name="geometry.reference.models.model_ring.h3"></a> 173 <span class="phrase"><a name="geometry.reference.models.model_ring.constructor_s_"></a></span><a class="link" href="model_ring.html#geometry.reference.models.model_ring.constructor_s_">Constructor(s)</a> 174 </h6> 175<div class="informaltable"><table class="table"> 176<colgroup> 177<col> 178<col> 179<col> 180</colgroup> 181<thead><tr> 182<th> 183 <p> 184 Function 185 </p> 186 </th> 187<th> 188 <p> 189 Description 190 </p> 191 </th> 192<th> 193 <p> 194 Parameters 195 </p> 196 </th> 197</tr></thead> 198<tbody> 199<tr> 200<td> 201 <p> 202</p> 203<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">ring</span><span class="special">()</span></pre> 204<p> 205 </p> 206 </td> 207<td> 208 <p> 209 Default constructor, creating an empty ring. 210 </p> 211 </td> 212<td> 213 </td> 214</tr> 215<tr> 216<td> 217 <p> 218</p> 219<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">></span> 220<span class="identifier">ring</span><span class="special">(</span><span class="identifier">Iterator</span> <span class="identifier">begin</span><span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">end</span><span class="special">)</span></pre> 221<p> 222 </p> 223 </td> 224<td> 225 <p> 226 Constructor with begin and end, filling the ring. 227 </p> 228 </td> 229<td> 230 <p> 231 <span class="bold"><strong>Iterator</strong></span>: <span class="emphasis"><em>begin</em></span>: 232 </p> 233 <p> 234 <span class="bold"><strong>Iterator</strong></span>: <span class="emphasis"><em>end</em></span>: 235 </p> 236 </td> 237</tr> 238<tr> 239<td> 240 <p> 241</p> 242<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">ring</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special"><</span> <span class="identifier">Point</span> <span class="special">></span> <span class="identifier">l</span><span class="special">)</span></pre> 243<p> 244 </p> 245 </td> 246<td> 247 <p> 248 Constructor taking std::initializer_list, filling the ring. 249 </p> 250 </td> 251<td> 252 <p> 253 <span class="bold"><strong>std::initializer_list< Point ></strong></span>: 254 <span class="emphasis"><em>l</em></span>: 255 </p> 256 </td> 257</tr> 258</tbody> 259</table></div> 260<h6> 261<a name="geometry.reference.models.model_ring.h4"></a> 262 <span class="phrase"><a name="geometry.reference.models.model_ring.header"></a></span><a class="link" href="model_ring.html#geometry.reference.models.model_ring.header">Header</a> 263 </h6> 264<p> 265 Either 266 </p> 267<p> 268 <code class="computeroutput"><span class="preprocessor">#include</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">geometries</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 269 </p> 270<p> 271 Or 272 </p> 273<p> 274 <code class="computeroutput"><span class="preprocessor">#include</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">geometries</span><span class="special">/</span><span class="identifier">ring</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 275 </p> 276<h6> 277<a name="geometry.reference.models.model_ring.h5"></a> 278 <span class="phrase"><a name="geometry.reference.models.model_ring.examples"></a></span><a class="link" href="model_ring.html#geometry.reference.models.model_ring.examples">Examples</a> 279 </h6> 280<p> 281 Declaration and use of the Boost.Geometry model::ring, modelling the Ring 282 Concept 283 </p> 284<p> 285</p> 286<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 287<span class="preprocessor">#include</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">hpp</span><span class="special">></span> 288<span class="preprocessor">#include</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">geometries</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 289 290<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> 291 292<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 293<span class="special">{</span> 294 <span class="keyword">typedef</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special"><</span><span class="keyword">double</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">></span> <span class="identifier">point_t</span><span class="special">;</span> 295 <span class="keyword">typedef</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">ring</span><span class="special"><</span><span class="identifier">point_t</span><span class="special">></span> <span class="identifier">ring_t</span><span class="special">;</span> <a class="co" name="geometry.reference.models.model_ring.c0" href="model_ring.html#geometry.reference.models.model_ring.c1"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> 296 297 <span class="identifier">ring_t</span> <span class="identifier">ring1</span><span class="special">;</span> <a class="co" name="geometry.reference.models.model_ring.c2" href="model_ring.html#geometry.reference.models.model_ring.c3"><img src="../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> 298 299<span class="preprocessor">#if</span> <span class="special">!</span><span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX</span><span class="special">)</span> <span class="special">\</span> 300 <span class="special">&&</span> <span class="special">!</span><span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_NO_CXX11_HDR_INITIALIZER_LIST</span><span class="special">)</span> 301 302 <span class="identifier">ring_t</span> <span class="identifier">ring2</span><span class="special">{{</span><span class="number">0.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">},</span> <span class="special">{</span><span class="number">0.0</span><span class="special">,</span> <span class="number">5.0</span><span class="special">},</span> <span class="special">{</span><span class="number">5.0</span><span class="special">,</span> <span class="number">5.0</span><span class="special">},</span> <span class="special">{</span><span class="number">5.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">},</span> <span class="special">{</span><span class="number">0.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">}};</span> <a class="co" name="geometry.reference.models.model_ring.c4" href="model_ring.html#geometry.reference.models.model_ring.c5"><img src="../../../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> 303 304<span class="preprocessor">#endif</span> 305 306 <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ring1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">0.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">));</span> <a class="co" name="geometry.reference.models.model_ring.c6" href="model_ring.html#geometry.reference.models.model_ring.c7"><img src="../../../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a> 307 <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ring1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">0.0</span><span class="special">,</span> <span class="number">5.0</span><span class="special">));</span> 308 <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ring1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">5.0</span><span class="special">,</span> <span class="number">5.0</span><span class="special">));</span> 309 <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ring1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">5.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">));</span> 310 <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ring1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">0.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">));</span> 311 312 <span class="keyword">double</span> <span class="identifier">a</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">area</span><span class="special">(</span><span class="identifier">ring1</span><span class="special">);</span> 313 314 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">a</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 315 316 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 317<span class="special">}</span> 318</pre> 319<p> 320 </p> 321<div class="calloutlist"><table border="0" summary="Callout list"> 322<tr> 323<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_ring.c1"></a><a href="#geometry.reference.models.model_ring.c0"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td> 324<td valign="top" align="left"><p> 325 Default parameters, clockwise, closed ring. 326 </p></td> 327</tr> 328<tr> 329<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_ring.c3"></a><a href="#geometry.reference.models.model_ring.c2"><img src="../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td> 330<td valign="top" align="left"><p> 331 Default-construct a ring. 332 </p></td> 333</tr> 334<tr> 335<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_ring.c5"></a><a href="#geometry.reference.models.model_ring.c4"><img src="../../../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> </p></td> 336<td valign="top" align="left"><p> 337 Construct a ring containing four points plus one closing point, using 338 C++11 unified initialization syntax. 339 </p></td> 340</tr> 341<tr> 342<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_ring.c7"></a><a href="#geometry.reference.models.model_ring.c6"><img src="../../../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a> </p></td> 343<td valign="top" align="left"><p> 344 Append point. 345 </p></td> 346</tr> 347</table></div> 348<p> 349 Output: 350 </p> 351<pre class="programlisting">25 352</pre> 353</div> 354<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 355<td align="left"></td> 356<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 357 Wulkiewicz, Oracle and/or its affiliates<p> 358 Distributed under the Boost Software License, Version 1.0. (See accompanying 359 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>) 360 </p> 361</div></td> 362</tr></table> 363<hr> 364<div class="spirit-nav"> 365<a accesskey="p" href="model_box.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../models.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="model_segment.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 366</div> 367</body> 368</html> 369