Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@16
|
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
Chris@16
|
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
Chris@16
|
6
|
Chris@16
|
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
9
|
Chris@16
|
10 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
12 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
13
|
Chris@16
|
14 #ifndef BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP
|
Chris@16
|
15 #define BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP
|
Chris@16
|
16
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/range.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #include <boost/geometry/core/point_type.hpp>
|
Chris@16
|
21 #include <boost/geometry/views/detail/points_view.hpp>
|
Chris@16
|
22 #include <boost/geometry/algorithms/assign.hpp>
|
Chris@16
|
23
|
Chris@16
|
24
|
Chris@16
|
25 namespace boost { namespace geometry
|
Chris@16
|
26 {
|
Chris@16
|
27
|
Chris@16
|
28
|
Chris@16
|
29 /*!
|
Chris@16
|
30 \brief Makes a box behave like a ring or a range
|
Chris@16
|
31 \details Adapts a box to the Boost.Range concept, enabling the user to iterating
|
Chris@16
|
32 box corners. The box_view is registered as a Ring Concept
|
Chris@16
|
33 \tparam Box \tparam_geometry{Box}
|
Chris@16
|
34 \tparam Clockwise If true, walks in clockwise direction, otherwise
|
Chris@16
|
35 it walks in counterclockwise direction
|
Chris@16
|
36 \ingroup views
|
Chris@16
|
37
|
Chris@16
|
38 \qbk{before.synopsis,
|
Chris@16
|
39 [heading Model of]
|
Chris@16
|
40 [link geometry.reference.concepts.concept_ring Ring Concept]
|
Chris@16
|
41 }
|
Chris@16
|
42
|
Chris@16
|
43 \qbk{[include reference/views/box_view.qbk]}
|
Chris@16
|
44 */
|
Chris@16
|
45 template <typename Box, bool Clockwise = true>
|
Chris@101
|
46 struct box_view
|
Chris@16
|
47 : public detail::points_view
|
Chris@16
|
48 <
|
Chris@101
|
49 typename geometry::point_type<Box>::type,
|
Chris@16
|
50 5
|
Chris@16
|
51 >
|
Chris@16
|
52 {
|
Chris@16
|
53 typedef typename geometry::point_type<Box>::type point_type;
|
Chris@101
|
54
|
Chris@16
|
55 /// Constructor accepting the box to adapt
|
Chris@16
|
56 explicit box_view(Box const& box)
|
Chris@16
|
57 : detail::points_view<point_type, 5>(copy_policy(box))
|
Chris@16
|
58 {}
|
Chris@101
|
59
|
Chris@101
|
60 private :
|
Chris@101
|
61
|
Chris@16
|
62 class copy_policy
|
Chris@16
|
63 {
|
Chris@16
|
64 public :
|
Chris@16
|
65 inline copy_policy(Box const& box)
|
Chris@16
|
66 : m_box(box)
|
Chris@16
|
67 {}
|
Chris@101
|
68
|
Chris@16
|
69 inline void apply(point_type* points) const
|
Chris@16
|
70 {
|
Chris@101
|
71 // assign_box_corners_oriented requires a range
|
Chris@101
|
72 // an alternative for this workaround would be to pass a range here,
|
Chris@101
|
73 // e.g. use boost::array in points_view instead of c-array
|
Chris@101
|
74 std::pair<point_type*, point_type*> rng = std::make_pair(points, points + 5);
|
Chris@101
|
75 detail::assign_box_corners_oriented<!Clockwise>(m_box, rng);
|
Chris@16
|
76 points[4] = points[0];
|
Chris@16
|
77 }
|
Chris@16
|
78 private :
|
Chris@16
|
79 Box const& m_box;
|
Chris@16
|
80 };
|
Chris@16
|
81
|
Chris@16
|
82 };
|
Chris@16
|
83
|
Chris@16
|
84
|
Chris@16
|
85 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
|
Chris@16
|
86
|
Chris@16
|
87 // All views on boxes are handled as rings
|
Chris@16
|
88 namespace traits
|
Chris@16
|
89 {
|
Chris@16
|
90
|
Chris@16
|
91 template<typename Box, bool Clockwise>
|
Chris@16
|
92 struct tag<box_view<Box, Clockwise> >
|
Chris@16
|
93 {
|
Chris@16
|
94 typedef ring_tag type;
|
Chris@16
|
95 };
|
Chris@16
|
96
|
Chris@16
|
97 template<typename Box>
|
Chris@16
|
98 struct point_order<box_view<Box, false> >
|
Chris@16
|
99 {
|
Chris@16
|
100 static order_selector const value = counterclockwise;
|
Chris@16
|
101 };
|
Chris@16
|
102
|
Chris@16
|
103
|
Chris@16
|
104 template<typename Box>
|
Chris@16
|
105 struct point_order<box_view<Box, true> >
|
Chris@16
|
106 {
|
Chris@16
|
107 static order_selector const value = clockwise;
|
Chris@16
|
108 };
|
Chris@16
|
109
|
Chris@16
|
110 }
|
Chris@16
|
111
|
Chris@16
|
112 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
|
Chris@16
|
113
|
Chris@16
|
114
|
Chris@16
|
115 }} // namespace boost::geometry
|
Chris@16
|
116
|
Chris@16
|
117
|
Chris@16
|
118 #endif // BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP
|