base_dynamic.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017, 2018, 2019.
  4. // Modifications copyright (c) 2017-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_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
  10. #define BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
  11. #include <string>
  12. #include <boost/geometry/srs/projections/exception.hpp>
  13. #include <boost/geometry/srs/projections/impl/projects.hpp>
  14. namespace boost { namespace geometry { namespace projections
  15. {
  16. #ifndef DOXYGEN_NO_DETAIL
  17. namespace detail
  18. {
  19. /*!
  20. \brief projection virtual base class
  21. \details class containing virtual methods
  22. \ingroup projection
  23. \tparam CT calculation type
  24. \tparam P parameters type
  25. */
  26. template <typename CT, typename P>
  27. class dynamic_wrapper_b
  28. {
  29. public :
  30. dynamic_wrapper_b(P const& par)
  31. : m_par(par)
  32. {}
  33. virtual ~dynamic_wrapper_b() {}
  34. /// Forward projection using lon / lat and x / y separately
  35. virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const = 0;
  36. /// Inverse projection using x / y and lon / lat
  37. virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const = 0;
  38. /// Forward projection, from Latitude-Longitude to Cartesian
  39. template <typename LL, typename XY>
  40. inline bool forward(LL const& lp, XY& xy) const
  41. {
  42. try
  43. {
  44. pj_fwd(*this, m_par, lp, xy);
  45. return true;
  46. }
  47. catch (...)
  48. {
  49. return false;
  50. }
  51. }
  52. /// Inverse projection, from Cartesian to Latitude-Longitude
  53. template <typename LL, typename XY>
  54. inline bool inverse(XY const& xy, LL& lp) const
  55. {
  56. try
  57. {
  58. pj_inv(*this, m_par, xy, lp);
  59. return true;
  60. }
  61. catch (projection_not_invertible_exception &)
  62. {
  63. BOOST_RETHROW
  64. }
  65. catch (...)
  66. {
  67. return false;
  68. }
  69. }
  70. /// Returns name of projection
  71. std::string name() const { return m_par.id.name; }
  72. /// Returns parameters of projection
  73. P const& params() const { return m_par; }
  74. /// Returns mutable parameters of projection
  75. P& mutable_params() { return m_par; }
  76. protected:
  77. P m_par;
  78. };
  79. // Forward
  80. template <typename Prj, typename CT, typename P>
  81. class dynamic_wrapper_f
  82. : public dynamic_wrapper_b<CT, P>
  83. , protected Prj
  84. {
  85. typedef dynamic_wrapper_b<CT, P> base_t;
  86. public:
  87. template <typename Params>
  88. dynamic_wrapper_f(Params const& params, P const& par)
  89. : base_t(par)
  90. , Prj(params, this->m_par) // prj can modify parameters
  91. {}
  92. template <typename Params, typename P3>
  93. dynamic_wrapper_f(Params const& params, P const& par, P3 const& p3)
  94. : base_t(par)
  95. , Prj(params, this->m_par, p3) // prj can modify parameters
  96. {}
  97. virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const
  98. {
  99. prj().fwd(par, lp_lon, lp_lat, xy_x, xy_y);
  100. }
  101. virtual void inv(P const& , CT const& , CT const& , CT& , CT& ) const
  102. {
  103. BOOST_THROW_EXCEPTION(projection_not_invertible_exception(this->name()));
  104. }
  105. protected:
  106. Prj const& prj() const { return *this; }
  107. };
  108. // Forward/inverse
  109. template <typename Prj, typename CT, typename P>
  110. class dynamic_wrapper_fi : public dynamic_wrapper_f<Prj, CT, P>
  111. {
  112. typedef dynamic_wrapper_f<Prj, CT, P> base_t;
  113. public:
  114. template <typename Params>
  115. dynamic_wrapper_fi(Params const& params, P const& par)
  116. : base_t(params, par)
  117. {}
  118. template <typename Params, typename P3>
  119. dynamic_wrapper_fi(Params const& params, P const& par, P3 const& p3)
  120. : base_t(params, par, p3)
  121. {}
  122. virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const
  123. {
  124. this->prj().inv(par, xy_x, xy_y, lp_lon, lp_lat);
  125. }
  126. };
  127. } // namespace detail
  128. #endif // DOXYGEN_NO_DETAIL
  129. }}} // namespace boost::geometry::projections
  130. #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP