...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
A ring (aka linear ring) is a closed line which should not be selfintersecting.
template<typename Point, bool ClockWise, bool Closed, template< typename, typename > class Container, template< typename > class Allocator> class model::ring : public std::vector< Point, std::allocator< Point > > { // ... };
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 Container |
std::vector |
container type, for example std::vector, std::deque |
template< typename > class Allocator |
std::allocator |
container-allocator-type |
Function |
Description |
Parameters |
---|---|---|
ring()
|
Default constructor, creating an empty ring. |
|
template<typename Iterator> ring(Iterator begin, Iterator end)
|
Constructor with begin and end, filling the ring. |
Iterator: begin: Iterator: end: |
ring(std::initializer_list< Point > l)
|
Constructor taking std::initializer_list, filling the ring. |
std::initializer_list< Point >: l: |
Either
#include <boost/geometry/geometries/geometries.hpp>
Or
#include <boost/geometry/geometries/ring.hpp>
Declaration and use of the Boost.Geometry model::ring, modelling the Ring 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::ring<point_t> ring_t; ring_t ring1; ring_t ring2{{0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0}}; bg::append(ring1, point_t(0.0, 0.0)); bg::append(ring1, point_t(0.0, 5.0)); bg::append(ring1, point_t(5.0, 5.0)); bg::append(ring1, point_t(5.0, 0.0)); bg::append(ring1, point_t(0.0, 0.0)); double a = bg::area(ring1); std::cout << a << std::endl; return 0; }
Default parameters, clockwise, closed ring. |
|
Default-construct a ring. |
|
Construct a ring containing four points plus one closing point, using C++11 unified initialization syntax. |
|
Append point. |
Output:
25