box_view.hpp 3.0 KB

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