91 lines
2.8 KiB
HTML
91 lines
2.8 KiB
HTML
|
<html>
|
|||
|
|
|||
|
<head>
|
|||
|
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
|||
|
<title>Point Usage</title>
|
|||
|
</head>
|
|||
|
|
|||
|
<body>
|
|||
|
|
|||
|
<p><font face="Courier New">/*<br>
|
|||
|
Copyright 2008 Intel Corporation<br>
|
|||
|
<br>
|
|||
|
Use, modification and distribution are subject to the Boost Software License,<br>
|
|||
|
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at<br>
|
|||
|
http://www.boost.org/LICENSE_1_0.txt).<br>
|
|||
|
*/<br>
|
|||
|
#include <boost/polygon/polygon.hpp><br>
|
|||
|
#include <cassert><br>
|
|||
|
namespace gtl = boost::polygon;<br>
|
|||
|
using namespace boost::polygon::operators;<br><br>
|
|||
|
int main() {<br>
|
|||
|
//constructing a gtl point<br>
|
|||
|
typedef gtl::point_data<int> Point;<br>
|
|||
|
int x = 10;<br>
|
|||
|
int y = 20;<br>
|
|||
|
Point pt(x, y);<br>
|
|||
|
assert(gtl::x(pt) == 10);<br>
|
|||
|
assert(gtl::y(pt) == 20);<br>
|
|||
|
<br>
|
|||
|
//a quick primer in isotropic point access<br>
|
|||
|
typedef gtl::orientation_2d O;<br>
|
|||
|
using gtl::HORIZONTAL;<br>
|
|||
|
using gtl::VERTICAL;<br>
|
|||
|
O o = HORIZONTAL;<br>
|
|||
|
assert(gtl::x(pt) == gtl::get(pt, o));<br>
|
|||
|
<br>
|
|||
|
o = o.get_perpendicular();<br>
|
|||
|
assert(o == VERTICAL);<br>
|
|||
|
assert(gtl::y(pt) == gtl::get(pt, o));<br>
|
|||
|
<br>
|
|||
|
gtl::set(pt, o, 30);<br>
|
|||
|
assert(gtl::y(pt) == 30);<br>
|
|||
|
<br>
|
|||
|
//using some of the library functions<br>
|
|||
|
Point pt2(10, 30);<br>
|
|||
|
assert(gtl::equivalence(pt, pt2));<br>
|
|||
|
<br>
|
|||
|
gtl::transformation<int> tr(gtl::axis_transformation::SWAP_XY);<br>
|
|||
|
gtl::transform(pt, tr);<br>
|
|||
|
assert(gtl::equivalence(pt, Point(30, 10)));<br>
|
|||
|
<br>
|
|||
|
gtl::transformation<int> tr2 = tr.inverse();<br>
|
|||
|
assert(tr == tr2); //SWAP_XY is its own inverse transform<br>
|
|||
|
<br>
|
|||
|
gtl::transform(pt, tr2);<br>
|
|||
|
assert(gtl::equivalence(pt, pt2)); //the two points are equal again<br>
|
|||
|
<br>
|
|||
|
gtl::move(pt, o, 10); //move pt 10 units in y<br>
|
|||
|
assert(gtl::euclidean_distance(pt, pt2) == 10.0f);<br>
|
|||
|
<br>
|
|||
|
gtl::move(pt, o.get_perpendicular(), 10); //move pt 10 units in x<br>
|
|||
|
assert(gtl::manhattan_distance(pt, pt2) == 20);<br>
|
|||
|
<br>
|
|||
|
return 0;<br>
|
|||
|
}<br>
|
|||
|
</font></p>
|
|||
|
|
|||
|
|
|||
|
<table class="docinfo" rules="none" frame="void" id="table1">
|
|||
|
<colgroup>
|
|||
|
<col class="docinfo-name"><col class="docinfo-content">
|
|||
|
</colgroup>
|
|||
|
<tbody vAlign="top">
|
|||
|
<tr>
|
|||
|
<th class="docinfo-name">Copyright:</th>
|
|||
|
<td>Copyright <20> Intel Corporation 2008-2010.</td>
|
|||
|
</tr>
|
|||
|
<tr class="field">
|
|||
|
<th class="docinfo-name">License:</th>
|
|||
|
<td class="field-body">Distributed under the Boost Software License,
|
|||
|
Version 1.0. (See accompanying file <tt class="literal">
|
|||
|
<span class="pre">LICENSE_1_0.txt</span></tt> or copy at
|
|||
|
<a class="reference" target="_top" href="http://www.boost.org/LICENSE_1_0.txt">
|
|||
|
http://www.boost.org/LICENSE_1_0.txt</a>)</td>
|
|||
|
</tr>
|
|||
|
</table>
|
|||
|
|
|||
|
</body>
|
|||
|
|
|||
|
</html>
|