envelope_segment.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2017-2020 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_GEOMETRY_STRATEGY_GEOGRAPHIC_ENVELOPE_SEGMENT_HPP
  9. #define BOOST_GEOMETRY_STRATEGY_GEOGRAPHIC_ENVELOPE_SEGMENT_HPP
  10. #include <boost/geometry/srs/spheroid.hpp>
  11. #include <boost/geometry/strategy/cartesian/envelope_segment.hpp>
  12. #include <boost/geometry/strategy/envelope.hpp>
  13. #include <boost/geometry/strategies/geographic/azimuth.hpp>
  14. #include <boost/geometry/strategies/geographic/parameters.hpp>
  15. #include <boost/geometry/strategies/normalize.hpp>
  16. #include <boost/geometry/strategy/spherical/envelope_segment.hpp>
  17. #include <boost/geometry/strategy/spherical/expand_box.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. namespace strategy { namespace envelope
  21. {
  22. template
  23. <
  24. typename FormulaPolicy = strategy::andoyer,
  25. typename Spheroid = geometry::srs::spheroid<double>,
  26. typename CalculationType = void
  27. >
  28. class geographic_segment
  29. {
  30. public:
  31. typedef Spheroid model_type;
  32. inline geographic_segment()
  33. : m_spheroid()
  34. {}
  35. explicit inline geographic_segment(Spheroid const& spheroid)
  36. : m_spheroid(spheroid)
  37. {}
  38. template <typename Point, typename Box>
  39. inline void apply(Point const& point1, Point const& point2, Box& box) const
  40. {
  41. Point p1_normalized, p2_normalized;
  42. strategy::normalize::spherical_point::apply(point1, p1_normalized);
  43. strategy::normalize::spherical_point::apply(point2, p2_normalized);
  44. geometry::strategy::azimuth::geographic
  45. <
  46. FormulaPolicy,
  47. Spheroid,
  48. CalculationType
  49. > azimuth_geographic(m_spheroid);
  50. typedef typename geometry::detail::cs_angular_units
  51. <
  52. Point
  53. >::type units_type;
  54. // first compute the envelope range for the first two coordinates
  55. strategy::envelope::detail::envelope_segment_impl
  56. <
  57. geographic_tag
  58. >::template apply<units_type>(geometry::get<0>(p1_normalized),
  59. geometry::get<1>(p1_normalized),
  60. geometry::get<0>(p2_normalized),
  61. geometry::get<1>(p2_normalized),
  62. box,
  63. azimuth_geographic);
  64. // now compute the envelope range for coordinates of
  65. // dimension 2 and higher
  66. strategy::envelope::detail::envelope_one_segment
  67. <
  68. 2, dimension<Point>::value
  69. >::apply(point1, point2, box);
  70. }
  71. Spheroid model() const
  72. {
  73. return m_spheroid;
  74. }
  75. private:
  76. Spheroid m_spheroid;
  77. };
  78. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  79. namespace services
  80. {
  81. template <typename CalculationType>
  82. struct default_strategy<segment_tag, geographic_tag, CalculationType>
  83. {
  84. typedef strategy::envelope::geographic_segment
  85. <
  86. strategy::andoyer,
  87. srs::spheroid<double>,
  88. CalculationType
  89. > type;
  90. };
  91. }
  92. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  93. }} // namespace strategy::envelope
  94. }} //namepsace boost::geometry
  95. #endif // BOOST_GEOMETRY_STRATEGY_GEOGRAPHIC_ENVELOPE_SEGMENT_HPP