4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=windows-1252">
5 <title>Polygon Usage
</title>
10 <p><font face=
"Courier New">/*
<br>
11 Copyright
2008 Intel Corporation
<br>
13 Use, modification and distribution are subject to the Boost Software License,
<br>
14 Version
1.0. (See accompanying file LICENSE_1_0.txt or copy at
<br>
15 http://www.boost.org/LICENSE_1_0.txt).
<br>
17 #include
<boost/polygon/polygon.hpp
><br>
18 #include
<cassert
><br>
19 namespace gtl = boost::polygon;
<br>
20 using namespace boost::polygon::operators;
<br><br>
22 //lets construct a
10x10 rectangle shaped polygon
<br>
23 typedef gtl::polygon_data
<int
> Polygon;
<br>
24 typedef gtl::polygon_traits
<Polygon
>::point_type Point;
<br>
25 Point pts[] = {gtl::construct
<Point
>(
0,
0),
<br>
26 gtl::construct
<Point
>(
10,
0),
<br>
27 gtl::construct
<Point
>(
10,
10),
<br>
28 gtl::construct
<Point
>(
0,
10) };
<br>
29 Polygon poly;
<br>
30 gtl::set_points(poly, pts, pts+
4);
<br>
32 //now lets see what we can do with this polygon
<br>
33 assert(gtl::area(poly) ==
100.0f);
<br>
34 assert(gtl::contains(poly, gtl::construct
<Point
>(
5,
5)));
<br>
35 assert(!gtl::contains(poly, gtl::construct
<Point
>(
15,
5)));
<br>
36 gtl::rectangle_data
<int
> rect;
<br>
37 assert(gtl::extents(rect, poly)); //get bounding box of poly
<br>
38 assert(gtl::equivalence(rect, poly)); //hey, that's slick
<br>
39 assert(gtl::winding(poly) == gtl::COUNTERCLOCKWISE);
<br>
40 assert(gtl::perimeter(poly) ==
40.0f);
<br>
42 //add
5 to all coords of poly
<br>
43 gtl::convolve(poly, gtl::construct
<Point
>(
5,
5));
<br>
44 //multiply all coords of poly by
2<br>
45 gtl::scale_up(poly,
2);
<br>
46 gtl::set_points(rect, gtl::point_data
<int
>(
10,
10),
<br>
47 gtl::point_data
<int
>(
30,
30));
<br>
48 assert(gtl::equivalence(poly, rect));
<br>
49 return
0;
<br>
51 //Now you know how to use the built in polygon data type
<br>
55 <table class=
"docinfo" rules=
"none" frame=
"void" id=
"table1">
57 <col class=
"docinfo-name"><col class=
"docinfo-content">
61 <th class=
"docinfo-name">Copyright:
</th>
62 <td>Copyright © Intel Corporation
2008-
2010.
</td>
65 <th class=
"docinfo-name">License:
</th>
66 <td class=
"field-body">Distributed under the Boost Software License,
67 Version
1.0. (See accompanying file
<tt class=
"literal">
68 <span class=
"pre">LICENSE_1_0.txt
</span></tt> or copy at
69 <a class=
"reference" target=
"_top" href=
"http://www.boost.org/LICENSE_1_0.txt">
70 http://www.boost.org/LICENSE_1_0.txt
</a>)
</td>