box_view.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. // This file was modified by Oracle on 2020.
  6. // Modifications copyright (c) 2020 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (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)
  13. #ifndef BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP
  14. #define BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP
  15. #include <boost/geometry/core/point_type.hpp>
  16. #include <boost/geometry/views/detail/points_view.hpp>
  17. #include <boost/geometry/algorithms/assign.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. /*!
  21. \brief Makes a box behave like a ring or a range
  22. \details Adapts a box to the Boost.Range concept, enabling the user to iterating
  23. box corners. The box_view is registered as a Ring Concept
  24. \tparam Box \tparam_geometry{Box}
  25. \tparam Clockwise If true, walks in clockwise direction, otherwise
  26. it walks in counterclockwise direction
  27. \ingroup views
  28. \qbk{before.synopsis,
  29. [heading Model of]
  30. [link geometry.reference.concepts.concept_ring Ring Concept]
  31. }
  32. \qbk{[include reference/views/box_view.qbk]}
  33. */
  34. template <typename Box, bool Clockwise = true>
  35. struct box_view
  36. : public detail::points_view
  37. <
  38. typename geometry::point_type<Box>::type,
  39. 5
  40. >
  41. {
  42. typedef typename geometry::point_type<Box>::type point_type;
  43. /// Constructor accepting the box to adapt
  44. explicit box_view(Box const& box)
  45. : detail::points_view<point_type, 5>(copy_policy(box))
  46. {}
  47. private :
  48. class copy_policy
  49. {
  50. public :
  51. inline copy_policy(Box const& box)
  52. : m_box(box)
  53. {}
  54. inline void apply(point_type* points) const
  55. {
  56. // assign_box_corners_oriented requires a range
  57. // an alternative for this workaround would be to pass a range here,
  58. // e.g. use boost::array in points_view instead of c-array
  59. std::pair<point_type*, point_type*> rng = std::make_pair(points, points + 5);
  60. detail::assign_box_corners_oriented<!Clockwise>(m_box, rng);
  61. points[4] = points[0];
  62. }
  63. private :
  64. Box const& m_box;
  65. };
  66. };
  67. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  68. // All views on boxes are handled as rings
  69. namespace traits
  70. {
  71. template<typename Box, bool Clockwise>
  72. struct tag<box_view<Box, Clockwise> >
  73. {
  74. typedef ring_tag type;
  75. };
  76. template<typename Box>
  77. struct point_order<box_view<Box, false> >
  78. {
  79. static order_selector const value = counterclockwise;
  80. };
  81. template<typename Box>
  82. struct point_order<box_view<Box, true> >
  83. {
  84. static order_selector const value = clockwise;
  85. };
  86. }
  87. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  88. }} // namespace boost::geometry
  89. #endif // BOOST_GEOMETRY_VIEWS_BOX_VIEW_HPP