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

PrevUpHomeNext

model::ring

A ring (aka linear ring) is a closed line which should not be selfintersecting.

Model of

Ring Concept

Synopsis

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 > >
{
  // ...
};

Template parameter(s)

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

Constructor(s)

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:

Header

Either

#include <boost/geometry/geometries/geometries.hpp>

Or

#include <boost/geometry/geometries/ring.hpp>

Examples

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; 1

    ring_t ring1; 2
    ring_t ring2{{0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0}}; 3

    bg::append(ring1, point_t(0.0, 0.0)); 4
    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;
}

1

Default parameters, clockwise, closed ring.

2

Default-construct a ring.

3

Construct a ring containing four points plus one closing point, using C++11 unified initialization syntax.

4

Append point.

Output:

25

PrevUpHomeNext