indexed.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2014-2015 Samuel Debionne, Grenoble, France.
  6. // This file was modified by Oracle on 2015, 2016, 2017, 2018.
  7. // Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  9. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  10. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  11. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  12. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  13. // Distributed under the Boost Software License, Version 1.0.
  14. // (See accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt)
  16. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_INDEXED_HPP
  17. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_INDEXED_HPP
  18. #include <cstddef>
  19. #include <functional>
  20. #include <boost/geometry/core/access.hpp>
  21. #include <boost/geometry/core/tags.hpp>
  22. #include <boost/geometry/util/select_coordinate_type.hpp>
  23. #include <boost/geometry/algorithms/dispatch/expand.hpp>
  24. namespace boost { namespace geometry
  25. {
  26. #ifndef DOXYGEN_NO_DETAIL
  27. namespace detail { namespace expand
  28. {
  29. template
  30. <
  31. std::size_t Index,
  32. std::size_t Dimension, std::size_t DimensionCount
  33. >
  34. struct indexed_loop
  35. {
  36. template <typename Box, typename Geometry>
  37. static inline void apply(Box& box, Geometry const& source)
  38. {
  39. typedef typename select_coordinate_type
  40. <
  41. Box,
  42. Geometry
  43. >::type coordinate_type;
  44. coordinate_type const coord = get<Index, Dimension>(source);
  45. std::less<coordinate_type> less;
  46. std::greater<coordinate_type> greater;
  47. if (less(coord, get<min_corner, Dimension>(box)))
  48. {
  49. set<min_corner, Dimension>(box, coord);
  50. }
  51. if (greater(coord, get<max_corner, Dimension>(box)))
  52. {
  53. set<max_corner, Dimension>(box, coord);
  54. }
  55. indexed_loop
  56. <
  57. Index, Dimension + 1, DimensionCount
  58. >::apply(box, source);
  59. }
  60. };
  61. template <std::size_t Index, std::size_t DimensionCount>
  62. struct indexed_loop
  63. <
  64. Index, DimensionCount, DimensionCount
  65. >
  66. {
  67. template <typename Box, typename Geometry>
  68. static inline void apply(Box&, Geometry const&) {}
  69. };
  70. // Changes a box such that the other box is also contained by the box
  71. template <std::size_t Dimension, std::size_t DimensionCount>
  72. struct expand_indexed
  73. {
  74. template <typename Box, typename Geometry>
  75. static inline void apply(Box& box, Geometry const& geometry)
  76. {
  77. indexed_loop
  78. <
  79. 0, Dimension, DimensionCount
  80. >::apply(box, geometry);
  81. indexed_loop
  82. <
  83. 1, Dimension, DimensionCount
  84. >::apply(box, geometry);
  85. }
  86. };
  87. }} // namespace detail::expand
  88. #endif // DOXYGEN_NO_DETAIL
  89. }} // namespace boost::geometry
  90. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_INDEXED_HPP