• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>model::segment</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_ring.html" title="model::ring">
10<link rel="next" href="model_referring_segment.html" title="model::referring_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_ring.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_referring_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_segment"></a><a class="link" href="model_segment.html" title="model::segment">model::segment</a>
28</h4></div></div></div>
29<p>
30          <a class="indexterm" name="idm45635678239552"></a><a class="indexterm" name="idm45635678238864"></a>
31Class segment: small class containing two points.
32        </p>
33<h6>
34<a name="geometry.reference.models.model_segment.h0"></a>
35          <span class="phrase"><a name="geometry.reference.models.model_segment.description"></a></span><a class="link" href="model_segment.html#geometry.reference.models.model_segment.description">Description</a>
36        </h6>
37<p>
38          From Wikipedia: In geometry, a line segment is a part of a line that is
39          bounded by two distinct end points, and contains every point on the line
40          between its end points.
41        </p>
42<h6>
43<a name="geometry.reference.models.model_segment.h1"></a>
44          <span class="phrase"><a name="geometry.reference.models.model_segment.model_of"></a></span><a class="link" href="model_segment.html#geometry.reference.models.model_segment.model_of">Model
45          of</a>
46        </h6>
47<p>
48          <a class="link" href="../concepts/concept_segment.html" title="Segment Concept">Segment Concept</a>
49        </p>
50<h6>
51<a name="geometry.reference.models.model_segment.h2"></a>
52          <span class="phrase"><a name="geometry.reference.models.model_segment.synopsis"></a></span><a class="link" href="model_segment.html#geometry.reference.models.model_segment.synopsis">Synopsis</a>
53        </h6>
54<p>
55</p>
56<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Point</span><span class="special">&gt;</span>
57<span class="keyword">class</span> <span class="identifier">model</span><span class="special">::</span><span class="identifier">segment</span>
58      <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span> <span class="identifier">Point</span><span class="special">,</span> <span class="identifier">Point</span> <span class="special">&gt;</span>
59<span class="special">{</span>
60  <span class="comment">// ...</span>
61<span class="special">};</span>
62</pre>
63<p>
64        </p>
65<h6>
66<a name="geometry.reference.models.model_segment.h3"></a>
67          <span class="phrase"><a name="geometry.reference.models.model_segment.template_parameter_s_"></a></span><a class="link" href="model_segment.html#geometry.reference.models.model_segment.template_parameter_s_">Template
68          parameter(s)</a>
69        </h6>
70<div class="informaltable"><table class="table">
71<colgroup>
72<col>
73<col>
74</colgroup>
75<thead><tr>
76<th>
77                  <p>
78                    Parameter
79                  </p>
80                </th>
81<th>
82                  <p>
83                    Description
84                  </p>
85                </th>
86</tr></thead>
87<tbody><tr>
88<td>
89                  <p>
90                    typename Point
91                  </p>
92                </td>
93<td>
94                </td>
95</tr></tbody>
96</table></div>
97<h6>
98<a name="geometry.reference.models.model_segment.h4"></a>
99          <span class="phrase"><a name="geometry.reference.models.model_segment.constructor_s_"></a></span><a class="link" href="model_segment.html#geometry.reference.models.model_segment.constructor_s_">Constructor(s)</a>
100        </h6>
101<div class="informaltable"><table class="table">
102<colgroup>
103<col>
104<col>
105<col>
106</colgroup>
107<thead><tr>
108<th>
109                  <p>
110                    Function
111                  </p>
112                </th>
113<th>
114                  <p>
115                    Description
116                  </p>
117                </th>
118<th>
119                  <p>
120                    Parameters
121                  </p>
122                </th>
123</tr></thead>
124<tbody>
125<tr>
126<td>
127                  <p>
128</p>
129<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">segment</span><span class="special">()</span></pre>
130<p>
131                  </p>
132                </td>
133<td>
134                  <p>
135                    Default constructor, no initialization.
136                  </p>
137                </td>
138<td>
139                </td>
140</tr>
141<tr>
142<td>
143                  <p>
144</p>
145<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">segment</span><span class="special">(</span><span class="identifier">Point</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">p1</span><span class="special">,</span> <span class="identifier">Point</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">p2</span><span class="special">)</span></pre>
146<p>
147                  </p>
148                </td>
149<td>
150                  <p>
151                    Constructor taking the first and the second point.
152                  </p>
153                </td>
154<td>
155                  <p>
156                    <span class="bold"><strong>Point const &amp;</strong></span>: <span class="emphasis"><em>p1</em></span>:
157                  </p>
158                  <p>
159                    <span class="bold"><strong>Point const &amp;</strong></span>: <span class="emphasis"><em>p2</em></span>:
160                  </p>
161                </td>
162</tr>
163</tbody>
164</table></div>
165<h6>
166<a name="geometry.reference.models.model_segment.h5"></a>
167          <span class="phrase"><a name="geometry.reference.models.model_segment.header"></a></span><a class="link" href="model_segment.html#geometry.reference.models.model_segment.header">Header</a>
168        </h6>
169<p>
170          Either
171        </p>
172<p>
173          <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">geometries</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
174        </p>
175<p>
176          Or
177        </p>
178<p>
179          <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">geometries</span><span class="special">/</span><span class="identifier">segment</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
180        </p>
181<h6>
182<a name="geometry.reference.models.model_segment.h6"></a>
183          <span class="phrase"><a name="geometry.reference.models.model_segment.examples"></a></span><a class="link" href="model_segment.html#geometry.reference.models.model_segment.examples">Examples</a>
184        </h6>
185<p>
186          Declaration and use of the Boost.Geometry model::segment, modelling the
187          Segment Concept
188        </p>
189<p>
190</p>
191<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
192<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>
193<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">geometries</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
194
195<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>
196
197<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
198<span class="special">{</span>
199    <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">&lt;</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">&gt;</span> <span class="identifier">point_t</span><span class="special">;</span>
200    <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">segment</span><span class="special">&lt;</span><span class="identifier">point_t</span><span class="special">&gt;</span> <span class="identifier">segment_t</span><span class="special">;</span>
201
202    <span class="identifier">segment_t</span> <span class="identifier">seg1</span><span class="special">;</span> <a class="co" name="geometry.reference.models.model_segment.c0" href="model_segment.html#geometry.reference.models.model_segment.c1"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>
203    <span class="identifier">segment_t</span> <span class="identifier">seg2</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> <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> <a class="co" name="geometry.reference.models.model_segment.c2" href="model_segment.html#geometry.reference.models.model_segment.c3"><img src="../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a>
204
205<span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX</span>
206
207    <span class="identifier">segment_t</span> <span class="identifier">seg3</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">5.0</span><span class="special">,</span> <span class="number">5.0</span><span class="special">}};</span> <a class="co" name="geometry.reference.models.model_segment.c4" href="model_segment.html#geometry.reference.models.model_segment.c5"><img src="../../../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a>
208
209<span class="preprocessor">#endif</span>
210
211    <span class="identifier">bg</span><span class="special">::</span><span class="identifier">set</span><span class="special">&lt;</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;(</span><span class="identifier">seg1</span><span class="special">,</span> <span class="number">1.0</span><span class="special">);</span> <a class="co" name="geometry.reference.models.model_segment.c6" href="model_segment.html#geometry.reference.models.model_segment.c7"><img src="../../../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a>
212    <span class="identifier">bg</span><span class="special">::</span><span class="identifier">set</span><span class="special">&lt;</span><span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">&gt;(</span><span class="identifier">seg1</span><span class="special">,</span> <span class="number">2.0</span><span class="special">);</span>
213    <span class="identifier">bg</span><span class="special">::</span><span class="identifier">set</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;(</span><span class="identifier">seg1</span><span class="special">,</span> <span class="number">3.0</span><span class="special">);</span>
214    <span class="identifier">bg</span><span class="special">::</span><span class="identifier">set</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">1</span><span class="special">&gt;(</span><span class="identifier">seg1</span><span class="special">,</span> <span class="number">4.0</span><span class="special">);</span>
215
216    <span class="keyword">double</span> <span class="identifier">x0</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;(</span><span class="identifier">seg1</span><span class="special">);</span> <a class="co" name="geometry.reference.models.model_segment.c8" href="model_segment.html#geometry.reference.models.model_segment.c9"><img src="../../../../../../../doc/src/images/callouts/5.png" alt="5" border="0"></a>
217    <span class="keyword">double</span> <span class="identifier">y0</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">&gt;(</span><span class="identifier">seg1</span><span class="special">);</span>
218    <span class="keyword">double</span> <span class="identifier">x1</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;(</span><span class="identifier">seg1</span><span class="special">);</span>
219    <span class="keyword">double</span> <span class="identifier">y1</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">1</span><span class="special">&gt;(</span><span class="identifier">seg1</span><span class="special">);</span>
220
221    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">x0</span> <span class="special">&lt;&lt;</span> <span class="string">", "</span> <span class="special">&lt;&lt;</span> <span class="identifier">y0</span> <span class="special">&lt;&lt;</span> <span class="string">", "</span> <span class="special">&lt;&lt;</span> <span class="identifier">x1</span> <span class="special">&lt;&lt;</span> <span class="string">", "</span> <span class="special">&lt;&lt;</span> <span class="identifier">y1</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>
222
223    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
224<span class="special">}</span>
225</pre>
226<p>
227        </p>
228<div class="calloutlist"><table border="0" summary="Callout list">
229<tr>
230<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_segment.c1"></a><a href="#geometry.reference.models.model_segment.c0"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
231<td valign="top" align="left"><p>
232              Default-construct a segment.
233            </p></td>
234</tr>
235<tr>
236<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_segment.c3"></a><a href="#geometry.reference.models.model_segment.c2"><img src="../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
237<td valign="top" align="left"><p>
238              Construct, assigning the first and the second point.
239            </p></td>
240</tr>
241<tr>
242<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_segment.c5"></a><a href="#geometry.reference.models.model_segment.c4"><img src="../../../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> </p></td>
243<td valign="top" align="left"><p>
244              Construct, using C++11 unified initialization syntax.
245            </p></td>
246</tr>
247<tr>
248<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_segment.c7"></a><a href="#geometry.reference.models.model_segment.c6"><img src="../../../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a> </p></td>
249<td valign="top" align="left"><p>
250              Set a coordinate.
251            </p></td>
252</tr>
253<tr>
254<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_segment.c9"></a><a href="#geometry.reference.models.model_segment.c8"><img src="../../../../../../../doc/src/images/callouts/5.png" alt="5" border="0"></a> </p></td>
255<td valign="top" align="left"><p>
256              Get a coordinate.
257            </p></td>
258</tr>
259</table></div>
260<p>
261          Output:
262        </p>
263<pre class="programlisting">1, 2, 3, 4
264</pre>
265</div>
266<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
267<td align="left"></td>
268<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
269      Wulkiewicz, Oracle and/or its affiliates<p>
270        Distributed under the Boost Software License, Version 1.0. (See accompanying
271        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>)
272      </p>
273</div></td>
274</tr></table>
275<hr>
276<div class="spirit-nav">
277<a accesskey="p" href="model_ring.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_referring_segment.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
278</div>
279</body>
280</html>
281