Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:37

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // This file was modified by Oracle on 2017-2020.
0006 // Modifications copyright (c) 2017-2020, Oracle and/or its affiliates.
0007 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0008 
0009 // Use, modification and distribution is subject to the Boost Software License,
0010 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
0012 
0013 #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
0014 #define BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
0015 
0016 #include <string>
0017 
0018 #include <boost/geometry/srs/projections/exception.hpp>
0019 #include <boost/geometry/srs/projections/impl/projects.hpp>
0020 
0021 namespace boost { namespace geometry { namespace projections
0022 {
0023 
0024 #ifndef DOXYGEN_NO_DETAIL
0025 namespace detail
0026 {
0027 
0028 /*!
0029     \brief projection virtual base class
0030     \details class containing virtual methods
0031     \ingroup projection
0032     \tparam CT calculation type
0033     \tparam P parameters type
0034 */
0035 template <typename CT, typename P>
0036 class dynamic_wrapper_b
0037 {
0038 public :
0039     dynamic_wrapper_b(P const& par)
0040         : m_par(par)
0041     {}
0042 
0043     virtual ~dynamic_wrapper_b() {}
0044 
0045     /// Forward projection using lon / lat and x / y separately
0046     virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const = 0;
0047 
0048     /// Inverse projection using x / y and lon / lat
0049     virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const = 0;
0050 
0051     /// Forward projection, from Latitude-Longitude to Cartesian
0052     template <typename LL, typename XY>
0053     inline bool forward(LL const& lp, XY& xy) const
0054     {
0055         try
0056         {
0057             pj_fwd(*this, m_par, lp, xy);
0058             return true;
0059         }
0060         catch (...)
0061         {
0062             return false;
0063         }
0064     }
0065 
0066     /// Inverse projection, from Cartesian to Latitude-Longitude
0067     template <typename LL, typename XY>
0068     inline bool inverse(XY const& xy, LL& lp) const
0069     {
0070         try
0071         {
0072             pj_inv(*this, m_par, xy, lp);
0073             return true;
0074         }
0075         catch (projection_not_invertible_exception &)
0076         {
0077             BOOST_RETHROW
0078         }
0079         catch (...)
0080         {
0081             return false;
0082         }
0083     }
0084 
0085     /// Returns name of projection
0086     std::string name() const { return m_par.id.name; }
0087 
0088     /// Returns parameters of projection
0089     P const& params() const { return m_par; }
0090 
0091     /// Returns mutable parameters of projection
0092     P& mutable_params() { return m_par; }
0093 
0094 protected:
0095     P m_par;
0096 };
0097 
0098 // Forward
0099 template <typename Prj, typename CT, typename P>
0100 class dynamic_wrapper_f
0101     : public dynamic_wrapper_b<CT, P>
0102     , protected Prj
0103 {
0104     typedef dynamic_wrapper_b<CT, P> base_t;
0105 
0106 public:
0107     template <typename Params>
0108     dynamic_wrapper_f(Params const& params, P const& par)
0109         : base_t(par)
0110         , Prj(params, this->m_par) // prj can modify parameters
0111     {}
0112 
0113     template <typename Params, typename P3>
0114     dynamic_wrapper_f(Params const& params, P const& par, P3 const& p3)
0115         : base_t(par)
0116         , Prj(params, this->m_par, p3) // prj can modify parameters
0117     {}
0118 
0119     virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const
0120     {
0121         prj().fwd(par, lp_lon, lp_lat, xy_x, xy_y);
0122     }
0123 
0124     virtual void inv(P const& , CT const& , CT const& , CT& , CT& ) const
0125     {
0126         BOOST_THROW_EXCEPTION(projection_not_invertible_exception(this->name()));
0127     }
0128 
0129 protected:
0130     Prj const& prj() const { return *this; }
0131 };
0132 
0133 // Forward/inverse
0134 template <typename Prj, typename CT, typename P>
0135 class dynamic_wrapper_fi : public dynamic_wrapper_f<Prj, CT, P>
0136 {
0137     typedef dynamic_wrapper_f<Prj, CT, P> base_t;
0138 
0139 public:
0140     template <typename Params>
0141     dynamic_wrapper_fi(Params const& params, P const& par)
0142         : base_t(params, par)
0143     {}
0144 
0145     template <typename Params, typename P3>
0146     dynamic_wrapper_fi(Params const& params, P const& par, P3 const& p3)
0147         : base_t(params, par, p3)
0148     {}
0149 
0150     virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const
0151     {
0152         this->prj().inv(par, xy_x, xy_y, lp_lon, lp_lat);
0153     }
0154 };
0155 
0156 } // namespace detail
0157 #endif // DOXYGEN_NO_DETAIL
0158 
0159 }}} // namespace boost::geometry::projections
0160 
0161 #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP