Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / geometry / doc / html / geometry / reference / algorithms / difference / difference_4_with_strategy.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>difference (with strategy)</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&#160;1.&#160;Geometry">
8 <link rel="up" href="../difference.html" title="difference">
9 <link rel="prev" href="../difference.html" title="difference">
10 <link rel="next" href="difference_3.html" title="difference">
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="../difference.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../difference.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="difference_3.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.difference.difference_4_with_strategy"></a><a class="link" href="difference_4_with_strategy.html" title="difference (with strategy)">difference
28           (with strategy)</a>
29 </h5></div></div></div>
30 <p>
31             <a class="indexterm" name="idm46187003664080"></a>
32           </p>
33 <h6>
34 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h0"></a>
35             <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.description"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.description">Description</a>
36           </h6>
37 <p>
38             Calculate the difference of two geometries
39           </p>
40 <p>
41             The free function difference calculates the spatial set theoretic difference
42             of two geometries.
43           </p>
44 <h6>
45 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h1"></a>
46             <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.synopsis"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.synopsis">Synopsis</a>
47           </h6>
48 <p>
49 </p>
50 <pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</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> <span class="keyword">typename</span> <span class="identifier">Collection</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Strategy</span><span class="special">&gt;</span>
51 <span class="keyword">void</span> <span class="identifier">difference</span><span class="special">(</span><span class="identifier">Geometry1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">geometry1</span><span class="special">,</span> <span class="identifier">Geometry2</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">geometry2</span><span class="special">,</span> <span class="identifier">Collection</span> <span class="special">&amp;</span> <span class="identifier">output_collection</span><span class="special">,</span>
52                 <span class="identifier">Strategy</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">strategy</span><span class="special">)</span></pre>
53 <p>
54           </p>
55 <h6>
56 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h2"></a>
57             <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.parameters"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.parameters">Parameters</a>
58           </h6>
59 <div class="informaltable"><table class="table">
60 <colgroup>
61 <col>
62 <col>
63 <col>
64 <col>
65 </colgroup>
66 <thead><tr>
67 <th>
68                     <p>
69                       Type
70                     </p>
71                   </th>
72 <th>
73                     <p>
74                       Concept
75                     </p>
76                   </th>
77 <th>
78                     <p>
79                       Name
80                     </p>
81                   </th>
82 <th>
83                     <p>
84                       Description
85                     </p>
86                   </th>
87 </tr></thead>
88 <tbody>
89 <tr>
90 <td>
91                     <p>
92                       Geometry1 const &amp;
93                     </p>
94                   </td>
95 <td>
96                     <p>
97                       Any type fulfilling a Geometry Concept
98                     </p>
99                   </td>
100 <td>
101                     <p>
102                       geometry1
103                     </p>
104                   </td>
105 <td>
106                     <p>
107                       A model of the specified concept
108                     </p>
109                   </td>
110 </tr>
111 <tr>
112 <td>
113                     <p>
114                       Geometry2 const &amp;
115                     </p>
116                   </td>
117 <td>
118                     <p>
119                       Any type fulfilling a Geometry Concept
120                     </p>
121                   </td>
122 <td>
123                     <p>
124                       geometry2
125                     </p>
126                   </td>
127 <td>
128                     <p>
129                       A model of the specified concept
130                     </p>
131                   </td>
132 </tr>
133 <tr>
134 <td>
135                     <p>
136                       Collection &amp;
137                     </p>
138                   </td>
139 <td>
140                     <p>
141                       output collection, either a multi-geometry, or a std::vector&lt;Geometry&gt;
142                       / std::deque&lt;Geometry&gt; etc
143                     </p>
144                   </td>
145 <td>
146                     <p>
147                       output_collection
148                     </p>
149                   </td>
150 <td>
151                     <p>
152                       the output collection
153                     </p>
154                   </td>
155 </tr>
156 <tr>
157 <td>
158                     <p>
159                       Strategy const &amp;
160                     </p>
161                   </td>
162 <td>
163                     <p>
164                       Any type fulfilling a Difference Strategy Concept
165                     </p>
166                   </td>
167 <td>
168                     <p>
169                       strategy
170                     </p>
171                   </td>
172 <td>
173                     <p>
174                       The strategy which will be used for difference calculations
175                     </p>
176                   </td>
177 </tr>
178 </tbody>
179 </table></div>
180 <h6>
181 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h3"></a>
182             <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.header"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.header">Header</a>
183           </h6>
184 <p>
185             Either
186           </p>
187 <p>
188             <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>
189           </p>
190 <p>
191             Or
192           </p>
193 <p>
194             <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">difference</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
195           </p>
196 <h6>
197 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h4"></a>
198             <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.conformance"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.conformance">Conformance</a>
199           </h6>
200 <p>
201             The function difference implements function Difference from the <a href="http://www.opengeospatial.org/standards/sfa" target="_top">OGC Simple Feature
202             Specification</a>.
203           </p>
204 <h6>
205 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h5"></a>
206             <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.behavior"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.behavior">Behavior</a>
207           </h6>
208 <div class="informaltable"><table class="table">
209 <colgroup>
210 <col>
211 <col>
212 </colgroup>
213 <thead><tr>
214 <th>
215                     <p>
216                       Case
217                     </p>
218                   </th>
219 <th>
220                     <p>
221                       Behavior
222                     </p>
223                   </th>
224 </tr></thead>
225 <tbody>
226 <tr>
227 <td>
228                     <p>
229                       areal (e.g. polygon)
230                     </p>
231                   </td>
232 <td>
233                     <p>
234                       All combinations of: box, ring, polygon, multi_polygon
235                     </p>
236                   </td>
237 </tr>
238 <tr>
239 <td>
240                     <p>
241                       linear (e.g. linestring) / areal (e.g. polygon)
242                     </p>
243                   </td>
244 <td>
245                     <p>
246                       A combinations of a (multi) linestring with a (multi) polygon
247                       results in a collection of linestrings
248                     </p>
249                   </td>
250 </tr>
251 <tr>
252 <td>
253                     <p>
254                       linear (e.g. linestring)
255                     </p>
256                   </td>
257 <td>
258                     <p>
259                       All combinations of: linestring, multi_linestring; results
260                       in a collection of linestrings
261                     </p>
262                   </td>
263 </tr>
264 <tr>
265 <td>
266                     <p>
267                       pointlike (e.g. point)
268                     </p>
269                   </td>
270 <td>
271                     <p>
272                       All combinations of: point, multi_point; results in a collection
273                       of points
274                     </p>
275                   </td>
276 </tr>
277 <tr>
278 <td>
279                     <p>
280                       Other geometries
281                     </p>
282                   </td>
283 <td>
284                     <p>
285                       Not yet supported in this version
286                     </p>
287                   </td>
288 </tr>
289 <tr>
290 <td>
291                     <p>
292                       Spherical
293                     </p>
294                   </td>
295 <td>
296                     <p>
297                       Not yet supported in this version
298                     </p>
299                   </td>
300 </tr>
301 <tr>
302 <td>
303                     <p>
304                       Three dimensional
305                     </p>
306                   </td>
307 <td>
308                     <p>
309                       Not yet supported in this version
310                     </p>
311                   </td>
312 </tr>
313 </tbody>
314 </table></div>
315 <div class="note"><table border="0" summary="Note">
316 <tr>
317 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td>
318 <th align="left">Note</th>
319 </tr>
320 <tr><td align="left" valign="top"><p>
321               Check the <a class="link" href="../../concepts/concept_polygon.html" title="Polygon Concept">Polygon
322               Concept</a> for the rules that polygon input for this algorithm
323               should fulfill
324             </p></td></tr>
325 </table></div>
326 <h6>
327 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h6"></a>
328             <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.example"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.example">Example</a>
329           </h6>
330 <p>
331             Shows how to subtract one polygon from another polygon
332           </p>
333 <p>
334 </p>
335 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
336 <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">list</span><span class="special">&gt;</span>
337
338 <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>
339 <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>
340 <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">polygon</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
341
342 <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">foreach</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
343
344
345 <span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
346 <span class="special">{</span>
347     <span class="keyword">typedef</span> <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><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">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="special">&gt;</span> <span class="identifier">polygon</span><span class="special">;</span>
348
349     <span class="identifier">polygon</span> <span class="identifier">green</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">;</span>
350
351     <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>
352         <span class="string">"POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"</span>
353             <span class="string">"(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))"</span><span class="special">,</span> <span class="identifier">green</span><span class="special">);</span>
354
355     <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>
356         <span class="string">"POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))"</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">);</span>
357
358     <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">polygon</span><span class="special">&gt;</span> <span class="identifier">output</span><span class="special">;</span>
359     <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">difference</span><span class="special">(</span><span class="identifier">green</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">,</span> <span class="identifier">output</span><span class="special">);</span>
360
361     <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
362     <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"green - blue:"</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>
363     <span class="identifier">BOOST_FOREACH</span><span class="special">(</span><span class="identifier">polygon</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">output</span><span class="special">)</span>
364     <span class="special">{</span>
365         <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">i</span><span class="special">++</span> <span class="special">&lt;&lt;</span> <span class="string">": "</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">area</span><span class="special">(</span><span class="identifier">p</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>
366     <span class="special">}</span>
367
368
369     <span class="identifier">output</span><span class="special">.</span><span class="identifier">clear</span><span class="special">();</span>
370     <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">difference</span><span class="special">(</span><span class="identifier">blue</span><span class="special">,</span> <span class="identifier">green</span><span class="special">,</span> <span class="identifier">output</span><span class="special">);</span>
371
372     <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
373     <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"blue - green:"</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>
374     <span class="identifier">BOOST_FOREACH</span><span class="special">(</span><span class="identifier">polygon</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">output</span><span class="special">)</span>
375     <span class="special">{</span>
376         <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">i</span><span class="special">++</span> <span class="special">&lt;&lt;</span> <span class="string">": "</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">area</span><span class="special">(</span><span class="identifier">p</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>
377     <span class="special">}</span>
378
379
380     <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
381 <span class="special">}</span>
382 </pre>
383 <p>
384           </p>
385 <p>
386             Output:
387           </p>
388 <pre class="programlisting">green - blue:
389 0: 0.02375
390 1: 0.542951
391 2: 0.0149697
392 3: 0.226855
393 4: 0.839424
394
395 <img src="../../../../img/algorithms/difference_a.png" alt="difference_a">
396
397 blue - green:
398 0: 0.525154
399 1: 0.015
400 2: 0.181136
401 3: 0.128798
402 4: 0.340083
403 5: 0.307778
404
405 <img src="../../../../img/algorithms/difference_b.png" alt="difference_b">
406 </pre>
407 <h6>
408 <a name="geometry.reference.algorithms.difference.difference_4_with_strategy.h7"></a>
409             <span class="phrase"><a name="geometry.reference.algorithms.difference.difference_4_with_strategy.see_also"></a></span><a class="link" href="difference_4_with_strategy.html#geometry.reference.algorithms.difference.difference_4_with_strategy.see_also">See
410             also</a>
411           </h6>
412 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
413 <li class="listitem">
414                 <a class="link" href="../sym_difference.html" title="sym_difference">sym_difference
415                 (symmetric difference)</a>
416               </li>
417 <li class="listitem">
418                 <a class="link" href="../intersection.html" title="intersection">intersection</a>
419               </li>
420 <li class="listitem">
421                 <a class="link" href="../union_.html" title="union_">union</a>
422               </li>
423 </ul></div>
424 </div>
425 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
426 <td align="left"></td>
427 <td align="right"><div class="copyright-footer">Copyright &#169; 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
428       Wulkiewicz, Oracle and/or its affiliates<p>
429         Distributed under the Boost Software License, Version 1.0. (See accompanying
430         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>)
431       </p>
432 </div></td>
433 </tr></table>
434 <hr>
435 <div class="spirit-nav">
436 <a accesskey="p" href="../difference.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../difference.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="difference_3.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
437 </div>
438 </body>
439 </html>