Boost
C++ Libraries
...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
This is an older version of Boost and was released in 2024. The current version is 1.89.0.
The polygon contains an outer ring and zero or more inner rings.
template<typename Point, bool ClockWise, bool Closed, template< typename, typename > class PointList, template< typename, typename > class RingList, template< typename > class PointAlloc, template< typename > class RingAlloc> class model::polygon { // ... };
|
Parameter |
Default |
Description |
|---|---|---|
|
typename Point |
point type |
|
|
bool ClockWise |
true |
true for clockwise direction, false for CounterClockWise direction |
|
bool Closed |
true |
true for closed polygons (last point == first point), false open points |
|
template< typename, typename > class PointList |
std::vector |
container type for points, for example std::vector, std::deque |
|
template< typename, typename > class RingList |
std::vector |
container type for inner rings, for example std::vector, std::deque |
|
template< typename > class PointAlloc |
std::allocator |
container-allocator-type, for the points |
|
template< typename > class RingAlloc |
std::allocator |
container-allocator-type, for the rings |
|
Function |
Description |
Parameters |
|---|---|---|
|
polygon()
|
Default constructor, creating an empty polygon. |
|
|
polygon(std::initializer_list< ring_type > l)
|
Constructor taking std::initializer_list, filling the polygon. |
std::initializer_list< ring_type >: l: |
|
Function |
Description |
Parameters |
Returns |
|---|---|---|---|
|
ring_type const & outer()
|
|||
|
inner_container_type const & inners()
|
|||
|
ring_type & outer()
|
|||
|
inner_container_type & inners()
|
|||
|
void clear()
|
Utility method, clears outer and inner rings. |
Either
#include <boost/geometry/geometries/geometries.hpp>
Or
#include <boost/geometry/geometries/polygon.hpp>
Declaration and use of the Boost.Geometry model::polygon, modelling the Polygon Concept
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::polygon<point_t> polygon_t;polygon_t poly1;
polygon_t polygon2{{{0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0}}, {{1.0, 1.0}, {4.0, 1.0}, {4.0, 4.0}, {1.0, 4.0}, {1.0, 1.0}}};
bg::append(poly1.outer(), point_t(0.0, 0.0));
bg::append(poly1.outer(), point_t(0.0, 5.0)); bg::append(poly1.outer(), point_t(5.0, 5.0)); bg::append(poly1.outer(), point_t(5.0, 0.0)); bg::append(poly1.outer(), point_t(0.0, 0.0)); poly1.inners().resize(1);
bg::append(poly1.inners()[0], point_t(1.0, 1.0));
bg::append(poly1.inners()[0], point_t(4.0, 1.0)); bg::append(poly1.inners()[0], point_t(4.0, 4.0)); bg::append(poly1.inners()[0], point_t(1.0, 4.0)); bg::append(poly1.inners()[0], point_t(1.0, 1.0)); double a = bg::area(poly1); std::cout << a << std::endl; return 0; }
Default parameters, clockwise, closed polygon. |
|
Default-construct a polygon. |
|
Construct a polygon containing an exterior and interior ring, using C++11 unified initialization syntax. |
|
Append point to the exterior ring. |
|
Resize a container of interior rings. |
|
Append point to the interior ring. |
Output:
16