side.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_segment.hpp>
  22. #include <boost/geometry/strategies/geographic/parameters.hpp>
  23. #include <boost/geometry/strategies/side.hpp>
  24. //#include <boost/geometry/strategies/concepts/side_concept.hpp>
  25. namespace boost { namespace geometry
  26. {
  27. namespace strategy { namespace side
  28. {
  29. /*!
  30. \brief Check at which side of a segment a point lies
  31. left of segment (> 0), right of segment (< 0), on segment (0)
  32. \ingroup strategies
  33. \tparam FormulaPolicy Geodesic solution formula policy.
  34. \tparam Spheroid Reference model of coordinate system.
  35. \tparam CalculationType \tparam_calculation
  36. \qbk{
  37. [heading See also]
  38. [link geometry.reference.srs.srs_spheroid srs::spheroid]
  39. }
  40. */
  41. template
  42. <
  43. typename FormulaPolicy = strategy::andoyer,
  44. typename Spheroid = srs::spheroid<double>,
  45. typename CalculationType = void
  46. >
  47. class geographic
  48. {
  49. public:
  50. typedef strategy::envelope::geographic_segment
  51. <
  52. FormulaPolicy,
  53. Spheroid,
  54. CalculationType
  55. > envelope_strategy_type;
  56. inline envelope_strategy_type get_envelope_strategy() const
  57. {
  58. return envelope_strategy_type(m_model);
  59. }
  60. typedef strategy::disjoint::segment_box_geographic
  61. <
  62. FormulaPolicy,
  63. Spheroid,
  64. CalculationType
  65. > disjoint_strategy_type;
  66. inline disjoint_strategy_type get_disjoint_strategy() const
  67. {
  68. return disjoint_strategy_type(m_model);
  69. }
  70. geographic()
  71. {}
  72. explicit geographic(Spheroid const& model)
  73. : m_model(model)
  74. {}
  75. template <typename P1, typename P2, typename P>
  76. inline int apply(P1 const& p1, P2 const& p2, P const& p) const
  77. {
  78. typedef typename promote_floating_point
  79. <
  80. typename select_calculation_type_alt
  81. <
  82. CalculationType,
  83. P1, P2, P
  84. >::type
  85. >::type calc_t;
  86. typedef typename FormulaPolicy::template inverse
  87. <calc_t, false, true, false, false, false> inverse_formula;
  88. calc_t a1p = azimuth<calc_t, inverse_formula>(p1, p, m_model);
  89. calc_t a12 = azimuth<calc_t, inverse_formula>(p1, p2, m_model);
  90. return formula::azimuth_side_value(a1p, a12);
  91. }
  92. private:
  93. template <typename ResultType,
  94. typename InverseFormulaType,
  95. typename Point1,
  96. typename Point2,
  97. typename ModelT>
  98. static inline ResultType azimuth(Point1 const& point1, Point2 const& point2,
  99. ModelT const& model)
  100. {
  101. return InverseFormulaType::apply(get_as_radian<0>(point1),
  102. get_as_radian<1>(point1),
  103. get_as_radian<0>(point2),
  104. get_as_radian<1>(point2),
  105. model).azimuth;
  106. }
  107. Spheroid m_model;
  108. };
  109. }} // namespace strategy::side
  110. }} // namespace boost::geometry
  111. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_SIDE_HPP