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