expand_box.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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, 2019.
  7. // Modifications copyright (c) 2015-2019, 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. // Distributed under the Boost Software License, Version 1.0.
  12. // (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_STRATEGY_SPHERICAL_EXPAND_BOX_HPP
  15. #define BOOST_GEOMETRY_STRATEGY_SPHERICAL_EXPAND_BOX_HPP
  16. #include <algorithm>
  17. #include <cstddef>
  18. #include <boost/geometry/core/cs.hpp>
  19. #include <boost/geometry/core/coordinate_dimension.hpp>
  20. #include <boost/geometry/core/coordinate_system.hpp>
  21. #include <boost/geometry/core/tags.hpp>
  22. #include <boost/geometry/algorithms/convert.hpp>
  23. #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
  24. #include <boost/geometry/algorithms/detail/normalize.hpp>
  25. #include <boost/geometry/algorithms/detail/envelope/transform_units.hpp>
  26. #include <boost/geometry/algorithms/detail/envelope/range_of_boxes.hpp>
  27. #include <boost/geometry/algorithms/dispatch/envelope.hpp>
  28. #include <boost/geometry/geometries/helper_geometry.hpp>
  29. #include <boost/geometry/strategy/expand.hpp>
  30. #include <boost/geometry/util/is_inverse_spheroidal_coordinates.hpp>
  31. #include <boost/geometry/views/detail/indexed_point_view.hpp>
  32. namespace boost { namespace geometry
  33. {
  34. #ifndef DOXYGEN_NO_DETAIL
  35. namespace detail { namespace envelope
  36. {
  37. template
  38. <
  39. std::size_t Index,
  40. std::size_t DimensionCount
  41. >
  42. struct envelope_indexed_box_on_spheroid
  43. {
  44. template <typename BoxIn, typename BoxOut>
  45. static inline void apply(BoxIn const& box_in, BoxOut& mbr)
  46. {
  47. // transform() does not work with boxes of dimension higher
  48. // than 2; to account for such boxes we transform the min/max
  49. // points of the boxes using the indexed_point_view
  50. detail::indexed_point_view<BoxIn const, Index> box_in_corner(box_in);
  51. detail::indexed_point_view<BoxOut, Index> mbr_corner(mbr);
  52. // first transform the units
  53. transform_units(box_in_corner, mbr_corner);
  54. // now transform the remaining coordinates
  55. detail::conversion::point_to_point
  56. <
  57. detail::indexed_point_view<BoxIn const, Index>,
  58. detail::indexed_point_view<BoxOut, Index>,
  59. 2,
  60. DimensionCount
  61. >::apply(box_in_corner, mbr_corner);
  62. }
  63. };
  64. struct envelope_box_on_spheroid
  65. {
  66. template <typename BoxIn, typename BoxOut>
  67. static inline void apply(BoxIn const& box_in, BoxOut& mbr)
  68. {
  69. // BoxIn can be non-mutable
  70. typename helper_geometry<BoxIn>::type box_in_normalized;
  71. geometry::convert(box_in, box_in_normalized);
  72. if (! is_inverse_spheroidal_coordinates(box_in))
  73. {
  74. strategy::normalize::spherical_box::apply(box_in, box_in_normalized);
  75. }
  76. geometry::detail::envelope::envelope_indexed_box_on_spheroid
  77. <
  78. min_corner, dimension<BoxIn>::value
  79. >::apply(box_in_normalized, mbr);
  80. geometry::detail::envelope::envelope_indexed_box_on_spheroid
  81. <
  82. max_corner, dimension<BoxIn>::value
  83. >::apply(box_in_normalized, mbr);
  84. }
  85. };
  86. }} // namespace detail::envelope
  87. #endif // DOXYGEN_NO_DETAIL
  88. namespace strategy { namespace expand
  89. {
  90. #ifndef DOXYGEN_NO_DETAIL
  91. namespace detail
  92. {
  93. struct box_on_spheroid
  94. {
  95. template <typename BoxOut, typename BoxIn>
  96. static inline void apply(BoxOut& box_out, BoxIn const& box_in)
  97. {
  98. // normalize both boxes and convert box-in to be of type of box-out
  99. BoxOut mbrs[2];
  100. geometry::detail::envelope::envelope_box_on_spheroid::apply(box_in, mbrs[0]);
  101. geometry::detail::envelope::envelope_box_on_spheroid::apply(box_out, mbrs[1]);
  102. // compute the envelope of the two boxes
  103. geometry::detail::envelope::envelope_range_of_boxes::apply(mbrs, box_out);
  104. }
  105. };
  106. } // namespace detail
  107. #endif // DOXYGEN_NO_DETAIL
  108. struct spherical_box
  109. : detail::box_on_spheroid
  110. {};
  111. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  112. namespace services
  113. {
  114. template <typename CalculationType>
  115. struct default_strategy<box_tag, spherical_equatorial_tag, CalculationType>
  116. {
  117. typedef spherical_box type;
  118. };
  119. template <typename CalculationType>
  120. struct default_strategy<box_tag, spherical_polar_tag, CalculationType>
  121. {
  122. typedef spherical_box type;
  123. };
  124. template <typename CalculationType>
  125. struct default_strategy<box_tag, geographic_tag, CalculationType>
  126. {
  127. typedef spherical_box type;
  128. };
  129. } // namespace services
  130. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  131. }} // namespace strategy::expand
  132. }} // namespace boost::geometry
  133. #endif // BOOST_GEOMETRY_STRATEGY_SPHERICAL_EXPAND_BOX_HPP