]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/srs/projections/proj/moll.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / geometry / srs / projections / proj / moll.hpp
1 #ifndef BOOST_GEOMETRY_PROJECTIONS_MOLL_HPP
2 #define BOOST_GEOMETRY_PROJECTIONS_MOLL_HPP
3
4 // Boost.Geometry - extensions-gis-projections (based on PROJ4)
5 // This file is automatically generated. DO NOT EDIT.
6
7 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
8
9 // This file was modified by Oracle on 2017.
10 // Modifications copyright (c) 2017, Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
12
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
16
17 // This file is converted from PROJ4, http://trac.osgeo.org/proj
18 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
19 // PROJ4 is maintained by Frank Warmerdam
20 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
21
22 // Last updated version of proj: 4.9.1
23
24 // Original copyright notice:
25
26 // Permission is hereby granted, free of charge, to any person obtaining a
27 // copy of this software and associated documentation files (the "Software"),
28 // to deal in the Software without restriction, including without limitation
29 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
30 // and/or sell copies of the Software, and to permit persons to whom the
31 // Software is furnished to do so, subject to the following conditions:
32
33 // The above copyright notice and this permission notice shall be included
34 // in all copies or substantial portions of the Software.
35
36 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
37 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
41 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
42 // DEALINGS IN THE SOFTWARE.
43
44 #include <boost/geometry/util/math.hpp>
45
46 #include <boost/geometry/srs/projections/impl/base_static.hpp>
47 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
48 #include <boost/geometry/srs/projections/impl/projects.hpp>
49 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
50 #include <boost/geometry/srs/projections/impl/aasincos.hpp>
51
52 namespace boost { namespace geometry
53 {
54
55 namespace srs { namespace par4
56 {
57 struct moll {};
58 struct wag4 {};
59 struct wag5 {};
60
61 }} //namespace srs::par4
62
63 namespace projections
64 {
65 #ifndef DOXYGEN_NO_DETAIL
66 namespace detail { namespace moll
67 {
68
69 static const int MAX_ITER = 10;
70 static const double LOOP_TOL = 1e-7;
71
72 template <typename T>
73 struct par_moll
74 {
75 T C_x, C_y, C_p;
76 };
77
78 // template class, using CRTP to implement forward/inverse
79 template <typename CalculationType, typename Parameters>
80 struct base_moll_spheroid : public base_t_fi<base_moll_spheroid<CalculationType, Parameters>,
81 CalculationType, Parameters>
82 {
83
84 typedef CalculationType geographic_type;
85 typedef CalculationType cartesian_type;
86
87 par_moll<CalculationType> m_proj_parm;
88
89 inline base_moll_spheroid(const Parameters& par)
90 : base_t_fi<base_moll_spheroid<CalculationType, Parameters>,
91 CalculationType, Parameters>(*this, par) {}
92
93 // FORWARD(s_forward) spheroid
94 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
95 inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
96 {
97 static const CalculationType HALFPI = detail::HALFPI<CalculationType>();
98
99 CalculationType k, V;
100 int i;
101
102 k = this->m_proj_parm.C_p * sin(lp_lat);
103 for (i = MAX_ITER; i ; --i) {
104 lp_lat -= V = (lp_lat + sin(lp_lat) - k) /
105 (1. + cos(lp_lat));
106 if (fabs(V) < LOOP_TOL)
107 break;
108 }
109 if (!i)
110 lp_lat = (lp_lat < 0.) ? -HALFPI : HALFPI;
111 else
112 lp_lat *= 0.5;
113 xy_x = this->m_proj_parm.C_x * lp_lon * cos(lp_lat);
114 xy_y = this->m_proj_parm.C_y * sin(lp_lat);
115 }
116
117 // INVERSE(s_inverse) spheroid
118 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
119 inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
120 {
121 lp_lat = aasin(xy_y / this->m_proj_parm.C_y);
122 lp_lon = xy_x / (this->m_proj_parm.C_x * cos(lp_lat));
123 lp_lat += lp_lat;
124 lp_lat = aasin((lp_lat + sin(lp_lat)) / this->m_proj_parm.C_p);
125 }
126
127 static inline std::string get_name()
128 {
129 return "moll_spheroid";
130 }
131
132 };
133
134 template <typename Parameters, typename T>
135 inline void setup(Parameters& par, par_moll<T>& proj_parm, T const& p)
136 {
137 T r, sp, p2 = p + p;
138
139 par.es = 0;
140 sp = sin(p);
141 r = sqrt(geometry::math::two_pi<T>() * sp / (p2 + sin(p2)));
142 proj_parm.C_x = 2. * r / geometry::math::pi<T>();
143 proj_parm.C_y = r / sp;
144 proj_parm.C_p = p2 + sin(p2);
145 }
146
147
148 // Mollweide
149 template <typename Parameters, typename T>
150 inline void setup_moll(Parameters& par, par_moll<T>& proj_parm)
151 {
152 setup(par, proj_parm, geometry::math::half_pi<T>());
153 }
154
155 // Wagner IV
156 template <typename Parameters, typename T>
157 inline void setup_wag4(Parameters& par, par_moll<T>& proj_parm)
158 {
159 setup(par, proj_parm, geometry::math::pi<T>()/3.);
160 }
161
162 // Wagner V
163 template <typename Parameters, typename T>
164 inline void setup_wag5(Parameters& par, par_moll<T>& proj_parm)
165 {
166 par.es = 0;
167 proj_parm.C_x = 0.90977;
168 proj_parm.C_y = 1.65014;
169 proj_parm.C_p = 3.00896;
170 }
171
172 }} // namespace detail::moll
173 #endif // doxygen
174
175 /*!
176 \brief Mollweide projection
177 \ingroup projections
178 \tparam Geographic latlong point type
179 \tparam Cartesian xy point type
180 \tparam Parameters parameter type
181 \par Projection characteristics
182 - Pseudocylindrical
183 - Spheroid
184 \par Example
185 \image html ex_moll.gif
186 */
187 template <typename CalculationType, typename Parameters>
188 struct moll_spheroid : public detail::moll::base_moll_spheroid<CalculationType, Parameters>
189 {
190 inline moll_spheroid(const Parameters& par) : detail::moll::base_moll_spheroid<CalculationType, Parameters>(par)
191 {
192 detail::moll::setup_moll(this->m_par, this->m_proj_parm);
193 }
194 };
195
196 /*!
197 \brief Wagner IV projection
198 \ingroup projections
199 \tparam Geographic latlong point type
200 \tparam Cartesian xy point type
201 \tparam Parameters parameter type
202 \par Projection characteristics
203 - Pseudocylindrical
204 - Spheroid
205 \par Example
206 \image html ex_wag4.gif
207 */
208 template <typename CalculationType, typename Parameters>
209 struct wag4_spheroid : public detail::moll::base_moll_spheroid<CalculationType, Parameters>
210 {
211 inline wag4_spheroid(const Parameters& par) : detail::moll::base_moll_spheroid<CalculationType, Parameters>(par)
212 {
213 detail::moll::setup_wag4(this->m_par, this->m_proj_parm);
214 }
215 };
216
217 /*!
218 \brief Wagner V projection
219 \ingroup projections
220 \tparam Geographic latlong point type
221 \tparam Cartesian xy point type
222 \tparam Parameters parameter type
223 \par Projection characteristics
224 - Pseudocylindrical
225 - Spheroid
226 \par Example
227 \image html ex_wag5.gif
228 */
229 template <typename CalculationType, typename Parameters>
230 struct wag5_spheroid : public detail::moll::base_moll_spheroid<CalculationType, Parameters>
231 {
232 inline wag5_spheroid(const Parameters& par) : detail::moll::base_moll_spheroid<CalculationType, Parameters>(par)
233 {
234 detail::moll::setup_wag5(this->m_par, this->m_proj_parm);
235 }
236 };
237
238 #ifndef DOXYGEN_NO_DETAIL
239 namespace detail
240 {
241
242 // Static projection
243 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::moll, moll_spheroid, moll_spheroid)
244 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::wag4, wag4_spheroid, wag4_spheroid)
245 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::wag5, wag5_spheroid, wag5_spheroid)
246
247 // Factory entry(s)
248 template <typename CalculationType, typename Parameters>
249 class moll_entry : public detail::factory_entry<CalculationType, Parameters>
250 {
251 public :
252 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
253 {
254 return new base_v_fi<moll_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
255 }
256 };
257
258 template <typename CalculationType, typename Parameters>
259 class wag4_entry : public detail::factory_entry<CalculationType, Parameters>
260 {
261 public :
262 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
263 {
264 return new base_v_fi<wag4_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
265 }
266 };
267
268 template <typename CalculationType, typename Parameters>
269 class wag5_entry : public detail::factory_entry<CalculationType, Parameters>
270 {
271 public :
272 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
273 {
274 return new base_v_fi<wag5_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
275 }
276 };
277
278 template <typename CalculationType, typename Parameters>
279 inline void moll_init(detail::base_factory<CalculationType, Parameters>& factory)
280 {
281 factory.add_to_factory("moll", new moll_entry<CalculationType, Parameters>);
282 factory.add_to_factory("wag4", new wag4_entry<CalculationType, Parameters>);
283 factory.add_to_factory("wag5", new wag5_entry<CalculationType, Parameters>);
284 }
285
286 } // namespace detail
287 #endif // doxygen
288
289 } // namespace projections
290
291 }} // namespace boost::geometry
292
293 #endif // BOOST_GEOMETRY_PROJECTIONS_MOLL_HPP
294