...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Makes a segment behave like a linestring or a range.
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
template<typename Segment> struct segment_view { // ... };
Parameter |
Description |
---|---|
typename Segment |
A type fulfilling the Segment Concept |
Function |
Description |
Parameters |
---|---|---|
segment_view(Segment const & segment)
|
Constructor accepting the segment to adapt. |
Segment const &: segment: |
Function |
Description |
Parameters |
Returns |
---|---|---|---|
const_iterator begin()
|
|||
const_iterator end()
|
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/views/segment_view.hpp>
Compile time
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) (1, 1) Length: 1.41421