box_view.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. detail::assign_box_corners_oriented<!Clockwise>(m_box, points);
  55. points[4] = points[0];
  56. }
  57. private :
  58. Box const& m_box;
  59. };
  60. };
  61. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  62. // All views on boxes are handled as rings
  63. namespace traits
  64. {
  65. template<typename Box, bool Clockwise>
  66. struct tag<box_view<Box, Clockwise> >
  67. {
  68. typedef ring_tag type;
  69. };
  70. template<typename Box>
  71. struct point_order<box_view<Box, false> >
  72. {
  73. static order_selector const value = counterclockwise;
  74. };
  75. template<typename Box>
  76. struct point_order<box_view<Box, true> >
  77. {
  78. static order_selector const value = clockwise;
  79. };
  80. }
  81. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  82. }} // namespace boost::geometry
  83. #endif // BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP