side.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // Boost.Geometry
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2014-2018.
  4. // Modifications copyright (c) 2014-2018 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 strategy::envelope::geographic
  52. <
  53. FormulaPolicy,
  54. Spheroid,
  55. CalculationType
  56. > envelope_strategy_type;
  57. inline envelope_strategy_type get_envelope_strategy() const
  58. {
  59. return envelope_strategy_type(m_model);
  60. }
  61. typedef strategy::disjoint::segment_box_geographic
  62. <
  63. FormulaPolicy,
  64. Spheroid,
  65. CalculationType
  66. > disjoint_strategy_type;
  67. inline disjoint_strategy_type get_disjoint_strategy() const
  68. {
  69. return disjoint_strategy_type(m_model);
  70. }
  71. typedef strategy::within::spherical_point_point equals_point_point_strategy_type;
  72. static inline equals_point_point_strategy_type get_equals_point_point_strategy()
  73. {
  74. return equals_point_point_strategy_type();
  75. }
  76. geographic()
  77. {}
  78. explicit geographic(Spheroid const& model)
  79. : m_model(model)
  80. {}
  81. template <typename P1, typename P2, typename P>
  82. inline int apply(P1 const& p1, P2 const& p2, P const& p) const
  83. {
  84. typedef typename promote_floating_point
  85. <
  86. typename select_calculation_type_alt
  87. <
  88. CalculationType,
  89. P1, P2, P
  90. >::type
  91. >::type calc_t;
  92. typedef typename FormulaPolicy::template inverse
  93. <calc_t, false, true, false, false, false> inverse_formula;
  94. calc_t a1p = azimuth<calc_t, inverse_formula>(p1, p, m_model);
  95. calc_t a12 = azimuth<calc_t, inverse_formula>(p1, p2, m_model);
  96. return formula::azimuth_side_value(a1p, a12);
  97. }
  98. private:
  99. template <typename ResultType,
  100. typename InverseFormulaType,
  101. typename Point1,
  102. typename Point2,
  103. typename ModelT>
  104. static inline ResultType azimuth(Point1 const& point1, Point2 const& point2,
  105. ModelT const& model)
  106. {
  107. return InverseFormulaType::apply(get_as_radian<0>(point1),
  108. get_as_radian<1>(point1),
  109. get_as_radian<0>(point2),
  110. get_as_radian<1>(point2),
  111. model).azimuth;
  112. }
  113. Spheroid m_model;
  114. };
  115. }} // namespace strategy::side
  116. }} // namespace boost::geometry
  117. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_SIDE_HPP