range.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. // This file was modified by Oracle on 2015, 2016, 2018.
  6. // Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Distributed under the Boost Software License, Version 1.0.
  13. // (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP
  17. #include <iterator>
  18. #include <vector>
  19. #include <boost/range/begin.hpp>
  20. #include <boost/range/end.hpp>
  21. #include <boost/geometry/algorithms/is_empty.hpp>
  22. #include <boost/geometry/algorithms/detail/envelope/initialize.hpp>
  23. #include <boost/geometry/algorithms/detail/expand/box.hpp>
  24. #include <boost/geometry/algorithms/detail/expand/point.hpp>
  25. #include <boost/geometry/algorithms/detail/expand/segment.hpp>
  26. #include <boost/geometry/core/coordinate_dimension.hpp>
  27. namespace boost { namespace geometry
  28. {
  29. #ifndef DOXYGEN_NO_DETAIL
  30. namespace detail { namespace envelope
  31. {
  32. // implementation for simple ranges
  33. struct envelope_range
  34. {
  35. template <typename Iterator, typename Box, typename Strategy>
  36. static inline void apply(Iterator it,
  37. Iterator last,
  38. Box& mbr,
  39. Strategy const& strategy)
  40. {
  41. typedef typename std::iterator_traits<Iterator>::value_type value_type;
  42. // initialize MBR
  43. initialize<Box, 0, dimension<Box>::value>::apply(mbr);
  44. if (it != last)
  45. {
  46. // initialize box with first element in range
  47. dispatch::envelope
  48. <
  49. value_type
  50. >::apply(*it, mbr, strategy.get_element_envelope_strategy());
  51. // consider now the remaining elements in the range (if any)
  52. for (++it; it != last; ++it)
  53. {
  54. dispatch::expand
  55. <
  56. Box, value_type
  57. >::apply(mbr, *it, strategy.get_element_expand_strategy());
  58. }
  59. }
  60. }
  61. template <typename Range, typename Box, typename Strategy>
  62. static inline void apply(Range const& range, Box& mbr, Strategy const& strategy)
  63. {
  64. return apply(Strategy::begin(range), Strategy::end(range), mbr, strategy);
  65. }
  66. };
  67. // implementation for multi-ranges
  68. template <typename EnvelopePolicy>
  69. struct envelope_multi_range
  70. {
  71. template <typename MultiRange, typename Box, typename Strategy>
  72. static inline void apply(MultiRange const& multirange,
  73. Box& mbr,
  74. Strategy const& strategy)
  75. {
  76. apply(boost::begin(multirange), boost::end(multirange), mbr, strategy);
  77. }
  78. template <typename Iter, typename Box, typename Strategy>
  79. static inline void apply(Iter it,
  80. Iter last,
  81. Box& mbr,
  82. Strategy const& strategy)
  83. {
  84. typename Strategy::template multi_state<Box> state;
  85. for (; it != last; ++it)
  86. {
  87. if (! geometry::is_empty(*it))
  88. {
  89. Box helper_mbr;
  90. EnvelopePolicy::apply(*it, helper_mbr, strategy);
  91. state.apply(helper_mbr);
  92. }
  93. }
  94. state.result(mbr);
  95. }
  96. };
  97. }} // namespace detail::envelope
  98. #endif // DOXYGEN_NO_DETAIL
  99. }} // namespace boost::geometry
  100. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_RANGE_HPP