side.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Boost.Geometry
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2014-2021.
  4. // Modifications copyright (c) 2014-2021 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_SIDE_HPP
  10. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_SIDE_HPP
  11. #include <boost/geometry/core/cs.hpp>
  12. #include <boost/geometry/core/access.hpp>
  13. #include <boost/geometry/core/radian_access.hpp>
  14. #include <boost/geometry/core/radius.hpp>
  15. #include <boost/geometry/formulas/spherical.hpp>
  16. #include <boost/geometry/srs/spheroid.hpp>
  17. //#include <boost/geometry/strategies/concepts/side_concept.hpp>
  18. #include <boost/geometry/strategies/geographic/disjoint_segment_box.hpp>
  19. #include <boost/geometry/strategies/geographic/parameters.hpp>
  20. #include <boost/geometry/strategies/side.hpp>
  21. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  22. #include <boost/geometry/strategy/geographic/envelope.hpp>
  23. #include <boost/geometry/util/math.hpp>
  24. #include <boost/geometry/util/promote_floating_point.hpp>
  25. #include <boost/geometry/util/select_calculation_type.hpp>
  26. namespace boost { namespace geometry
  27. {
  28. namespace strategy { namespace side
  29. {
  30. /*!
  31. \brief Check at which side of a segment a point lies
  32. left of segment (> 0), right of segment (< 0), on segment (0)
  33. \ingroup strategies
  34. \tparam FormulaPolicy Geodesic solution formula policy.
  35. \tparam Spheroid Reference model of coordinate system.
  36. \tparam CalculationType \tparam_calculation
  37. \qbk{
  38. [heading See also]
  39. [link geometry.reference.srs.srs_spheroid srs::spheroid]
  40. }
  41. */
  42. template
  43. <
  44. typename FormulaPolicy = strategy::andoyer,
  45. typename Spheroid = srs::spheroid<double>,
  46. typename CalculationType = void
  47. >
  48. class geographic
  49. {
  50. public:
  51. typedef geographic_tag cs_tag;
  52. typedef strategy::envelope::geographic
  53. <
  54. FormulaPolicy,
  55. Spheroid,
  56. CalculationType
  57. > envelope_strategy_type;
  58. inline envelope_strategy_type get_envelope_strategy() const
  59. {
  60. return envelope_strategy_type(m_model);
  61. }
  62. typedef strategy::disjoint::segment_box_geographic
  63. <
  64. FormulaPolicy,
  65. Spheroid,
  66. CalculationType
  67. > disjoint_strategy_type;
  68. inline disjoint_strategy_type get_disjoint_strategy() const
  69. {
  70. return disjoint_strategy_type(m_model);
  71. }
  72. typedef strategy::within::spherical_point_point equals_point_point_strategy_type;
  73. static inline equals_point_point_strategy_type get_equals_point_point_strategy()
  74. {
  75. return equals_point_point_strategy_type();
  76. }
  77. geographic()
  78. {}
  79. explicit geographic(Spheroid const& model)
  80. : m_model(model)
  81. {}
  82. template <typename P1, typename P2, typename P>
  83. inline int apply(P1 const& p1, P2 const& p2, P const& p) const
  84. {
  85. if (equals_point_point_strategy_type::apply(p, p1)
  86. || equals_point_point_strategy_type::apply(p, p2)
  87. || equals_point_point_strategy_type::apply(p1, p2))
  88. {
  89. return 0;
  90. }
  91. typedef typename promote_floating_point
  92. <
  93. typename select_calculation_type_alt
  94. <
  95. CalculationType,
  96. P1, P2, P
  97. >::type
  98. >::type calc_t;
  99. typedef typename FormulaPolicy::template inverse
  100. <calc_t, false, true, false, false, false> inverse_formula;
  101. calc_t a1p = azimuth<calc_t, inverse_formula>(p1, p, m_model);
  102. calc_t a12 = azimuth<calc_t, inverse_formula>(p1, p2, m_model);
  103. return formula::azimuth_side_value(a1p, a12);
  104. }
  105. Spheroid const& model() const
  106. {
  107. return m_model;
  108. }
  109. private:
  110. template <typename ResultType,
  111. typename InverseFormulaType,
  112. typename Point1,
  113. typename Point2,
  114. typename ModelT>
  115. static inline ResultType azimuth(Point1 const& point1, Point2 const& point2,
  116. ModelT const& model)
  117. {
  118. return InverseFormulaType::apply(get_as_radian<0>(point1),
  119. get_as_radian<1>(point1),
  120. get_as_radian<0>(point2),
  121. get_as_radian<1>(point2),
  122. model).azimuth;
  123. }
  124. Spheroid m_model;
  125. };
  126. }} // namespace strategy::side
  127. }} // namespace boost::geometry
  128. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_SIDE_HPP