box_view

| Home | Libraries | People | FAQ | More

#### box_view

Makes a box behave like a ring or a range.

###### Description

Adapts a box to the Boost.Range concept, enabling the user to iterating box corners. The box_view is registered as a Ring Concept

###### Model of

Ring Concept

###### Synopsis

    template<typename Box, bool Clockwise>
    struct box_view
          : public detail::points_view< geometry::point_type< Box >::type, 5 >
    {
      // ...
    };

###### Template parameter(s)

Parameter | Default | Description
--- | --- | ---
typename Box |  | A type fulfilling the Box Concept
bool Clockwise | true | If true, walks in clockwise direction, otherwise it walks in counterclockwise direction

###### Constructor(s)

Function | Description | Parameters
--- | --- | ---

    box_view(Box const & box)

Constructor accepting the box to adapt.

Box const &: box:

###### Header

Either

`#include <boost/geometry.hpp>`

Or

`#include <boost/geometry/views/box_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::box
            <
                boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
            > box_type;

        // Define the Boost.Range compatible type:
        typedef boost::geometry::box_view<box_type> box_view;

        box_type box;
        boost::geometry::assign_values(box, 0, 0, 4, 4);

        box_view view(box);

        // Iterating in clockwise direction over the points of this box
        for (boost::range_iterator<box_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 box_view is tagged as a ring, so supports area etc.
        std::cout << "Area: " << boost::geometry::area(view) << std::endl;

        return 0;
    }

Output:

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