1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>assign_values (2 coordinate values)</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="../assign.html" title="assign"> 9<link rel="prev" href="assign_points.html" title="assign_points"> 10<link rel="next" href="assign_values_4_3_coordinate_values.html" title="assign_values (3 coordinate values)"> 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="assign_points.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../assign.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="assign_values_4_3_coordinate_values.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.assign.assign_values_3_2_coordinate_values"></a><a class="link" href="assign_values_3_2_coordinate_values.html" title="assign_values (2 coordinate values)">assign_values 28 (2 coordinate values)</a> 29</h5></div></div></div> 30<p> 31 <a class="indexterm" name="idm45635707096496"></a> 32Assign two coordinates to a geometry (usually a 2D point) 33 </p> 34<h6> 35<a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.h0"></a> 36 <span class="phrase"><a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.synopsis"></a></span><a class="link" href="assign_values_3_2_coordinate_values.html#geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.synopsis">Synopsis</a> 37 </h6> 38<p> 39</p> 40<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Geometry</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Type</span><span class="special">></span> 41<span class="keyword">void</span> <span class="identifier">assign_values</span><span class="special">(</span><span class="identifier">Geometry</span> <span class="special">&</span> <span class="identifier">geometry</span><span class="special">,</span> <span class="identifier">Type</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">c1</span><span class="special">,</span> <span class="identifier">Type</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">c2</span><span class="special">)</span></pre> 42<p> 43 </p> 44<h6> 45<a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.h1"></a> 46 <span class="phrase"><a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.parameters"></a></span><a class="link" href="assign_values_3_2_coordinate_values.html#geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.parameters">Parameters</a> 47 </h6> 48<div class="informaltable"><table class="table"> 49<colgroup> 50<col> 51<col> 52<col> 53<col> 54</colgroup> 55<thead><tr> 56<th> 57 <p> 58 Type 59 </p> 60 </th> 61<th> 62 <p> 63 Concept 64 </p> 65 </th> 66<th> 67 <p> 68 Name 69 </p> 70 </th> 71<th> 72 <p> 73 Description 74 </p> 75 </th> 76</tr></thead> 77<tbody> 78<tr> 79<td> 80 <p> 81 Geometry & 82 </p> 83 </td> 84<td> 85 <p> 86 Any type fulfilling a Geometry Concept 87 </p> 88 </td> 89<td> 90 <p> 91 geometry 92 </p> 93 </td> 94<td> 95 <p> 96 A model of the specified concept 97 </p> 98 </td> 99</tr> 100<tr> 101<td> 102 <p> 103 Type const & 104 </p> 105 </td> 106<td> 107 <p> 108 numerical type (int, double, ttmath, ...) to specify the coordinates 109 </p> 110 </td> 111<td> 112 <p> 113 c1 114 </p> 115 </td> 116<td> 117 <p> 118 First coordinate (usually x-coordinate) 119 </p> 120 </td> 121</tr> 122<tr> 123<td> 124 <p> 125 Type const & 126 </p> 127 </td> 128<td> 129 <p> 130 numerical type (int, double, ttmath, ...) to specify the coordinates 131 </p> 132 </td> 133<td> 134 <p> 135 c2 136 </p> 137 </td> 138<td> 139 <p> 140 Second coordinate (usually y-coordinate) 141 </p> 142 </td> 143</tr> 144</tbody> 145</table></div> 146<h6> 147<a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.h2"></a> 148 <span class="phrase"><a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.header"></a></span><a class="link" href="assign_values_3_2_coordinate_values.html#geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.header">Header</a> 149 </h6> 150<p> 151 Either 152 </p> 153<p> 154 <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">hpp</span><span class="special">></span></code> 155 </p> 156<p> 157 Or 158 </p> 159<p> 160 <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">algorithms</span><span class="special">/</span><span class="identifier">assign</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 161 </p> 162<h6> 163<a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.h3"></a> 164 <span class="phrase"><a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.example"></a></span><a class="link" href="assign_values_3_2_coordinate_values.html#geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.example">Example</a> 165 </h6> 166<p> 167 Shows the usage of assign to set point coordinates, and, besides that, 168 shows how you can initialize ttmath points with high precision 169 </p> 170<p> 171</p> 172<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 173<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iomanip</span><span class="special">></span> 174 175<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> 176<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">point_xy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 177 178<span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">HAVE_TTMATH</span><span class="special">)</span> 179<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">extensions</span><span class="special">/</span><span class="identifier">contrib</span><span class="special">/</span><span class="identifier">ttmath_stub</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 180<span class="preprocessor">#endif</span> 181 182 183<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 184<span class="special">{</span> 185 <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">assign_values</span><span class="special">;</span> 186 187 188 <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"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">p1</span><span class="special">;</span> 189 <span class="identifier">assign_values</span><span class="special">(</span><span class="identifier">p1</span><span class="special">,</span> <span class="number">1.2345</span><span class="special">,</span> <span class="number">2.3456</span><span class="special">);</span> 190 191<span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">HAVE_TTMATH</span><span class="special">)</span> 192 <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"><</span><span class="identifier">ttmath</span><span class="special">::</span><span class="identifier">Big</span><span class="special"><</span><span class="number">1</span><span class="special">,</span><span class="number">4</span><span class="special">></span> <span class="special">></span> <span class="identifier">p2</span><span class="special">;</span> 193 <span class="identifier">assign_values</span><span class="special">(</span><span class="identifier">p2</span><span class="special">,</span> <span class="string">"1.2345"</span><span class="special">,</span> <span class="string">"2.3456"</span><span class="special">);</span> <a class="co" name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.c0" href="assign_values_3_2_coordinate_values.html#geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.c1"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> 194<span class="preprocessor">#endif</span> 195 196 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> 197 <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="number">20</span><span class="special">)</span> 198 <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">dsv</span><span class="special">(</span><span class="identifier">p1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> 199<span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">HAVE_TTMATH</span><span class="special">)</span> 200 <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">dsv</span><span class="special">(</span><span class="identifier">p2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> 201<span class="preprocessor">#endif</span> 202 <span class="special">;</span> 203 204 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 205<span class="special">}</span> 206</pre> 207<p> 208 </p> 209<div class="calloutlist"><table border="0" summary="Callout list"><tr> 210<td width="5%" valign="top" align="left"><p><a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.c1"></a><a href="#geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.c0"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td> 211<td valign="top" align="left"><p> 212 It is possible to assign coordinates with other types than the coordinate 213 type. For ttmath, you can e.g. conveniently use strings. The advantage 214 is that it then has higher precision, because if doubles are used 215 for assignments the double-precision is used. 216 </p></td> 217</tr></table></div> 218<p> 219 Output: 220 </p> 221<pre class="programlisting">(1.2344999999999999, 2.3456000000000001) 222(1.2345, 2.3456) 223</pre> 224<h6> 225<a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.h4"></a> 226 <span class="phrase"><a name="geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.see_also"></a></span><a class="link" href="assign_values_3_2_coordinate_values.html#geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values.see_also">See 227 also</a> 228 </h6> 229<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 230 <a class="link" href="../make/make_2_2_coordinate_values.html" title="make (2 coordinate values)">make</a> 231 </li></ul></div> 232</div> 233<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 234<td align="left"></td> 235<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 236 Wulkiewicz, Oracle and/or its affiliates<p> 237 Distributed under the Boost Software License, Version 1.0. (See accompanying 238 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>) 239 </p> 240</div></td> 241</tr></table> 242<hr> 243<div class="spirit-nav"> 244<a accesskey="p" href="assign_points.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../assign.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="assign_values_4_3_coordinate_values.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 245</div> 246</body> 247</html> 248