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 the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

segment_view

Makes a segment behave like a linestring or a range.

Description

Adapts a segment to the Boost.Range concept, enabling the user to iterate the two segment points. The segment_view is registered as a LineString Concept

Model of

LineString Concept

Synopsis

template<typename Segment>
struct segment_view
{
  // ...
};

Template parameter(s)

Parameter

Description

typename Segment

A type fulfilling the Segment Concept

Constructor(s)

Function

Description

Parameters

segment_view(Segment const & segment)

Constructor accepting the segment to adapt.

Segment const &: segment:

Header

Either

#include <boost/geometry/geometry.hpp>

Or

#include <boost/geometry/views/segment_view.hpp>

Complexity

Compile time

Example

Shows usage of the Boost.Range compatible view on a box

#include <iostream>

#include <boost/geometry.hpp>


int main()
{
    typedef boost::geometry::model::segment
        <
            boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
        > segment_type;

    typedef boost::geometry::segment_view<segment_type> segment_view;

    segment_type segment;
    boost::geometry::assign_values(segment, 0, 0, 1, 1);

    segment_view view(segment);

    // Iterating over the points of this segment
    for (boost::range_iterator<segment_view const>::type it = boost::begin(view);
        it != boost::end(view); ++it)
    {
        std::cout << " " << boost::geometry::dsv(*it);
    }
    std::cout << std::endl;

    // Note that a segment_view is tagged as a linestring, so supports length etc.
    std::cout << "Length: " << boost::geometry::length(view) << std::endl;

    return 0;
}

Output:

(0, 0) (0, 4) (4, 4) (4, 0) (0, 0)
Area: 16

PrevUpHomeNext