box.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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-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. // Distributed under the Boost Software License, Version 1.0.
  11. // (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_BOX_HPP
  14. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_BOX_HPP
  15. #include <cstddef>
  16. #include <boost/geometry/core/cs.hpp>
  17. #include <boost/geometry/core/coordinate_dimension.hpp>
  18. #include <boost/geometry/core/coordinate_system.hpp>
  19. #include <boost/geometry/core/tags.hpp>
  20. #include <boost/geometry/views/detail/indexed_point_view.hpp>
  21. #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
  22. #include <boost/geometry/algorithms/detail/normalize.hpp>
  23. #include <boost/geometry/algorithms/detail/envelope/transform_units.hpp>
  24. #include <boost/geometry/algorithms/dispatch/envelope.hpp>
  25. namespace boost { namespace geometry
  26. {
  27. #ifndef DOXYGEN_NO_DETAIL
  28. namespace detail { namespace envelope
  29. {
  30. template
  31. <
  32. std::size_t Index,
  33. std::size_t Dimension,
  34. std::size_t DimensionCount
  35. >
  36. struct envelope_indexed_box
  37. {
  38. template <typename BoxIn, typename BoxOut>
  39. static inline void apply(BoxIn const& box_in, BoxOut& mbr)
  40. {
  41. detail::indexed_point_view<BoxIn const, Index> box_in_corner(box_in);
  42. detail::indexed_point_view<BoxOut, Index> mbr_corner(mbr);
  43. detail::conversion::point_to_point
  44. <
  45. detail::indexed_point_view<BoxIn const, Index>,
  46. detail::indexed_point_view<BoxOut, Index>,
  47. Dimension,
  48. DimensionCount
  49. >::apply(box_in_corner, mbr_corner);
  50. }
  51. };
  52. template
  53. <
  54. std::size_t Index,
  55. std::size_t DimensionCount
  56. >
  57. struct envelope_indexed_box_on_spheroid
  58. {
  59. template <typename BoxIn, typename BoxOut>
  60. static inline void apply(BoxIn const& box_in, BoxOut& mbr)
  61. {
  62. // transform() does not work with boxes of dimension higher
  63. // than 2; to account for such boxes we transform the min/max
  64. // points of the boxes using the indexed_point_view
  65. detail::indexed_point_view<BoxIn const, Index> box_in_corner(box_in);
  66. detail::indexed_point_view<BoxOut, Index> mbr_corner(mbr);
  67. // first transform the units
  68. transform_units(box_in_corner, mbr_corner);
  69. // now transform the remaining coordinates
  70. detail::conversion::point_to_point
  71. <
  72. detail::indexed_point_view<BoxIn const, Index>,
  73. detail::indexed_point_view<BoxOut, Index>,
  74. 2,
  75. DimensionCount
  76. >::apply(box_in_corner, mbr_corner);
  77. }
  78. };
  79. struct envelope_box
  80. {
  81. template<typename BoxIn, typename BoxOut, typename Strategy>
  82. static inline void apply(BoxIn const& box_in,
  83. BoxOut& mbr,
  84. Strategy const&)
  85. {
  86. envelope_indexed_box
  87. <
  88. min_corner, 0, dimension<BoxIn>::value
  89. >::apply(box_in, mbr);
  90. envelope_indexed_box
  91. <
  92. max_corner, 0, dimension<BoxIn>::value
  93. >::apply(box_in, mbr);
  94. }
  95. };
  96. struct envelope_box_on_spheroid
  97. {
  98. template <typename BoxIn, typename BoxOut, typename Strategy>
  99. static inline void apply(BoxIn const& box_in,
  100. BoxOut& mbr,
  101. Strategy const&)
  102. {
  103. BoxIn box_in_normalized = box_in;
  104. if (!is_inverse_spheroidal_coordinates(box_in))
  105. {
  106. box_in_normalized = detail::return_normalized<BoxIn>(box_in);
  107. }
  108. envelope_indexed_box_on_spheroid
  109. <
  110. min_corner, dimension<BoxIn>::value
  111. >::apply(box_in_normalized, mbr);
  112. envelope_indexed_box_on_spheroid
  113. <
  114. max_corner, dimension<BoxIn>::value
  115. >::apply(box_in_normalized, mbr);
  116. }
  117. };
  118. }} // namespace detail::envelope
  119. #endif // DOXYGEN_NO_DETAIL
  120. #ifndef DOXYGEN_NO_DISPATCH
  121. namespace dispatch
  122. {
  123. template <typename Box>
  124. struct envelope<Box, box_tag, cartesian_tag>
  125. : detail::envelope::envelope_box
  126. {};
  127. template <typename Box>
  128. struct envelope<Box, box_tag, spherical_polar_tag>
  129. : detail::envelope::envelope_box_on_spheroid
  130. {};
  131. template <typename Box>
  132. struct envelope<Box, box_tag, spherical_equatorial_tag>
  133. : detail::envelope::envelope_box_on_spheroid
  134. {};
  135. template <typename Box>
  136. struct envelope<Box, box_tag, geographic_tag>
  137. : detail::envelope::envelope_box_on_spheroid
  138. {};
  139. } // namespace dispatch
  140. #endif // DOXYGEN_NO_DISPATCH
  141. }} // namespace boost::geometry
  142. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_BOX_HPP