expand_box.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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/views/detail/indexed_point_view.hpp>
  31. namespace boost { namespace geometry
  32. {
  33. #ifndef DOXYGEN_NO_DETAIL
  34. namespace detail { namespace envelope
  35. {
  36. template
  37. <
  38. std::size_t Index,
  39. std::size_t DimensionCount
  40. >
  41. struct envelope_indexed_box_on_spheroid
  42. {
  43. template <typename BoxIn, typename BoxOut>
  44. static inline void apply(BoxIn const& box_in, BoxOut& mbr)
  45. {
  46. // transform() does not work with boxes of dimension higher
  47. // than 2; to account for such boxes we transform the min/max
  48. // points of the boxes using the indexed_point_view
  49. detail::indexed_point_view<BoxIn const, Index> box_in_corner(box_in);
  50. detail::indexed_point_view<BoxOut, Index> mbr_corner(mbr);
  51. // first transform the units
  52. transform_units(box_in_corner, mbr_corner);
  53. // now transform the remaining coordinates
  54. detail::conversion::point_to_point
  55. <
  56. detail::indexed_point_view<BoxIn const, Index>,
  57. detail::indexed_point_view<BoxOut, Index>,
  58. 2,
  59. DimensionCount
  60. >::apply(box_in_corner, mbr_corner);
  61. }
  62. };
  63. struct envelope_box_on_spheroid
  64. {
  65. template <typename BoxIn, typename BoxOut>
  66. static inline void apply(BoxIn const& box_in, BoxOut& mbr)
  67. {
  68. // BoxIn can be non-mutable
  69. typename helper_geometry<BoxIn>::type box_in_normalized;
  70. geometry::convert(box_in, box_in_normalized);
  71. if (! is_inverse_spheroidal_coordinates(box_in))
  72. {
  73. strategy::normalize::spherical_box::apply(box_in, box_in_normalized);
  74. }
  75. geometry::detail::envelope::envelope_indexed_box_on_spheroid
  76. <
  77. min_corner, dimension<BoxIn>::value
  78. >::apply(box_in_normalized, mbr);
  79. geometry::detail::envelope::envelope_indexed_box_on_spheroid
  80. <
  81. max_corner, dimension<BoxIn>::value
  82. >::apply(box_in_normalized, mbr);
  83. }
  84. };
  85. }} // namespace detail::envelope
  86. #endif // DOXYGEN_NO_DETAIL
  87. namespace strategy { namespace expand
  88. {
  89. #ifndef DOXYGEN_NO_DETAIL
  90. namespace detail
  91. {
  92. struct box_on_spheroid
  93. {
  94. template <typename BoxOut, typename BoxIn>
  95. static inline void apply(BoxOut& box_out, BoxIn const& box_in)
  96. {
  97. // normalize both boxes and convert box-in to be of type of box-out
  98. BoxOut mbrs[2];
  99. geometry::detail::envelope::envelope_box_on_spheroid::apply(box_in, mbrs[0]);
  100. geometry::detail::envelope::envelope_box_on_spheroid::apply(box_out, mbrs[1]);
  101. // compute the envelope of the two boxes
  102. geometry::detail::envelope::envelope_range_of_boxes::apply(mbrs, box_out);
  103. }
  104. };
  105. } // namespace detail
  106. #endif // DOXYGEN_NO_DETAIL
  107. struct spherical_box
  108. : detail::box_on_spheroid
  109. {};
  110. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  111. namespace services
  112. {
  113. template <typename CalculationType>
  114. struct default_strategy<box_tag, spherical_equatorial_tag, CalculationType>
  115. {
  116. typedef spherical_box type;
  117. };
  118. template <typename CalculationType>
  119. struct default_strategy<box_tag, spherical_polar_tag, CalculationType>
  120. {
  121. typedef spherical_box type;
  122. };
  123. template <typename CalculationType>
  124. struct default_strategy<box_tag, geographic_tag, CalculationType>
  125. {
  126. typedef spherical_box type;
  127. };
  128. } // namespace services
  129. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  130. }} // namespace strategy::expand
  131. }} // namespace boost::geometry
  132. #endif // BOOST_GEOMETRY_STRATEGY_SPHERICAL_EXPAND_BOX_HPP