...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The Polygon Concept describes the requirements for a polygon type. All algorithms in Boost.Geometry will check any geometry arguments against the concept requirements.
A polygon is A polygon is a planar surface defined by one exterior boundary and zero or more interior boundaries (OGC Simple Feature Specification).
So the definition of a Boost.Geometry polygon differs a bit from e.g. Wiki, where a polygon does not have holes. A polygon of Boost.Geometry is a polygon with or without holes. (A polygon without holes is a helper geometry within Boost.Geometry, and referred to as a ring.)
The Polygon Concept is defined as following:
traits::tag
defining polygon_tag
as type
traits::ring_mutable_type
defining the mutable types of its exterior and interior rings as type
traits::ring_const_type
defining the constant types of its exterior and interior rings as type
traits::ring_mutable_type
and traits::ring_const_type
must fulfill the
Ring Concept
traits::interior_mutable_type
defining the mutable type of the collection of its interior rings as
type;
traits::interior_const_type
defining the constant type of the collection of its interior rings
as type; each of these collections itself must fulfill a Boost.Range
Random Access Range Concept
traits::exterior_ring
with two functions named get
,
returning the exterior ring, one being const, the other being non const
traits::interior_rings
with two functions named get
,
returning the interior rings, one being const, the other being non
const
Besides the Concepts, which are checks on compile-time, there are some other rules that valid polygons must fulfill. This follows the opengeospatial rules (see link above).
ring_type
is defined as clockwise, the exterior ring must have the clockwise
orientation, and any interior ring must be reversed w.r.t. the defined
orientation (so: counter clockwise for clockwise exterior rings). If
the ring_type
is defined
counter clockwise, it is vice versa.
ring_type
is defined as closed, all rings must be closed: the first point must
be spatially equal to the last point.
The algorithms such as intersection, area, centroid, union, etc. do not check validity. There will be an algorithm is_valid which checks for validity against these rules, at runtime, and which can be called (by the library user) before.
If the input is invalid, the output might be invalid too. For example: if a polygon which should be closed is not closed, the area will be incorrect.
#include
boost/geometry/geometries/adapted/boost_polygon/polygon.hpp>
)