1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2017, 2018, 2019.
6 // Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
14 #define BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP
18 #include <boost/geometry/srs/projections/exception.hpp>
19 #include <boost/geometry/srs/projections/impl/projects.hpp>
21 namespace boost { namespace geometry { namespace projections
24 #ifndef DOXYGEN_NO_DETAIL
29 \brief projection virtual base class
30 \details class containing virtual methods
32 \tparam CT calculation type
33 \tparam P parameters type
35 template <typename CT, typename P>
36 class dynamic_wrapper_b
39 dynamic_wrapper_b(P const& par)
43 virtual ~dynamic_wrapper_b() {}
45 /// Forward projection using lon / lat and x / y separately
46 virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const = 0;
48 /// Inverse projection using x / y and lon / lat
49 virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const = 0;
51 /// Forward projection, from Latitude-Longitude to Cartesian
52 template <typename LL, typename XY>
53 inline bool forward(LL const& lp, XY& xy) const
57 pj_fwd(*this, m_par, lp, xy);
66 /// Inverse projection, from Cartesian to Latitude-Longitude
67 template <typename LL, typename XY>
68 inline bool inverse(XY const& xy, LL& lp) const
72 pj_inv(*this, m_par, xy, lp);
75 catch (projection_not_invertible_exception &)
85 /// Returns name of projection
86 std::string name() const { return m_par.id.name; }
88 /// Returns parameters of projection
89 P const& params() const { return m_par; }
91 /// Returns mutable parameters of projection
92 P& mutable_params() { return m_par; }
99 template <typename Prj, typename CT, typename P>
100 class dynamic_wrapper_f
101 : public dynamic_wrapper_b<CT, P>
104 typedef dynamic_wrapper_b<CT, P> base_t;
107 template <typename Params>
108 dynamic_wrapper_f(Params const& params, P const& par)
110 , Prj(params, this->m_par) // prj can modify parameters
113 template <typename Params, typename P3>
114 dynamic_wrapper_f(Params const& params, P const& par, P3 const& p3)
116 , Prj(params, this->m_par, p3) // prj can modify parameters
119 virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const
121 prj().fwd(par, lp_lon, lp_lat, xy_x, xy_y);
124 virtual void inv(P const& , CT const& , CT const& , CT& , CT& ) const
126 BOOST_THROW_EXCEPTION(projection_not_invertible_exception(this->name()));
130 Prj const& prj() const { return *this; }
134 template <typename Prj, typename CT, typename P>
135 class dynamic_wrapper_fi : public dynamic_wrapper_f<Prj, CT, P>
137 typedef dynamic_wrapper_f<Prj, CT, P> base_t;
140 template <typename Params>
141 dynamic_wrapper_fi(Params const& params, P const& par)
142 : base_t(params, par)
145 template <typename Params, typename P3>
146 dynamic_wrapper_fi(Params const& params, P const& par, P3 const& p3)
147 : base_t(params, par, p3)
150 virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const
152 this->prj().inv(par, xy_x, xy_y, lp_lon, lp_lat);
156 } // namespace detail
157 #endif // DOXYGEN_NO_DETAIL
159 }}} // namespace boost::geometry::projections
161 #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_DYNAMIC_HPP