mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-13 12:32:09 +00:00
168 lines
9.6 KiB
HTML
168 lines
9.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Boost.Geometry (aka GGL, Generic Geometry Library)</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
<link href="tabs.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
|
|
<table cellpadding="2" width="100%">
|
|
<tbody>
|
|
<tr>
|
|
<td valign="top">
|
|
<img alt="Boost.Geometry" src="images/ggl-logo-big.png" height="80" width="200">
|
|
|
|
</td>
|
|
<td valign="top" align="right">
|
|
<a href="http://www.boost.org">
|
|
<img alt="Boost C++ Libraries" src="images/accepted_by_boost.png" height="80" width="230" border="0">
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<!-- Generated by Doxygen 1.5.9 -->
|
|
<div class="navigation" id="top">
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li><a href="examples.html"><span>Examples</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="contents">
|
|
<h1>01_point_example.cpp</h1>In most cases the documentation gives small examples of how to use the algorithms or classes. The point example is a slightly larger example giving an idea of how to use different algorithms from the library, related to points. It shows<ul>
|
|
<li>the usage of include files</li><li>how to declare points, using different coordinate types</li><li>how to construct points, specifying coordinates, initializing to zero or to infinite</li><li>how to compare points to each other</li><li>how points can be streamed as OGC text</li><li>calculating the distance from point to point</li></ul>
|
|
<p>
|
|
<div class="fragment"><pre class="fragment"><span class="comment">// Boost.Geometry (aka GGL, Generic Geometry Library)</span>
|
|
<span class="comment">//</span>
|
|
<span class="comment">// Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands</span>
|
|
<span class="comment">// Copyright Bruno Lalande 2008, 2009</span>
|
|
<span class="comment">// Use, modification and distribution is subject to the Boost Software License,</span>
|
|
<span class="comment">// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
|
|
<span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span>
|
|
<span class="comment">//</span>
|
|
<span class="comment">// Point Example - showing different type of points</span>
|
|
|
|
<span class="preprocessor">#include <iostream></span>
|
|
|
|
<span class="preprocessor">#include <boost/geometry/geometry.hpp></span>
|
|
<span class="preprocessor">#include <<a class="code" href="tuple__cartesian_8hpp.html">boost/geometry/geometries/adapted/tuple_cartesian.hpp</a>></span>
|
|
<span class="preprocessor">#include <<a class="code" href="c__array__cartesian_8hpp.html">boost/geometry/geometries/adapted/c_array_cartesian.hpp</a>></span>
|
|
<span class="preprocessor">#include <<a class="code" href="cartesian2d_8hpp.html">boost/geometry/geometries/cartesian2d.hpp</a>></span>
|
|
|
|
|
|
<span class="keywordtype">int</span> main()
|
|
{
|
|
<span class="keyword">using namespace </span>boost::geometry;
|
|
|
|
<span class="comment">// GGL contains several point types:</span>
|
|
<span class="comment">// 1: it's own generic type</span>
|
|
<a name="_a0"></a><a class="code" href="classboost_1_1geometry_1_1point.html" title="Basic point class, having coordinates defined in a neutral way.">point<double, 2, cs::cartesian></a> pt1;
|
|
|
|
<span class="comment">// 2: it's own type targetted to Cartesian (x,y) coordinates</span>
|
|
<a name="_a1"></a><a class="code" href="classboost_1_1geometry_1_1point__xy.html" title="2D point in Cartesian coordinate system">point_2d</a> pt2;
|
|
|
|
<span class="comment">// 3: it supports Boost tuple's (by including the headerfile)</span>
|
|
boost::tuple<double, double> pt3;
|
|
|
|
<span class="comment">// 4: it supports normal arrays</span>
|
|
<span class="keywordtype">double</span> pt4[2];
|
|
|
|
<span class="comment">// 5: there are more variants, and you can create your own.</span>
|
|
<span class="comment">// (see therefore the custom_point example)</span>
|
|
|
|
<span class="comment">// All these types are handled the same way. We show here</span>
|
|
<span class="comment">// assigning them and calculating distances.</span>
|
|
<a name="a2"></a><a class="code" href="group__access.html#gd1a7d6277b95439021f13191094aebdb" title="assign two values to a 2D point">assign</a>(pt1, 1, 1);
|
|
<a class="code" href="group__access.html#gd1a7d6277b95439021f13191094aebdb" title="assign two values to a 2D point">assign</a>(pt2, 2, 2);
|
|
<a class="code" href="group__access.html#gd1a7d6277b95439021f13191094aebdb" title="assign two values to a 2D point">assign</a>(pt3, 3, 3);
|
|
<a class="code" href="group__access.html#gd1a7d6277b95439021f13191094aebdb" title="assign two values to a 2D point">assign</a>(pt4, 4, 4);
|
|
|
|
<span class="keywordtype">double</span> d1 = <a name="a3"></a><a class="code" href="group__distance.html#g8fb8022d64a75b24c80a64ba46ec4738" title="Calculate distance between two geometries with a specified strategy.">distance</a>(pt1, pt2);
|
|
<span class="keywordtype">double</span> d2 = <a class="code" href="group__distance.html#g8fb8022d64a75b24c80a64ba46ec4738" title="Calculate distance between two geometries with a specified strategy.">distance</a>(pt3, pt4);
|
|
std::cout << <span class="stringliteral">"Distances: "</span> << d1 << <span class="stringliteral">" and "</span> << d2 << std::endl;
|
|
|
|
<span class="comment">// (in case you didn't note, distances can be calculated</span>
|
|
<span class="comment">// from points with different point-types)</span>
|
|
|
|
|
|
<span class="comment">// Several ways of construction and setting point values</span>
|
|
<span class="comment">// 1: default, empty constructor, causing no initialization at all</span>
|
|
<a class="code" href="classboost_1_1geometry_1_1point__xy.html" title="2D point in Cartesian coordinate system">point_2d</a> p1;
|
|
|
|
<span class="comment">// 2: as shown above, assign</span>
|
|
<a class="code" href="classboost_1_1geometry_1_1point__xy.html" title="2D point in Cartesian coordinate system">point_2d</a> p2;
|
|
<a class="code" href="group__access.html#gd1a7d6277b95439021f13191094aebdb" title="assign two values to a 2D point">assign</a>(p2, 1, 1);
|
|
|
|
<span class="comment">// 3: using "set" function</span>
|
|
<span class="comment">// set uses the concepts behind, such that it can be applied for</span>
|
|
<span class="comment">// every point-type (like assign)</span>
|
|
<a class="code" href="classboost_1_1geometry_1_1point__xy.html" title="2D point in Cartesian coordinate system">point_2d</a> p3;
|
|
set<0>(p3, 1);
|
|
set<1>(p3, 1);
|
|
<span class="comment">// set<2>(p3, 1); //will result in compile-error</span>
|
|
|
|
|
|
<span class="comment">// 3: for any point type, and other geometry objects:</span>
|
|
<span class="comment">// there is the "make" object generator</span>
|
|
<span class="comment">// (this one requires to specify the point-type).</span>
|
|
<a class="code" href="classboost_1_1geometry_1_1point__xy.html" title="2D point in Cartesian coordinate system">point_2d</a> p4 = make<point_2d>(1,1);
|
|
|
|
|
|
<span class="comment">// 5: for the point_2d type only: constructor with two values</span>
|
|
<a class="code" href="classboost_1_1geometry_1_1point__xy.html" title="2D point in Cartesian coordinate system">point_2d</a> p5(1,1);
|
|
|
|
<span class="comment">// 6: for boost tuples you can of course use make_tuple</span>
|
|
|
|
|
|
<span class="comment">// Some ways of getting point values</span>
|
|
|
|
<span class="comment">// 1: using the "get" function following the concepts behind</span>
|
|
std::cout << get<0>(p2) << <span class="stringliteral">","</span> << get<1>(p2) << std::endl;
|
|
|
|
<span class="comment">// 2: for point-2d only</span>
|
|
std::cout << p2.<a name="a4"></a><a class="code" href="classboost_1_1geometry_1_1point__xy.html#cbe13eb956f6b54824c1f59f8f739e64" title="Get x-value.">x</a>() << <span class="stringliteral">","</span> << p2.<a name="a5"></a><a class="code" href="classboost_1_1geometry_1_1point__xy.html#d7e6488907fb2ff7adb1a57c38ea5f22" title="Get y-value.">y</a>() << std::endl;
|
|
|
|
<span class="comment">// 3: using boost-tuples you of course can boost-tuple-methods</span>
|
|
std::cout << pt3.get<0>() << <span class="stringliteral">","</span> << pt3.get<1>() << std::endl;
|
|
|
|
<span class="comment">// 4: GGL supports various output formats, e.g. DSV</span>
|
|
<span class="comment">// (delimiter separated values)</span>
|
|
std::cout << <a name="a6"></a><a class="code" href="group__utility.html#g62cc5db4d3bb1147591298b3500f8f1a" title="Main DSV-streaming function.">dsv</a>(pt3) << std::endl;
|
|
|
|
|
|
<span class="comment">// Other examples show other types of points, geometries and more algorithms</span>
|
|
|
|
<span class="keywordflow">return</span> 0;
|
|
}
|
|
</pre></div> </div>
|
|
<hr size="1">
|
|
<table width="100%">
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><small>
|
|
<p>December 1, 2009</p>
|
|
</small></td>
|
|
<td align="right">
|
|
<small>Copyright © 1995-2009 Barend Gehrels, Geodan, Amsterdam<br>
|
|
Copyright © 2008-2009 Bruno Lalande, Paris<br>
|
|
Copyright © 2009 Mateusz Loskot, Cadcorp, London<br>
|
|
</small>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<address style="text-align: right;"><small>
|
|
Documentation is generated by <a href="http://www.doxygen.org/index.html">Doxygen</a>
|
|
</small></address>
|
|
</body>
|
|
</html>
|