1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP
15 #define BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP
18 #include <boost/range.hpp>
20 #include <boost/geometry/core/point_type.hpp>
21 #include <boost/geometry/views/detail/points_view.hpp>
22 #include <boost/geometry/algorithms/assign.hpp>
25 namespace boost { namespace geometry
30 \brief Makes a box behave like a ring or a range
31 \details Adapts a box to the Boost.Range concept, enabling the user to iterating
32 box corners. The box_view is registered as a Ring Concept
33 \tparam Box \tparam_geometry{Box}
34 \tparam Clockwise If true, walks in clockwise direction, otherwise
35 it walks in counterclockwise direction
40 [link geometry.reference.concepts.concept_ring Ring Concept]
43 \qbk{[include reference/views/box_view.qbk]}
45 template <typename Box, bool Clockwise = true>
47 : public detail::points_view
49 typename geometry::point_type<Box>::type,
53 typedef typename geometry::point_type<Box>::type point_type;
55 /// Constructor accepting the box to adapt
56 explicit box_view(Box const& box)
57 : detail::points_view<point_type, 5>(copy_policy(box))
65 inline copy_policy(Box const& box)
69 inline void apply(point_type* points) const
71 // assign_box_corners_oriented requires a range
72 // an alternative for this workaround would be to pass a range here,
73 // e.g. use boost::array in points_view instead of c-array
74 std::pair<point_type*, point_type*> rng = std::make_pair(points, points + 5);
75 detail::assign_box_corners_oriented<!Clockwise>(m_box, rng);
76 points[4] = points[0];
85 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
87 // All views on boxes are handled as rings
91 template<typename Box, bool Clockwise>
92 struct tag<box_view<Box, Clockwise> >
94 typedef ring_tag type;
97 template<typename Box>
98 struct point_order<box_view<Box, false> >
100 static order_selector const value = counterclockwise;
104 template<typename Box>
105 struct point_order<box_view<Box, true> >
107 static order_selector const value = clockwise;
112 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
115 }} // namespace boost::geometry
118 #endif // BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP