box_view.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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-2021.
  6. // Modifications copyright (c) 2020-2021 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 <array>
  16. #include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
  17. #include <boost/geometry/core/point_order.hpp>
  18. #include <boost/geometry/core/point_type.hpp>
  19. #include <boost/geometry/core/tag.hpp>
  20. namespace boost { namespace geometry
  21. {
  22. // NOTE: This is equivalent to the previous implementation with detail::points_view.
  23. // Technically this should not be called a view because it owns the elements.
  24. // It's also not a borrowed_range because of dangling iterators after the
  25. // destruction.
  26. // It's a container or more specifically a ring of some sort, e.g. static_ring.
  27. // NOTE: It would be possible to implement a borrowed_range or a view.
  28. // The iterators would have to store copies of points.
  29. // Another possibility is to store the original Box or reference/pointer
  30. // to Box and index. But then the reference would be the value type
  31. // so technically they would be InputIterators not RandomAccessIterators.
  32. // NOTE: This object can not represent a Box correctly in all coordinates systems.
  33. // It's correct only in cartesian CS so maybe it should be removed entirely.
  34. /*!
  35. \brief Makes a box behave like a ring or a range
  36. \details Adapts a box to the Boost.Range concept, enabling the user to iterating
  37. box corners. The box_view is registered as a Ring Concept
  38. \tparam Box \tparam_geometry{Box}
  39. \tparam Clockwise If true, walks in clockwise direction, otherwise
  40. it walks in counterclockwise direction
  41. \ingroup views
  42. \qbk{before.synopsis,
  43. [heading Model of]
  44. [link geometry.reference.concepts.concept_ring Ring Concept]
  45. }
  46. \qbk{[include reference/views/box_view.qbk]}
  47. */
  48. template <typename Box, bool Clockwise = true>
  49. struct box_view
  50. {
  51. using array_t = std::array<typename geometry::point_type<Box>::type, 5>;
  52. using iterator = typename array_t::const_iterator;
  53. using const_iterator = typename array_t::const_iterator;
  54. /// Constructor accepting the box to adapt
  55. explicit box_view(Box const& box)
  56. {
  57. detail::assign_box_corners_oriented<!Clockwise>(box, m_array);
  58. m_array[4] = m_array[0];
  59. }
  60. const_iterator begin() const noexcept { return m_array.begin(); }
  61. const_iterator end() const noexcept { return m_array.end(); }
  62. private:
  63. array_t m_array;
  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