1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>touches (two geometries)</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="../touches.html" title="touches"> 9<link rel="prev" href="touches_1_one_geometry.html" title="touches (one geometry)"> 10<link rel="next" href="touches_3_with_strategy.html" title="touches (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="touches_1_one_geometry.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../touches.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="touches_3_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.touches.touches_2_two_geometries"></a><a class="link" href="touches_2_two_geometries.html" title="touches (two geometries)">touches 28 (two geometries)</a> 29</h5></div></div></div> 30<p> 31 <a class="indexterm" name="idm45635688319232"></a> 32Checks if two geometries have at least one touching point (tangent - 33 non overlapping) 34 </p> 35<h6> 36<a name="geometry.reference.algorithms.touches.touches_2_two_geometries.h0"></a> 37 <span class="phrase"><a name="geometry.reference.algorithms.touches.touches_2_two_geometries.synopsis"></a></span><a class="link" href="touches_2_two_geometries.html#geometry.reference.algorithms.touches.touches_2_two_geometries.synopsis">Synopsis</a> 38 </h6> 39<p> 40</p> 41<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Geometry1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Geometry2</span><span class="special">></span> 42<span class="keyword">bool</span> <span class="identifier">touches</span><span class="special">(</span><span class="identifier">Geometry1</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">geometry1</span><span class="special">,</span> <span class="identifier">Geometry2</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">geometry2</span><span class="special">)</span></pre> 43<p> 44 </p> 45<h6> 46<a name="geometry.reference.algorithms.touches.touches_2_two_geometries.h1"></a> 47 <span class="phrase"><a name="geometry.reference.algorithms.touches.touches_2_two_geometries.parameters"></a></span><a class="link" href="touches_2_two_geometries.html#geometry.reference.algorithms.touches.touches_2_two_geometries.parameters">Parameters</a> 48 </h6> 49<div class="informaltable"><table class="table"> 50<colgroup> 51<col> 52<col> 53<col> 54<col> 55</colgroup> 56<thead><tr> 57<th> 58 <p> 59 Type 60 </p> 61 </th> 62<th> 63 <p> 64 Concept 65 </p> 66 </th> 67<th> 68 <p> 69 Name 70 </p> 71 </th> 72<th> 73 <p> 74 Description 75 </p> 76 </th> 77</tr></thead> 78<tbody> 79<tr> 80<td> 81 <p> 82 Geometry1 const & 83 </p> 84 </td> 85<td> 86 <p> 87 Any type fulfilling a Geometry Concept 88 </p> 89 </td> 90<td> 91 <p> 92 geometry1 93 </p> 94 </td> 95<td> 96 <p> 97 A model of the specified concept 98 </p> 99 </td> 100</tr> 101<tr> 102<td> 103 <p> 104 Geometry2 const & 105 </p> 106 </td> 107<td> 108 <p> 109 Any type fulfilling a Geometry Concept 110 </p> 111 </td> 112<td> 113 <p> 114 geometry2 115 </p> 116 </td> 117<td> 118 <p> 119 A model of the specified concept 120 </p> 121 </td> 122</tr> 123</tbody> 124</table></div> 125<h6> 126<a name="geometry.reference.algorithms.touches.touches_2_two_geometries.h2"></a> 127 <span class="phrase"><a name="geometry.reference.algorithms.touches.touches_2_two_geometries.returns"></a></span><a class="link" href="touches_2_two_geometries.html#geometry.reference.algorithms.touches.touches_2_two_geometries.returns">Returns</a> 128 </h6> 129<p> 130 Returns true if two geometries touch each other 131 </p> 132<h6> 133<a name="geometry.reference.algorithms.touches.touches_2_two_geometries.h3"></a> 134 <span class="phrase"><a name="geometry.reference.algorithms.touches.touches_2_two_geometries.header"></a></span><a class="link" href="touches_2_two_geometries.html#geometry.reference.algorithms.touches.touches_2_two_geometries.header">Header</a> 135 </h6> 136<p> 137 Either 138 </p> 139<p> 140 <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> 141 </p> 142<p> 143 Or 144 </p> 145<p> 146 <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">touches</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 147 </p> 148<h6> 149<a name="geometry.reference.algorithms.touches.touches_2_two_geometries.h4"></a> 150 <span class="phrase"><a name="geometry.reference.algorithms.touches.touches_2_two_geometries.conformance"></a></span><a class="link" href="touches_2_two_geometries.html#geometry.reference.algorithms.touches.touches_2_two_geometries.conformance">Conformance</a> 151 </h6> 152<p> 153 The function touches implements function Touches from the <a href="http://www.opengeospatial.org/standards/sfa" target="_top">OGC 154 Simple Feature Specification</a>. 155 </p> 156<p> 157 The version with one parameter is additional and not described in the 158 OGC standard 159 </p> 160<div class="note"><table border="0" summary="Note"> 161<tr> 162<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td> 163<th align="left">Note</th> 164</tr> 165<tr><td align="left" valign="top"><p> 166 Implemented for Point/Linestring/MultiLinestring/Polygon/MultiPolygon. 167 </p></td></tr> 168</table></div> 169<h6> 170<a name="geometry.reference.algorithms.touches.touches_2_two_geometries.h5"></a> 171 <span class="phrase"><a name="geometry.reference.algorithms.touches.touches_2_two_geometries.examples"></a></span><a class="link" href="touches_2_two_geometries.html#geometry.reference.algorithms.touches.touches_2_two_geometries.examples">Examples</a> 172 </h6> 173<p> 174 Checks if two geometries have at least one touching point (tangent - 175 non overlapping) 176 </p> 177<p> 178</p> 179<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 180 181<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> 182<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> 183<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">polygon</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 184 185<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.touches.touches_2_two_geometries.c0" href="touches_2_two_geometries.html#geometry.reference.algorithms.touches.touches_2_two_geometries.c1"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> 186 187<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 188<span class="special">{</span> 189 <span class="comment">// Checks if the two geometries touch</span> 190 <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"><</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"><</span><span class="keyword">double</span><span class="special">></span> <span class="special">></span> <span class="identifier">poly1</span><span class="special">;</span> 191 <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,0 4,4 4,4 0,0 0))"</span><span class="special">,</span> <span class="identifier">poly1</span><span class="special">);</span> 192 <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"><</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"><</span><span class="keyword">double</span><span class="special">></span> <span class="special">></span> <span class="identifier">poly2</span><span class="special">;</span> 193 <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,0 -4,-4 -4,-4 0,0 0))"</span><span class="special">,</span> <span class="identifier">poly2</span><span class="special">);</span> 194 <span class="keyword">bool</span> <span class="identifier">check_touches</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">touches</span><span class="special">(</span><span class="identifier">poly1</span><span class="special">,</span> <span class="identifier">poly2</span><span class="special">);</span> 195 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">check_touches</span><span class="special">)</span> <span class="special">{</span> 196 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Touches: Yes"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 197 <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span> 198 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Touches: No"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 199 <span class="special">}</span> 200 201 <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"><</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"><</span><span class="keyword">double</span><span class="special">></span> <span class="special">></span> <span class="identifier">poly3</span><span class="special">;</span> 202 <span class="identifier">bg</span><span class="special">::</span><span class="identifier">read_wkt</span><span class="special">(</span><span class="string">"POLYGON((1 1,0 -4,-4 -4,-4 0,1 1))"</span><span class="special">,</span> <span class="identifier">poly3</span><span class="special">);</span> 203 <span class="identifier">check_touches</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">touches</span><span class="special">(</span><span class="identifier">poly1</span><span class="special">,</span> <span class="identifier">poly3</span><span class="special">);</span> 204 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">check_touches</span><span class="special">)</span> <span class="special">{</span> 205 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Touches: Yes"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 206 <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span> 207 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Touches: No"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 208 <span class="special">}</span> 209 210 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 211<span class="special">}</span> 212</pre> 213<p> 214 </p> 215<div class="calloutlist"><table border="0" summary="Callout list"><tr> 216<td width="5%" valign="top" align="left"><p><a name="geometry.reference.algorithms.touches.touches_2_two_geometries.c1"></a><a href="#geometry.reference.algorithms.touches.touches_2_two_geometries.c0"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td> 217<td valign="top" align="left"><p> 218 Convenient namespace alias 219 </p></td> 220</tr></table></div> 221<p> 222 Output: 223 </p> 224<pre class="programlisting">Touches: Yes 225 226<img src="../../../../img/algorithms/touches_two_geometries.png" alt="touches_two_geometries"> 227 228Touches: No 229</pre> 230</div> 231<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 232<td align="left"></td> 233<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 234 Wulkiewicz, Oracle and/or its affiliates<p> 235 Distributed under the Boost Software License, Version 1.0. (See accompanying 236 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>) 237 </p> 238</div></td> 239</tr></table> 240<hr> 241<div class="spirit-nav"> 242<a accesskey="p" href="touches_1_one_geometry.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../touches.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="touches_3_with_strategy.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 243</div> 244</body> 245</html> 246