side.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Boost.Geometry
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2014-2019.
  4. // Modifications copyright (c) 2014-2019 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/util/math.hpp>
  18. #include <boost/geometry/util/promote_floating_point.hpp>
  19. #include <boost/geometry/util/select_calculation_type.hpp>
  20. #include <boost/geometry/strategies/geographic/disjoint_segment_box.hpp>
  21. #include <boost/geometry/strategies/geographic/envelope.hpp>
  22. #include <boost/geometry/strategies/geographic/parameters.hpp>
  23. #include <boost/geometry/strategies/side.hpp>
  24. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  25. //#include <boost/geometry/strategies/concepts/side_concept.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. typedef typename promote_floating_point
  86. <
  87. typename select_calculation_type_alt
  88. <
  89. CalculationType,
  90. P1, P2, P
  91. >::type
  92. >::type calc_t;
  93. typedef typename FormulaPolicy::template inverse
  94. <calc_t, false, true, false, false, false> inverse_formula;
  95. calc_t a1p = azimuth<calc_t, inverse_formula>(p1, p, m_model);
  96. calc_t a12 = azimuth<calc_t, inverse_formula>(p1, p2, m_model);
  97. return formula::azimuth_side_value(a1p, a12);
  98. }
  99. Spheroid const& model() const
  100. {
  101. return m_model;
  102. }
  103. private:
  104. template <typename ResultType,
  105. typename InverseFormulaType,
  106. typename Point1,
  107. typename Point2,
  108. typename ModelT>
  109. static inline ResultType azimuth(Point1 const& point1, Point2 const& point2,
  110. ModelT const& model)
  111. {
  112. return InverseFormulaType::apply(get_as_radian<0>(point1),
  113. get_as_radian<1>(point1),
  114. get_as_radian<0>(point2),
  115. get_as_radian<1>(point2),
  116. model).azimuth;
  117. }
  118. Spheroid m_model;
  119. };
  120. }} // namespace strategy::side
  121. }} // namespace boost::geometry
  122. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_SIDE_HPP