side.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/coordinate_promotion.hpp>
  14. #include <boost/geometry/core/radian_access.hpp>
  15. #include <boost/geometry/core/radius.hpp>
  16. #include <boost/geometry/formulas/spherical.hpp>
  17. #include <boost/geometry/srs/spheroid.hpp>
  18. //#include <boost/geometry/strategies/concepts/side_concept.hpp>
  19. #include <boost/geometry/strategies/geographic/disjoint_segment_box.hpp>
  20. #include <boost/geometry/strategies/geographic/parameters.hpp>
  21. #include <boost/geometry/strategies/side.hpp>
  22. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  23. #include <boost/geometry/strategy/geographic/envelope.hpp>
  24. #include <boost/geometry/util/math.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. geographic() = default;
  53. explicit geographic(Spheroid const& model)
  54. : m_model(model)
  55. {}
  56. template <typename P1, typename P2, typename P>
  57. inline int apply(P1 const& p1, P2 const& p2, P const& p) const
  58. {
  59. typedef strategy::within::spherical_point_point equals_point_point_strategy_type;
  60. if (equals_point_point_strategy_type::apply(p, p1)
  61. || equals_point_point_strategy_type::apply(p, p2)
  62. || equals_point_point_strategy_type::apply(p1, p2))
  63. {
  64. return 0;
  65. }
  66. typedef typename promote_floating_point
  67. <
  68. typename select_calculation_type_alt
  69. <
  70. CalculationType,
  71. P1, P2, P
  72. >::type
  73. >::type calc_t;
  74. typedef typename FormulaPolicy::template inverse
  75. <calc_t, false, true, false, false, false> inverse_formula;
  76. calc_t a1p = azimuth<calc_t, inverse_formula>(p1, p, m_model);
  77. calc_t a12 = azimuth<calc_t, inverse_formula>(p1, p2, m_model);
  78. return formula::azimuth_side_value(a1p, a12);
  79. }
  80. Spheroid const& model() const
  81. {
  82. return m_model;
  83. }
  84. private:
  85. template <typename ResultType,
  86. typename InverseFormulaType,
  87. typename Point1,
  88. typename Point2,
  89. typename ModelT>
  90. static inline ResultType azimuth(Point1 const& point1, Point2 const& point2,
  91. ModelT const& model)
  92. {
  93. return InverseFormulaType::apply(get_as_radian<0>(point1),
  94. get_as_radian<1>(point1),
  95. get_as_radian<0>(point2),
  96. get_as_radian<1>(point2),
  97. model).azimuth;
  98. }
  99. Spheroid m_model;
  100. };
  101. }} // namespace strategy::side
  102. }} // namespace boost::geometry
  103. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_SIDE_HPP